Skip to content

Commit

Permalink
chore: automate release
Browse files Browse the repository at this point in the history
  • Loading branch information
Arun-KumarH committed Apr 17, 2024
1 parent 2de7270 commit 0a81c83
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 19 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/approve-merge.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Merge Release PR

on:
pull_request_review:
types: [submitted]

jobs:
pr_approved:
if: ${{ github.event.review.state == 'approved' && github.event.pull_request.base.ref == 'master' && github.event.pull_request.head.ref == 'next' }}
runs-on: ubuntu-latest
steps:
- name: Clone git repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Merge PR
run: |
git checkout master
git merge --ff origin/next
git push -u origin master
- uses: benc-uk/workflow-dispatch@v1
with:
workflow: release.yaml
ref: master
52 changes: 33 additions & 19 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
name: build
name: Build

on: push

jobs:
build:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Setup NodeJS
uses: actions/setup-node@v1
- uses: actions/setup-node@v4
with:
node-version: '20.8.0'
node-version-file: '.nvmrc'

- name: Install Dependencies
run: npm ci
Expand All @@ -21,29 +19,45 @@ jobs:
run: npm run build

test:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
needs: build
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Setup NodeJS
uses: actions/setup-node@v1
- uses: actions/setup-node@v4
with:
node-version: '20.8.0'
node-version-file: '.nvmrc'

- name: Setup System
uses: restorecommerce/setup-system-action@v1
with:
backing-only: true
- uses: restorecommerce/setup-system-action@v1

- name: Install Dependencies
run: npm ci

- name: Test
run: npm run test && npm run lcov-report

- name: Coveralls
uses: coverallsapp/github-action@master
- uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

image:
runs-on: ubuntu-22.04
needs: build
steps:
- uses: actions/checkout@v4

- uses: docker/setup-buildx-action@v3

- name: Set variables
id: vars
run: |
echo ::set-output name=version_tag::$(echo ${GITHUB_REF#refs/*/})
echo ::set-output name=repo_name::$(echo ${GITHUB_REPOSITORY#*/*})
- uses: docker/build-push-action@v5
with:
platforms: linux/amd64
build-args: |
APP_HOME=/home/node/${{ steps.vars.outputs.repo_name }}
cache-from: |
${{ github.repository }}:latest
20 changes: 20 additions & 0 deletions .github/workflows/pr-lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: "Lint PR"

on:
pull_request_target:
types:
- opened
- edited
- synchronize

permissions:
pull-requests: read

jobs:
lint:
name: pr-lint
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46 changes: 46 additions & 0 deletions .github/workflows/release-pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Release PR

on:
push:
branches:
- next

permissions:
contents: read

jobs:
release_pr:
permissions:
issues: write
pull-requests: write
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'

- name: Install Dependencies
run: npm clean-install

- name: Generate Changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -ex
echo '# Release Changes' > changes.md
npx [email protected] -d -p '@semantic-release/release-notes-generator' -b next | grep -v semantic-release | tee -a changes.md
printf '\n---\n\n### Approve this PR to release above packages!' >> changes.md
- name: Create PR
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -ex
export PR_NUMBER=$(gh pr list -B master -H next --json number | jq -r '.[0].number')
if [[ "$(git rev-parse origin/master)" == "$(git rev-parse origin/next)" ]]; then exit 0; fi
if [[ "$PR_NUMBER" == "null" ]]; then gh pr create -B master -H next -t "chore: release" -F changes.md; fi
if [[ "$PR_NUMBER" != "null" ]]; then gh pr edit $PR_NUMBER -F changes.md; fi
73 changes: 73 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Release

on:
push:
branches:
- master
workflow_dispatch:

permissions:
contents: read

jobs:
release:
permissions:
contents: write
issues: write
pull-requests: write
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
ref: master

- uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.CR_PAT }}

- uses: docker/setup-buildx-action@v3
with:
install: true

- name: Set variables
id: vars
run: |
echo ::set-output name=repo_name::$(echo ${GITHUB_REPOSITORY#*/*})
- uses: docker/metadata-action@v5
id: docker_meta
with:
images: ${{ github.repository }}

- uses: docker/build-push-action@v5
with:
load: true
build-args: |
APP_HOME=/home/node/${{ steps.vars.outputs.repo_name }}
tags: ${{ github.repository }}
labels: ${{ steps.docker_meta.outputs.labels }}

- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'

- name: Install Dependencies
run: npm clean-install

- run: npx [email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- uses: benc-uk/workflow-dispatch@v1
with:
workflow: upgrade-services.yaml
ref: master
repo: restorecommerce/charts
token: "${{ secrets.CHARTS_WORKFLOW_TOKEN }}"
12 changes: 12 additions & 0 deletions .husky
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

BRANCH=$(git rev-parse --abbrev-ref HEAD)

if [ "$BRACH" = "main" ]
then
echo "committing directly to main is blocked"
exit 1
fi

./node_modules/.bin/commitlint -e $1
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20.11.1

0 comments on commit 0a81c83

Please sign in to comment.