-
Notifications
You must be signed in to change notification settings - Fork 479
Add GitHub Actions integration #778
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
90c9338
Add GitHub Actions integration
frederikprijck fe80446
update
frederikprijck 67618dd
Merge branch 'main' into chore/github-actions
frederikprijck 3838f55
Merge branch 'main' into chore/github-actions
frederikprijck c750bb3
Use setup-node
frederikprijck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
name: Build and Test | ||
|
||
on: | ||
merge_group: | ||
workflow_dispatch: | ||
pull_request: | ||
branches: | ||
- main | ||
push: | ||
branches: | ||
- main | ||
|
||
permissions: | ||
contents: read | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} | ||
|
||
env: | ||
NODE_VERSION: 18 | ||
CACHE_KEY: '${{ github.ref }}-${{ github.run_id }}-${{ github.run_attempt }}' | ||
|
||
jobs: | ||
build: | ||
name: Build Package | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
- name: Setup Node | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 18 | ||
- run: npm ci | ||
- run: npm run lint | ||
- run: npm run build | ||
- run: npm run test:ci | ||
- run: npm run test:types | ||
- name: Upload coverage | ||
uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
name: Publish Release | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
branch: | ||
description: The branch to release from | ||
required: true | ||
default: main | ||
version: | ||
description: The version being published. This should be a valid semver version, such as `1.0.0`. | ||
required: true | ||
default: '' | ||
type: string | ||
tag: | ||
description: The tag being published. This should be latest, beta or any tag you wish to support. | ||
required: true | ||
default: latest | ||
type: string | ||
dry-run: | ||
type: boolean | ||
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. | ||
default: false | ||
|
||
permissions: | ||
contents: read | ||
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/ | ||
|
||
env: | ||
NODE_VERSION: 18 | ||
NODE_ENV: development | ||
|
||
jobs: | ||
configure: | ||
name: Validate input parameters | ||
runs-on: ubuntu-latest | ||
|
||
outputs: | ||
vtag: ${{ steps.vtag.outputs.vtag }} # The fully constructed release tag to use for publishing | ||
dry-run: ${{ steps.dry-run.outputs.dry-run }} # The dry-run flag to use for publishing, if applicable | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
ref: ${{ github.event.inputs.branch }} | ||
|
||
# Configure for dry-run, if applicable. @see https://docs.npmjs.com/cli/v9/commands/npm-publish#dry-run | ||
- id: dry-run | ||
if: ${{ github.event.inputs.dry-run == 'true' }} | ||
name: Configure for `--dry-run` | ||
run: | | ||
echo "dry-run=--dry-run" >> $GITHUB_ENV | ||
echo "dry-run=--dry-run" >> $GITHUB_OUTPUT | ||
|
||
# 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. | ||
- name: Build tag | ||
id: vtag | ||
run: | | ||
PACKAGE_VERSION="${{ github.event.inputs.version }}" | ||
echo "vtag=${PACKAGE_VERSION}" >> $GITHUB_ENV | ||
echo "vtag=${PACKAGE_VERSION}" >> $GITHUB_OUTPUT | ||
|
||
# Ensure tag does not already exist. | ||
- name: Validate version | ||
uses: actions/github-script@v6 | ||
env: | ||
vtag: ${{ env.vtag }} | ||
with: | ||
script: | | ||
const releaseMeta = github.rest.repos.listReleases.endpoint.merge({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
}); | ||
|
||
const releases = await github.paginate(releaseMeta); | ||
|
||
for (const release of releases) { | ||
if (release.name === process.env.vtag) { | ||
throw new Error(`${process.env.vtag} already exists`); | ||
} | ||
} | ||
|
||
console.log(`${process.env.vtag} does not exist. Proceeding with release.`) | ||
|
||
publish-npm: | ||
needs: configure | ||
|
||
name: Publish to NPM | ||
runs-on: ubuntu-latest | ||
environment: release | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
ref: ${{ github.event.inputs.branch }} | ||
|
||
- name: Setup Node | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ env.NODE_VERSION }} | ||
cache: npm | ||
registry-url: 'https://registry.npmjs.org' | ||
|
||
- name: Install dependencies | ||
run: npm ci | ||
|
||
- name: Build | ||
run: npm run build && cp README.md ./dist/angular-jwt/ | ||
|
||
- name: Publish release to NPM | ||
run: npm publish ./dist/angular-jwt --provenance --tag ${{ github.event.inputs.tag }} ${{ needs.configure.outputs.dry-run }} | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.