From 90c93387a6e5d3c7ba0b219deea2088062cc4615 Mon Sep 17 00:00:00 2001 From: frederikprijck Date: Mon, 30 Oct 2023 08:57:23 +0100 Subject: [PATCH 1/3] Add GitHub Actions integration --- .github/workflows/build.yml | 37 +++++++++++ .github/workflows/publish.yml | 114 ++++++++++++++++++++++++++++++++++ 2 files changed, 151 insertions(+) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..c0b87291 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,37 @@ +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 + - 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 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..ed1914d8 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,114 @@ +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: Publish release to NPM + run: npm publish --provenance --tag ${{ github.event.inputs.tag }} ${{ needs.configure.outputs.dry-run }} + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} From fe804460ffedb1945a2be83d07d44f77bd0814b9 Mon Sep 17 00:00:00 2001 From: frederikprijck Date: Mon, 30 Oct 2023 09:08:46 +0100 Subject: [PATCH 2/3] update --- .github/workflows/build.yml | 1 + .github/workflows/publish.yml | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c0b87291..3b715eda 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -29,6 +29,7 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 + - run: npm ci - run: npm run lint - run: npm run build - run: npm run test:ci diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index ed1914d8..b5c61b2b 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -108,7 +108,10 @@ jobs: - 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 --provenance --tag ${{ github.event.inputs.tag }} ${{ needs.configure.outputs.dry-run }} + run: npm publish ./dist/angular-jwt --provenance --tag ${{ github.event.inputs.tag }} ${{ needs.configure.outputs.dry-run }} env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} From c750bb321402bbb4841edc73b4a3886158805730 Mon Sep 17 00:00:00 2001 From: frederikprijck Date: Tue, 31 Oct 2023 11:53:39 +0100 Subject: [PATCH 3/3] Use setup-node --- .github/workflows/build.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3b715eda..e747d19a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -29,6 +29,10 @@ jobs: 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