Skip to content

Commit

Permalink
Merge pull request #27 from ngraveio/release-pipeline
Browse files Browse the repository at this point in the history
feat: add release pipeline and update test/lint pipelines
  • Loading branch information
irfan798 authored Oct 16, 2024
2 parents 6bae3c1 + ec23ff3 commit 4fb1d2c
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 46 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@ name: Lints

on:
pull_request:
branches:
- main

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: 16.x
node-version: '20.x'

- name: Install dependencies
run: yarn
Expand Down
53 changes: 37 additions & 16 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,56 @@ on:
push:
branches:
- main
workflow_run:
workflows: ['Lints', 'Coverage']
types:
- completed
- release

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
release:
name: Release
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 16
cache: 'yarn'
cache-dependency-path: '**/yarn.lock'

- uses: actions/setup-node@v1
with:
node-version: 16
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
- name: Config git user

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Run build
run: yarn lerna run build

- name: Run test
run: yarn test

- name: Configure git user
run: |
git config --global user.name "${{ github.actor }}"
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
- run: yarn install --frozen-lockfile
- name: Bump version and create release
run: |
if [ "${{ github.ref_name }}" == "main" ]; then
yarn lerna version --yes --conventional-commits --conventional-prerelease --exact --create-release github --preid beta --loglevel silly
else
yarn lerna version --yes --conventional-commits --conventional-graduate --exact --create-release github --loglevel silly
fi
env:
GH_TOKEN: ${{ github.token }}

- name: Publish to NPM
run: |
if [ "${{ github.ref_name }}" == "main" ]; then
yarn lerna publish from-package --yes --no-private --loglevel silly --preid beta --dist-tag beta
else
yarn lerna publish from-package --yes --no-private --loglevel silly
fi
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
38 changes: 38 additions & 0 deletions .github/workflows/sync-main-branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Sync main with release

on:
push:
branches:
- main

jobs:
sync-main-branch:
runs-on: ubuntu-22.04
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Create PR from release to main
env:
GH_TOKEN: ${{ github.token }}
run: |
# Check if a pull request already exists from release to main
pr_url=$(gh pr list --head release --base main --json url --jq '.[0].url')
if [ -n "$pr_url" ]; then
echo "PR already exists: $pr_url"
else
pr_url=$(gh pr create \
--head release \
--base main \
--title "[skip ci][skip release] Sync main with the release branch" \
--body "Auto-created pull request to merge changes from release into main."
)
echo "Created PR: $pr_url"
fi
# Attempt to merge the pull request (Fails, investigate later)
# gh pr merge "$pr_url" --merge --auto
30 changes: 8 additions & 22 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,28 @@
name: Test

on:
push:
pull_request:

jobs:
test:
name: Test
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 18.x
node-version: '20.x'

- name: Install dependencies
run: yarn

- name: Run test over the merged changes
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git checkout $GITHUB_BASE_REF
git merge --no-commit --no-edit ${{ github.event.pull_request.head.sha }}
yarn
yarn lerna run build
yarn test
if: github.event_name == 'pull_request'
- name: Run build
run: yarn lerna run build

- name: Test
run: |
yarn lerna run build
yarn test
if: github.event_name != 'pull_request'
- name: Run test
run: yarn test

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v3
4 changes: 2 additions & 2 deletions lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"useNx": true,
"command": {
"version": {
"message": "chore(release): Publish 🚀 [ci publish]",
"allowBranch": ["main"],
"message": "chore(release): [skip ci] Publish 🚀",
"allowBranch": ["main", "release"],
"conventional-commits": true,
"create-release": "github"
}
Expand Down

0 comments on commit 4fb1d2c

Please sign in to comment.