From 8c8980aa633a8e32594131471d95ec8f1d5ef385 Mon Sep 17 00:00:00 2001 From: Vladimir Yumatov Date: Mon, 11 Apr 2022 19:24:40 +0300 Subject: [PATCH] ci: add build and prerelease for forked repos --- .github/actions/build/action.yml | 23 +++++++ .github/actions/pr-comment/action.yml | 26 ++++++++ .github/workflows/build-fork.yml | 50 ++++++++++++++ .github/workflows/ci.yaml | 86 ++++++++++-------------- .github/workflows/prerelease-fork.yaml | 90 ++++++++++++++++++++++++++ package.json | 2 +- 6 files changed, 223 insertions(+), 54 deletions(-) create mode 100644 .github/actions/build/action.yml create mode 100644 .github/actions/pr-comment/action.yml create mode 100644 .github/workflows/build-fork.yml create mode 100644 .github/workflows/prerelease-fork.yaml diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml new file mode 100644 index 00000000..97ef4aad --- /dev/null +++ b/.github/actions/build/action.yml @@ -0,0 +1,23 @@ +name: Build +description: Build +runs: + using: "composite" + steps: + - uses: actions/setup-node@9ced9a43a244f3ac94f13bfd896db8c8f30da67a # v3.0.0 + with: + node-version-file: '.nvmrc' + cache: 'yarn' + + - name: install + shell: sh + run: yarn --frozen-lockfile + + - name: lint + shell: sh + run: yarn lint + - name: cover + shell: sh + run: yarn cover + - name: build + shell: sh + run: yarn build diff --git a/.github/actions/pr-comment/action.yml b/.github/actions/pr-comment/action.yml new file mode 100644 index 00000000..ce843d3b --- /dev/null +++ b/.github/actions/pr-comment/action.yml @@ -0,0 +1,26 @@ +name: Publish canary version +description: Publish canary version +inputs: + PR_NUMBER: + description: Pull request number to comment on + required: true +runs: + using: "composite" + steps: + - name: get canary version + shell: sh + run: | + grep -Po '@aave/math-utils.*=>\s[0-9].*$' __publish-log.txt | awk '{print $3}' > __version + + - name: 'Comment on PR' + uses: actions/github-script@9ac08808f993958e9de277fe43a64532a609130e # v6.0.0 + with: + script: | + const fs = require('fs'); + const version = fs.readFileSync('./__version'); + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: Number(${{ inputs.PR_NUMBER }}), + body: `🎉 Canary Release\nTo install use\n\`npm install @aave/math-utils@${version}\`\n\`npm install @aave/contract-helpers@${version}\`` + }); diff --git a/.github/workflows/build-fork.yml b/.github/workflows/build-fork.yml new file mode 100644 index 00000000..10d4e1ce --- /dev/null +++ b/.github/workflows/build-fork.yml @@ -0,0 +1,50 @@ +name: Build PR From Fork + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref }} + cancel-in-progress: true + +on: + pull_request: + branches: ["master"] + +jobs: + build: + runs-on: ubuntu-latest + if: | # check if PR opened from fork + github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name + steps: + - uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846 # v3.0.0 + with: + persist-credentials: false + + - name: Build packages + uses: ./.github/actions/build + + + - name: Save SHA of commit + if: github.event.number + shell: sh + run: | + mkdir -p ./__pr + echo ${{ github.event.pull_request.head.sha }} > ./__pr/SHA + echo ${{ github.event.number }} > ./__pr/NUM + - name: store PR info + if: github.event.number + uses: actions/upload-artifact@6673cd052c4cd6fcf4b4e6e60ea986c889389535 # v3.0.0 + with: + name: pr + path: __pr/ + retention-days: 10 + - name: Store math-utils build + uses: actions/upload-artifact@6673cd052c4cd6fcf4b4e6e60ea986c889389535 # v3.0.0 + with: + name: math-utils + path: packages/math-utils/dist + retention-days: 10 + - name: Store contract-helpers build + uses: actions/upload-artifact@6673cd052c4cd6fcf4b4e6e60ea986c889389535 # v3.0.0 + with: + name: contract-helpers + path: packages/contract-helpers/dist + retention-days: 10 diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index bb791e7d..f28547ce 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -6,75 +6,55 @@ concurrency: on: push: - branches: - - master + branches: ['master'] pull_request: + branches: ['master'] jobs: ci: runs-on: ubuntu-latest - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + if: | + github.event.pull_request.head.repo.full_name == github.repository || + (github.ref == 'refs/heads/master' && github.event_name == 'push') steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846 # v3.0.0 with: token: ${{ secrets.BOT_TOKEN }} - - uses: actions/setup-node@v2 - with: - node-version: '16' - cache: 'yarn' - - name: prepare - id: prepare - shell: bash - run: | - echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_AUTH_TOKEN }}" >> ~/.npmrc - git config user.name "GitHub Actions Build" - git config user.email "developers@aave.com" - - name: install - id: install - run: | - yarn install --frozen-lockfile - - id: lint - name: lint - run: | - yarn lint - - id: cover - name: cover - run: | - yarn cover - - id: build - name: build - run: | - yarn build + - name: Build packages + uses: ./.github/actions/build + # https://github.com/lerna/lerna/issues/2788 --no-verify-access # https://github.com/lerna/lerna/issues/1893 --preid ${{ github.sha }} - - id: prerelease - name: prerelease + - name: prerelease if: | - github.event.pull_request.head.repo.full_name == github.repository && !contains(github.head_ref, 'dependabot') && github.ref != 'refs/heads/master' run: | - yarn release:canary --yes --no-verify-access --dist-tag ${{ github.sha }} --preid ${{ github.sha }} - #- uses: actions/github-script@v4 - # if: | - # github.event.pull_request.head.repo.full_name == github.repository && - # !contains(github.head_ref, 'dependabot') && - # github.ref != 'refs/heads/master' - # with: - # script: | - # github.issues.createComment({ - # issue_number: context.issue.number, - # owner: context.repo.owner, - # repo: context.repo.repo, - # body: '🎉 Canary Release. You can install canary version via `npm install package@next`' - # }) - - id: release - name: release + yarn release:canary \ + --yes --no-verify-access \ + --dist-tag ${{ github.event.pull_request.head.sha }} --preid ${{ github.event.pull_request.head.sha }} \ + | tee __publish-log.txt + + - name: Comment on PR + if: github.event.number + uses: ./.github/actions/pr-comment + with: + PR_NUMBER: ${{ github.event.number }} + + - name: prepare git + if: | + github.event_name == 'push' && + github.ref == 'refs/heads/master' + run: | + echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_AUTH_TOKEN }}" >> ~/.npmrc + git config user.name "GitHub Actions Build" + git config user.email "developers@aave.com" + + - name: release if: | - github.ref == 'refs/heads/master' && - !contains(github.event.head_commit.message, 'chore(release)') + github.event_name == 'push' && + github.ref == 'refs/heads/master' run: | yarn release:check yarn release:latest --yes --no-verify-access diff --git a/.github/workflows/prerelease-fork.yaml b/.github/workflows/prerelease-fork.yaml new file mode 100644 index 00000000..90018319 --- /dev/null +++ b/.github/workflows/prerelease-fork.yaml @@ -0,0 +1,90 @@ +name: Canary release from fork + +concurrency: + group: ${{ github.workflow }}-${{ github.event.workflow_run.id }} + cancel-in-progress: true + +on: + workflow_run: + workflows: ['Build PR From Fork'] + types: ['completed'] + branches-ignore: ['master'] + +jobs: + prepare_jobs: + runs-on: ubuntu-latest + if: | + github.event.workflow_run.event == 'pull_request' && + github.event.workflow_run.conclusion == 'success' + outputs: + pr_commit_sha: ${{ steps.set_pr_info.outputs.pr_commit_sha }} + pr_number: ${{ steps.set_pr_info.outputs.pr_number }} + steps: + - name: Download PR info + uses: dawidd6/action-download-artifact@575b1e4167df67acf7e692af784566618b23c71e # v2.17.0 + with: + workflow: build-fork.yml + run_id: ${{ github.event.workflow_run.id }} + workflow_conclusion: success + name: pr + path: ./ + + - name: Set PR info + id: set_pr_info + run: | + echo "::set-output name=pr_commit_sha::$(cat SHA)" + echo "::set-output name=pr_number::$(cat NUM)" + + prerelease: + runs-on: ubuntu-latest + needs: ['prepare_jobs'] + env: + pr_commit_sha: ${{ needs.prepare_jobs.outputs.pr_commit_sha }} + pr_number: ${{ needs.prepare_jobs.outputs.pr_number }} + steps: + - uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846 # v3.0.0 + with: + token: ${{ secrets.BOT_TOKEN }} + + - name: Download math-utils build + uses: dawidd6/action-download-artifact@575b1e4167df67acf7e692af784566618b23c71e # v2.17.0 + with: + workflow: build-fork.yml + run_id: ${{ github.event.workflow_run.id }} + workflow_conclusion: success + name: math-utils + path: packages/math-utils/dist + - name: Download contract-helpers build + uses: dawidd6/action-download-artifact@575b1e4167df67acf7e692af784566618b23c71e # v2.17.0 + with: + workflow: build-fork.yml + run_id: ${{ github.event.workflow_run.id }} + workflow_conclusion: success + name: contract-helpers + path: packages/contract-helpers/dist + + - name: prerelease + shell: bash + run: | + yarn release:canary \ + --yes --no-verify-access \ + --dist-tag ${{ env.pr_commit_sha }} --preid ${{ env.pr_commit_sha }} \ + | tee __publish-log.txt + + - name: Comment on PR + if: success() + uses: ./.github/actions/pr-comment + with: + PR_NUMBER: ${{ env.pr_number }} + + - name: Notify about failure + if: failure() + uses: actions/github-script@9ac08808f993958e9de277fe43a64532a609130e # v6.0.0 + with: + script: | + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: Number(${{ env.pr_number }}), + body: '❌ Something went wrong with canary release\nPlease see logs at ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}' + }); diff --git a/package.json b/package.json index 50565b6c..953b4740 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "commit": "git-cz", "release:check": "lerna changed", "release:latest": "lerna publish --yes --conventional-commits --create-release github --message 'chore(release): publish [ci skip]'", - "release:canary": "lerna publish --canary", + "release:canary": "lerna publish --canary --ignore-scripts", "prepare": "husky install" }, "workspaces": [