diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-lint-test.yml similarity index 84% rename from .github/workflows/build-test.yml rename to .github/workflows/build-lint-test.yml index 9c7c9ba5..bda779e6 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-lint-test.yml @@ -1,9 +1,7 @@ name: Build, Lint, and Test on: - push: - branches: [main] - pull_request: + workflow_call: jobs: build-lint-test: @@ -15,7 +13,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v2 + uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} - name: Get Yarn cache directory @@ -40,10 +38,3 @@ jobs: - name: Validate changelog if: ${{ !startsWith(github.head_ref, 'release/') }} run: yarn auto-changelog validate - all-jobs-pass: - name: All jobs pass - runs-on: ubuntu-20.04 - needs: - - build-lint-test - steps: - - run: echo "Great success!" diff --git a/.github/workflows/create-release-pr.yml b/.github/workflows/create-release-pr.yml index e843833d..fe78e867 100644 --- a/.github/workflows/create-release-pr.yml +++ b/.github/workflows/create-release-pr.yml @@ -1,5 +1,9 @@ name: Create Release Pull Request +permissions: + contents: write + pull-requests: write + on: workflow_dispatch: inputs: @@ -21,7 +25,7 @@ jobs: contents: write pull-requests: write steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: # This is to guarantee that the most recent tag is fetched. # This can be configured to a more reasonable value by consumers. @@ -29,12 +33,10 @@ jobs: # We check out the specified branch, which will be used as the base # branch for all git operations and the release PR. ref: ${{ github.event.inputs.base-branch }} - - name: Get Node.js version - id: nvm - run: echo ::set-output name=NODE_VERSION::$(cat .nvmrc) - - uses: actions/setup-node@v2 + - name: Setup Node.js + uses: actions/setup-node@v3 with: - node-version: ${{ steps.nvm.outputs.NODE_VERSION }} + node-version-file: '.nvmrc' - uses: MetaMask/action-create-release-pr@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..2af11a0a --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,61 @@ +name: Main + +on: + push: + branches: [main] + pull_request: + +jobs: + build-lint-test: + name: Test + uses: ./.github/workflows/build-lint-test.yml + + all-jobs-completed: + name: All jobs completed + runs-on: ubuntu-latest + needs: + - build-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-completed + steps: + - name: Check that all jobs have passed + run: | + passed="${{ needs.all-jobs-completed.outputs.PASSED }}" + if [[ $passed != "true" ]]; then + exit 1 + fi + + is-release: + # Filtering by `push` events ensures that we only release from the `main` branch, which is a + # requirement for our npm publishing environment. + # The commit author should always be 'github-actions' for releases created by the + # 'create-release-pr' workflow, so we filter by that as well to prevent accidentally + # triggering a release. + if: github.event_name == 'push' && startsWith(github.event.head_commit.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 }} diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 31484ac4..a08fa299 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -1,8 +1,10 @@ name: Publish Release on: - pull_request: - types: [closed] + workflow_call: + secrets: + NPM_TOKEN: + required: true jobs: publish-release: @@ -13,17 +15,68 @@ jobs: startsWith(github.event.pull_request.head.ref, 'release/') runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - with: - # We check out the release pull request's base branch, which will be - # used as the base branch for all git operations. - ref: ${{ github.event.pull_request.base.ref }} - - name: Get Node.js version - id: nvm - run: echo ::set-output name=NODE_VERSION::$(cat .nvmrc) - - uses: actions/setup-node@v2 - with: - node-version: ${{ steps.nvm.outputs.NODE_VERSION }} - - uses: MetaMask/action-publish-release@v1 + - uses: actions/checkout@v3 + with: + ref: ${{ github.sha }} + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version-file: '.nvmrc' + - uses: MetaMask/action-publish-release@v2 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Install + run: | + yarn install + yarn build + - uses: actions/cache@v3 + id: restore-build + with: + path: | + ./dist + ./node_modules/.yarn-state.yml + key: ${{ github.sha }} + + publish-npm-dry-run: + runs-on: ubuntu-latest + needs: publish-release + steps: + - uses: actions/checkout@v3 + with: + ref: ${{ github.sha }} + - uses: actions/cache@v3 + id: restore-build + with: + path: | + ./dist + ./node_modules/.yarn-state.yml + key: ${{ github.sha }} + - name: Dry Run Publish + # omit npm-token token to perform dry run publish + uses: MetaMask/action-npm-publish@v2 + env: + SKIP_PREPACK: true + + publish-npm: + environment: npm-publish + runs-on: ubuntu-latest + needs: publish-npm-dry-run + steps: + - uses: actions/checkout@v3 + with: + ref: ${{ github.sha }} + - uses: actions/cache@v3 + id: restore-build + with: + path: | + ./dist + ./node_modules/.yarn-state.yml + key: ${{ github.sha }} + - name: Publish + uses: MetaMask/action-npm-publish@v2 + 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