Skip to content

Commit

Permalink
ci: update the release pipeline of the artifacts of the repo
Browse files Browse the repository at this point in the history
  • Loading branch information
apolikamixitos committed Oct 22, 2024
1 parent b323ae6 commit fcc8f46
Show file tree
Hide file tree
Showing 15 changed files with 1,479 additions and 257 deletions.
24 changes: 24 additions & 0 deletions .github/actions/nodejs-ci/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Install node.js dependencues
description: 'Setup node.js and install dependencies'

inputs:
node-version:
description: 'The version of node.js CLI to install'
required: true
default: '18'

runs:
using: 'composite'

steps:
- name: Setup Node
# TODO: consider while migrating the `setup-node` action later the usage of `blacksmith` actions
uses: useblacksmith/setup-node@v5
with:
node-version: '${{ inputs.node-version }}'
cache: 'npm'
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
shell: bash
run: npm ci
20 changes: 20 additions & 0 deletions .github/actions/setup-tools/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Setup tools
description: 'Setup tools for repo workflows'

inputs:
install-nodejs:
description: "Install nodejs and setup repo's npm package"
required: false
default: 'false'

runs:
using: 'composite'
steps:
# This Action bundles other reusable actions in case needed.

# Install Node.js and its dependencies
- name: Setup node.js and install dependencies
if: inputs.install-nodejs == 'true'
uses: ./.github/actions/nodejs-ci
with:
node-version: '18' # Version is hardcoded across all other steps to ensure stability of the code, although the `package.json` has `>=18` engine version
20 changes: 8 additions & 12 deletions .github/workflows/codecov.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Coverage
name: Code Coverage

on:
pull_request:
Expand All @@ -16,28 +16,24 @@ jobs:
runs-on: blacksmith-2vcpu-ubuntu-2204

steps:
- uses: actions/checkout@v4
- name: Checkout code
uses: actions/checkout@v4

- name: Install Node.js
uses: useblacksmith/setup-node@v5
- name: Setup tools
uses: ./.github/actions/setup-tools
with:
node-version: 18.x
cache: 'npm'

- name: Install Dependencies
run: npm ci
install-nodejs: 'true'

# Step to do builds and check for warnings
- name: Build
run: npm run build > build.log 2>&1

- name: Check for build warnings
run: |
if grep -q -i "error" build.log || grep -q -i "warning" build.log; then
echo "Build contains following errors or warnings..."
cat build.log
exit 1
exit 1;
else
exit 0;
fi
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/conventional-commits.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ concurrency:

jobs:
ensure-CC:
runs-on: ubuntu-latest
runs-on: blacksmith-2vcpu-ubuntu-2204

steps:
- name: semantic-pull-request
uses: amannn/action-semantic-pull-request@v3.2.6
uses: amannn/action-semantic-pull-request@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
Expand Down
83 changes: 83 additions & 0 deletions .github/workflows/create-release-pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# This workflow concerns the preparation of the `changeset` PR and keeping it updated by tracking the changes on `main` branch.
name: Create Release PR

on:
workflow_dispatch:

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

jobs:
create-release-pr:
name: Create Release PR
runs-on: blacksmith-2vcpu-ubuntu-2204
steps:
- name: Check if a branch is whitelisted and maintained
id: branch-check
run: |
BRANCH_NAME="${GITHUB_REF#refs/heads/}"
WHITELISTED_BRANCHES=("main" "releases/*")
IS_WHITELISTED=false
# Check the branch against the whitelist using wildcard matching
for BRANCH in "${WHITELISTED_BRANCHES[@]}"; do
if [[ "$BRANCH_NAME" == $BRANCH ]]; then
IS_WHITELISTED=true;
break;
fi
done
if [ "$IS_WHITELISTED" == true ]; then
echo "Branch is whitelisted: $BRANCH_NAME"
else
echo "Branch $BRANCH_NAME is not whitelisted."
exit 1
fi
echo "branch_name=${BRANCH_NAME}" >> "$GITHUB_OUTPUT"
- name: Checkout Repo
uses: actions/checkout@v4
with:
persist-credentials: false
ref: ${{ steps.branch-check.outputs.branch_name }}

- name: Check for changeset files
run: |
if ! ls .changeset/*.md | grep -q '\.changeset\/[a-z-]\+\.md$'; then
echo "No changeset files found. Exiting workflow."
exit 1
fi
echo "Changeset files found. Continuing with the workflow."
- name: Setup tools
uses: ./.github/actions/setup-tools
with:
install-nodejs: 'true'

- name: Extract the old and new versions of the package
id: extract-package-versions
run: |
# Using `--since` flag in the `status` step on the same branch returns empty release file and doesn't reflect the upcoming changes, hence we override the `baseBranch` in the config file.
jq '.baseBranch = "${{ steps.branch-check.outputs.branch_name }}"' ./.changeset/config.json > temp.json
mv temp.json ./.changeset/config.json
npm run cs -- status --output=release.json
NEW_PACKAGE_VERSION=$(jq -r '.releases[0].newVersion' release.json)
OLD_PACKAGE_VERSION=$(jq -r '.releases[0].oldVersion' release.json)
rm release.json
echo "new_package_version=${NEW_PACKAGE_VERSION}" >> "$GITHUB_OUTPUT"
echo "old_package_version=${OLD_PACKAGE_VERSION}" >> "$GITHUB_OUTPUT"
# Keep the version of the PRs up-to-date
- name: Create Release Pull Request
id: release-pr
uses: changesets/action@aba318e9165b45b7948c60273e0b72fce0a64eb9 # v1.4.7
with:
# This branch context is ignored in this step: `https://github.com/changesets/action/blob/50750fa876cc1e54c7cb972db5e2f7271fc53d99/src/run.ts#L328`, therefore the usage of `branch` selection in the workflow trigger.
branch: ${{ steps.branch-check.outputs.branch_name }}
title: 'chore(release): bump version from `${{ steps.extract-package-versions.outputs.old_package_version }}` to `${{ steps.extract-package-versions.outputs.new_package_version }}`'
commit: 'chore(release): bump version from `${{ steps.extract-package-versions.outputs.old_package_version }}` to `${{ steps.extract-package-versions.outputs.new_package_version }}`'
env:
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
18 changes: 6 additions & 12 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Linting

on:
- pull_request
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand All @@ -12,23 +12,17 @@ jobs:
runs-on: blacksmith-2vcpu-ubuntu-2204

steps:
- uses: actions/checkout@v4
- name: Checkout code
uses: actions/checkout@v4

- name: Install Node.js
uses: useblacksmith/setup-node@v5
- name: Setup tools
uses: ./.github/actions/setup-tools
with:
node-version: 18.x
cache: 'npm'

- name: Install Dependencies
run: npm ci
install-nodejs: 'true'

- name: Lint
run: npm run lint

- name: Flatten
run: npm run flatten

- name: Prettier
run: npm run prettier

Expand Down
53 changes: 0 additions & 53 deletions .github/workflows/publish-bytecode.yaml

This file was deleted.

23 changes: 0 additions & 23 deletions .github/workflows/publish-to-npm.yaml

This file was deleted.

34 changes: 0 additions & 34 deletions .github/workflows/release-dry-run.yaml

This file was deleted.

27 changes: 27 additions & 0 deletions .github/workflows/release-snapshot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This workflow publishes snapshot releases as an npm package. These releases aren't supposed to be reusable in `production` environments.
# It's triggered manually in case a snapshot release would be needed for testing purposes.
name: Release Snapshot

on:
workflow_dispatch:

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

jobs:
release-snapshot:
name: Release Snapshot
runs-on: blacksmith-2vcpu-ubuntu-2204
steps:
- name: Checkout Repo
uses: actions/checkout@v4

- name: Setup tools
uses: ./.github/actions/setup-tools
with:
install-nodejs: 'true'

- name: Build and Publish a Snapshot to NPM
run: |
npm run release-snapshot
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Loading

0 comments on commit fcc8f46

Please sign in to comment.