Skip to content

Commit

Permalink
ci: add build and prerelease for forked repos
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Yumatov authored and RoRu committed Apr 18, 2022
1 parent 0d884fa commit 8c8980a
Show file tree
Hide file tree
Showing 6 changed files with 223 additions and 54 deletions.
23 changes: 23 additions & 0 deletions .github/actions/build/action.yml
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions .github/actions/pr-comment/action.yml
Original file line number Diff line number Diff line change
@@ -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}\``
});
50 changes: 50 additions & 0 deletions .github/workflows/build-fork.yml
Original file line number Diff line number Diff line change
@@ -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
86 changes: 33 additions & 53 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 "[email protected]"
- 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 "[email protected]"
- 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
90 changes: 90 additions & 0 deletions .github/workflows/prerelease-fork.yaml
Original file line number Diff line number Diff line change
@@ -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 }}'
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down

0 comments on commit 8c8980a

Please sign in to comment.