Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release pipeline #4

Merged
merged 5 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .backstage/get_npm_tag.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const version = process.env.GIT_VERSION;

if (!version) {
console.error('Script expected a GIT_VERSION environment variable');
process.exit(1);
}

// Only allow latest tag if we are releasing a major/minor/patch
if (/^\d+\.\d+\.\d+$/.test(version)) {
console.log('latest');
process.exit(0);
}

// Use the suffix as the tag. i.e. `0.11.0-rc.5` -> `rc`
const suffix = version.match(/^\d+\.\d+\.\d+-([a-z]+)\.\d+$/i)?.[1];
if (suffix) {
console.log(suffix.toLowerCase());
process.exit(0);
}

console.error(`No release tag found for ${version} — exiting`);
process.exit(1);
18 changes: 18 additions & 0 deletions .backstage/get_tagged_version.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
let cp = require("child_process");

let output = cp
.execSync("git describe --tags | sed 's/^v\\(.*\\)$/\\1/'")
.toString()
.trim();

let ver_regex = /^\d+\.\d+\.\d+(-[a-z]+\.\d+)?$/i;

if (!ver_regex.test(output)) {
console.error(`Version ${output} doesn't match our versioning spec.`);
console.error(
`Valid version samples: 0.1.0 / 1.2.3 / 1.5.0-alpha.0 / 1.1.1-rc.8`
);
process.exit(1);
}

console.log(output);
104 changes: 104 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: Release

on:
push:
tags:
- v*

jobs:
test:
runs-on: ubuntu-24.04
steps:
- name: Clone
uses: actions/checkout@v3

- name: Install
run: npm ci

- name: Build
run: npm run build

- name: Unit Test
run: npm run test

publish-github-release:
name: Publish to GitHub
runs-on: ubuntu-24.04
needs: test
steps:
- name: Get Token
id: get_workflow_token
uses: peter-murray/workflow-application-token-action@v2
with:
application_id: ${{ secrets.CC_OSS_BOT_ID }}
application_private_key: ${{ secrets.CC_OSS_BOT_PEM }}

- name: Swap to main
uses: actions/checkout@v3
with:
ref: main
fetch-depth: 0 # Full fetch
token: ${{ steps.get_workflow_token.outputs.token }}

- name: Get Version
run: |
GIT_VERSION=$(node ./.backstage/get_tagged_version.cjs)
echo GIT_VERSION="$GIT_VERSION" >> $GITHUB_ENV
- name: Get Release Tag
run: |
NPM_TAG=$(node ./.backstage/get_npm_tag.cjs)
echo NPM_TAG="$NPM_TAG" >> $GITHUB_ENV
- name: Stable Release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/') && env.NPM_TAG == 'latest'
env:
GITHUB_TOKEN: ${{ steps.get_workflow_token.outputs.token }}

- name: Prerelease
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/') && env.NPM_TAG != 'latest'
with:
prerelease: true
env:
GITHUB_TOKEN: ${{ steps.get_workflow_token.outputs.token }}

publish-npm-release:
runs-on: ubuntu-24.04
needs: publish-github-release
steps:
- name: Clone
uses: actions/checkout@v3

- name: Get Version
run: |
GIT_VERSION=$(node ./.backstage/get_tagged_version.cjs)
echo GIT_VERSION="$GIT_VERSION" >> $GITHUB_ENV
- name: Get Release Tag
run: |
NPM_TAG=$(node ./.backstage/get_npm_tag.cjs)
echo NPM_TAG="$NPM_TAG" >> $GITHUB_ENV
- name: Prepare package
run: |
npm --no-git-tag-version version $GIT_VERSION
- name: Install
run: npm ci

- name: Build
run: npm run build

- name: Publish internal
uses: JS-DevTools/npm-publish@v3
with:
tag: ${{ env.NPM_TAG }}
token: ${{ secrets.GITHUB_TOKEN }}
registry: "https://npm.pkg.github.com"

- name: Publish external
uses: JS-DevTools/npm-publish@v3
with:
tag: ${{ env.NPM_TAG }}
token: ${{ secrets.NPM_TOKEN }}
access: public
34 changes: 34 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Test

on:
push:
branches: ["main"]
pull_request:
branches: [main]

jobs:
test:
name: Test
runs-on: ${{matrix.os}}
defaults:
run:
shell: bash
strategy:
matrix:
include:
- build: linux
os: ubuntu-24.04
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 1

- name: Install
run: npm ci

- name: Build
run: npm run build

- name: Unit Test
run: npm run test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules/
build/
1 change: 0 additions & 1 deletion .npmrc

This file was deleted.

Loading
Loading