Skip to content

Commit 50a456a

Browse files
Add GitHub Actions integration (#778)
1 parent aa65cd0 commit 50a456a

File tree

2 files changed

+159
-0
lines changed

2 files changed

+159
-0
lines changed

.github/workflows/build.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Build and Test
2+
3+
on:
4+
merge_group:
5+
workflow_dispatch:
6+
pull_request:
7+
branches:
8+
- main
9+
push:
10+
branches:
11+
- main
12+
13+
permissions:
14+
contents: read
15+
16+
concurrency:
17+
group: ${{ github.workflow }}-${{ github.ref }}
18+
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
19+
20+
env:
21+
NODE_VERSION: 18
22+
CACHE_KEY: '${{ github.ref }}-${{ github.run_id }}-${{ github.run_attempt }}'
23+
24+
jobs:
25+
build:
26+
name: Build Package
27+
runs-on: ubuntu-latest
28+
29+
steps:
30+
- name: Checkout code
31+
uses: actions/checkout@v4
32+
- name: Setup Node
33+
uses: actions/setup-node@v4
34+
with:
35+
node-version: 18
36+
- run: npm ci
37+
- run: npm run lint
38+
- run: npm run build
39+
- run: npm run test:ci
40+
- run: npm run test:types
41+
- name: Upload coverage
42+
uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d

.github/workflows/publish.yml

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
name: Publish Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
branch:
7+
description: The branch to release from
8+
required: true
9+
default: main
10+
version:
11+
description: The version being published. This should be a valid semver version, such as `1.0.0`.
12+
required: true
13+
default: ''
14+
type: string
15+
tag:
16+
description: The tag being published. This should be latest, beta or any tag you wish to support.
17+
required: true
18+
default: latest
19+
type: string
20+
dry-run:
21+
type: boolean
22+
description: Perform a publishing dry run. This will not publish the release, but will validate the release and log the commands that would be run.
23+
default: false
24+
25+
permissions:
26+
contents: read
27+
id-token: write # For publishing to NPM with provenance. Allows developers to run `npm audit signatures` and verify release signature of SDK. @see https://github.blog/2023-04-19-introducing-npm-package-provenance/
28+
29+
env:
30+
NODE_VERSION: 18
31+
NODE_ENV: development
32+
33+
jobs:
34+
configure:
35+
name: Validate input parameters
36+
runs-on: ubuntu-latest
37+
38+
outputs:
39+
vtag: ${{ steps.vtag.outputs.vtag }} # The fully constructed release tag to use for publishing
40+
dry-run: ${{ steps.dry-run.outputs.dry-run }} # The dry-run flag to use for publishing, if applicable
41+
42+
steps:
43+
- name: Checkout repository
44+
uses: actions/checkout@v4
45+
with:
46+
fetch-depth: 0
47+
ref: ${{ github.event.inputs.branch }}
48+
49+
# Configure for dry-run, if applicable. @see https://docs.npmjs.com/cli/v9/commands/npm-publish#dry-run
50+
- id: dry-run
51+
if: ${{ github.event.inputs.dry-run == 'true' }}
52+
name: Configure for `--dry-run`
53+
run: |
54+
echo "dry-run=--dry-run" >> $GITHUB_ENV
55+
echo "dry-run=--dry-run" >> $GITHUB_OUTPUT
56+
57+
# Build the tag string from package.json version and release suffix. Produces something like `1.0.0-beta.1` for a beta, or `1.0.0` for a stable release.
58+
- name: Build tag
59+
id: vtag
60+
run: |
61+
PACKAGE_VERSION="${{ github.event.inputs.version }}"
62+
echo "vtag=${PACKAGE_VERSION}" >> $GITHUB_ENV
63+
echo "vtag=${PACKAGE_VERSION}" >> $GITHUB_OUTPUT
64+
65+
# Ensure tag does not already exist.
66+
- name: Validate version
67+
uses: actions/github-script@v6
68+
env:
69+
vtag: ${{ env.vtag }}
70+
with:
71+
script: |
72+
const releaseMeta = github.rest.repos.listReleases.endpoint.merge({
73+
owner: context.repo.owner,
74+
repo: context.repo.repo,
75+
});
76+
77+
const releases = await github.paginate(releaseMeta);
78+
79+
for (const release of releases) {
80+
if (release.name === process.env.vtag) {
81+
throw new Error(`${process.env.vtag} already exists`);
82+
}
83+
}
84+
85+
console.log(`${process.env.vtag} does not exist. Proceeding with release.`)
86+
87+
publish-npm:
88+
needs: configure
89+
90+
name: Publish to NPM
91+
runs-on: ubuntu-latest
92+
environment: release
93+
94+
steps:
95+
- name: Checkout code
96+
uses: actions/checkout@v4
97+
with:
98+
fetch-depth: 0
99+
ref: ${{ github.event.inputs.branch }}
100+
101+
- name: Setup Node
102+
uses: actions/setup-node@v4
103+
with:
104+
node-version: ${{ env.NODE_VERSION }}
105+
cache: npm
106+
registry-url: 'https://registry.npmjs.org'
107+
108+
- name: Install dependencies
109+
run: npm ci
110+
111+
- name: Build
112+
run: npm run build && cp README.md ./dist/angular-jwt/
113+
114+
- name: Publish release to NPM
115+
run: npm publish ./dist/angular-jwt --provenance --tag ${{ github.event.inputs.tag }} ${{ needs.configure.outputs.dry-run }}
116+
env:
117+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

0 commit comments

Comments
 (0)