Skip to content

Commit

Permalink
Update workflows and configs (#376)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrtenz authored Sep 27, 2024
1 parent 33a5fbc commit 191bc48
Show file tree
Hide file tree
Showing 30 changed files with 3,613 additions and 3,026 deletions.
42 changes: 0 additions & 42 deletions .github/workflows/create-release-pr.yml

This file was deleted.

121 changes: 48 additions & 73 deletions .github/workflows/lint-test.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,66 @@
name: Lint and Test

on:
push:
branches: [main]
pull_request:
workflow_call:

jobs:
prepare:
name: Prepare
runs-on: ubuntu-latest
outputs:
child-workspace-package-names: ${{ steps.workspace-package-names.outputs.child-workspace-package-names }}
steps:
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'yarn'
cache: yarn
- name: Install Yarn dependencies
run: yarn --immutable
- name: Fetch workspace package names
id: workspace-package-names
run: |
echo "child-workspace-package-names=$(yarn workspaces list --no-private --json | jq --slurp --raw-output 'map(.name) | @json')" >> "$GITHUB_OUTPUT"
shell: bash

lint:
name: Lint
runs-on: ubuntu-latest
needs:
- prepare
needs: prepare
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: yarn
- run: yarn --immutable
- run: yarn lint
- name: Require clean working directory
shell: bash
run: |
if ! git diff --exit-code; then
echo "Working tree dirty at end of job"
exit 1
fi
validate-changelog:
name: Validate changelog
runs-on: ubuntu-latest
needs: prepare
strategy:
matrix:
node-version: [18.x, 20.x]
package-name: ${{ fromJson(needs.prepare.outputs.child-workspace-package-names) }}
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
- run: yarn --immutable --immutable-cache
- run: yarn lint
- name: Validate RC changelog
if: ${{ startsWith(github.head_ref, 'release/') }}
run: yarn lint:changelogs --rc
- name: Validate changelog
if: ${{ !startsWith(github.head_ref, 'release/') }}
run: yarn lint:changelogs
node-version-file: '.nvmrc'
cache: yarn
- run: yarn --immutable
- run: yarn workspace ${{ matrix.package-name }} changelog:validate
- name: Require clean working directory
shell: bash
run: |
Expand All @@ -59,63 +78,19 @@ jobs:
matrix:
node-version: [18.x, 20.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
- uses: actions/checkout@v4
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
cache: yarn
- run: yarn --immutable --immutable-cache
- run: yarn test
- name: Test
run: yarn test
- name: Require clean working directory
shell: bash
run: |
if ! git diff --exit-code; then
echo "Working tree dirty at end of job"
exit 1
fi
check-workflows:
name: Check workflows
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Download actionlint
id: download-actionlint
run: bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/7fdc9630cc360ea1a469eed64ac6d78caeda1234/scripts/download-actionlint.bash) 1.6.22
shell: bash
- name: Check workflow files
run: ${{ steps.download-actionlint.outputs.executable }} -color
shell: bash

all-jobs-pass:
name: All jobs pass
runs-on: ubuntu-latest
needs:
- lint
- test
- check-workflows
steps:
- run: echo "Great success!"

is-release:
# release merge commits come from github-actions
if: startsWith(github.event.commits[0].author.name, 'github-actions')
needs:
- all-jobs-pass
outputs:
IS_RELEASE: ${{ steps.is-release.outputs.IS_RELEASE }}
runs-on: ubuntu-latest
steps:
- uses: MetaMask/action-is-release@v1
id: is-release

publish-release:
needs: is-release
if: needs.is-release.outputs.IS_RELEASE == 'true'
name: Publish release
permissions:
contents: write
uses: ./.github/workflows/publish-release.yml
secrets:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
73 changes: 73 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Main

on:
push:
branches: [main]
pull_request:

jobs:
check-workflows:
name: Check workflows
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Download actionlint
id: download-actionlint
run: bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/7fdc9630cc360ea1a469eed64ac6d78caeda1234/scripts/download-actionlint.bash) 1.6.25
shell: bash
- name: Check workflow files
run: ${{ steps.download-actionlint.outputs.executable }} -color
shell: bash

lint-test:
name: Lint, build, and test
needs: check-workflows
uses: ./.github/workflows/lint-test.yml

is-release:
name: Determine whether this is a release merge commit
needs: lint-test
if: github.event_name == 'push'
runs-on: ubuntu-latest
outputs:
IS_RELEASE: ${{ steps.is-release.outputs.IS_RELEASE }}
steps:
- id: is-release
uses: MetaMask/action-is-release@v2
with:
commit-starts-with: 'Release [version],Release v[version],Release/[version],Release/v[version]'

publish-release:
name: Publish release
needs: is-release
if: needs.is-release.outputs.IS_RELEASE == 'true'
permissions:
contents: write
uses: ./.github/workflows/publish-release.yml
secrets:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

all-jobs-complete:
name: All jobs complete
runs-on: ubuntu-latest
needs: lint-test
outputs:
passed: ${{ steps.set-output.outputs.passed }}
steps:
- name: Set passed output
id: set-output
run: echo "passed=true" >> "$GITHUB_OUTPUT"

all-jobs-pass:
name: All jobs pass
if: ${{ always() }}
runs-on: ubuntu-latest
needs: all-jobs-complete
steps:
- name: Check that all jobs have passed
run: |
passed="${{ needs.all-jobs-complete.outputs.passed }}"
if [[ $passed != "true" ]]; then
exit 1
fi
64 changes: 44 additions & 20 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,67 @@ on:
secrets:
NPM_TOKEN:
required: true
SLACK_WEBHOOK_URL:
required: true

jobs:
publish-release:
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{ github.sha }}
- name: Setup Node.js
uses: actions/setup-node@v3
- name: Install Node
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- uses: MetaMask/action-publish-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Install
run: yarn install
- uses: actions/cache@v3
id: restore-build
- name: Install Yarn
run: corepack enable
- name: Restore Yarn cache
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: yarn
- uses: actions/cache@v4
with:
path: |
./packages/**/src
./node_modules/.yarn-state.yml
key: ${{ github.sha }}
- uses: MetaMask/action-publish-release@v3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: yarn --immutable
- run: yarn build

publish-npm-dry-run:
runs-on: ubuntu-latest
needs: publish-release
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{ github.sha }}
- uses: actions/cache@v3
id: restore-build
- name: Install Node
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- name: Install Yarn
run: corepack enable
- uses: actions/cache@v4
with:
path: |
./packages/**/src
./node_modules/.yarn-state.yml
key: ${{ github.sha }}
fail-on-cache-miss: true
- name: Dry Run Publish
# omit npm-token token to perform dry run publish
uses: MetaMask/action-npm-publish@v2
uses: MetaMask/action-npm-publish@v5
with:
slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
subteam: S042S7RE4AE # @metamask-npm-publishers
env:
SKIP_PREPACK: true

Expand All @@ -55,20 +74,25 @@ jobs:
runs-on: ubuntu-latest
needs: publish-npm-dry-run
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{ github.sha }}
- uses: actions/cache@v3
id: restore-build
- name: Install Node
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- name: Install Yarn
run: corepack enable
- uses: actions/cache@v4
with:
path: |
./packages/**/src
./node_modules/.yarn-state.yml
key: ${{ github.sha }}
fail-on-cache-miss: true
- name: Publish
uses: MetaMask/action-npm-publish@v2
uses: MetaMask/action-npm-publish@v5
with:
# This `NPM_TOKEN` needs to be manually set per-repository.
# Look in the repository settings under "Environments", and set this token in the `npm-publish` environment.
npm-token: ${{ secrets.NPM_TOKEN }}
env:
SKIP_PREPACK: true
Loading

0 comments on commit 191bc48

Please sign in to comment.