From 401c265bd438e28a799c18c39d01445ac3c4d7df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Thu, 21 Oct 2021 13:23:14 +0100 Subject: [PATCH 1/5] Create create-release.yml --- .github/workflows/create-release.yml | 41 ++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 .github/workflows/create-release.yml diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml new file mode 100644 index 0000000..bb5e155 --- /dev/null +++ b/.github/workflows/create-release.yml @@ -0,0 +1,41 @@ +on: + push: + tags: + - 'v*' + +name: Create Release + +jobs: + publish: + name: Publish to npm + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: '16' + cache: 'npm' + - name: Publish + run: | + npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN} + npm ci + npm publish + env: + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + + create-github-release: + name: Create GitHub Release + runs-on: ubuntu-latest + needs: publish + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Create Release Notes + uses: actions/github-script@v4.0.2 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + await github.request(`POST /repos/${{ github.repository }}/releases`, { + tag_name: "${{ github.ref }}", + generate_release_notes: true + }); From 95f9cfac6ec377aec4b8b805b0f09d12652b8be6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Thu, 21 Oct 2021 13:28:32 +0100 Subject: [PATCH 2/5] Create bump-version.yml --- .github/workflows/bump-version.yml | 43 ++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .github/workflows/bump-version.yml diff --git a/.github/workflows/bump-version.yml b/.github/workflows/bump-version.yml new file mode 100644 index 0000000..ef82937 --- /dev/null +++ b/.github/workflows/bump-version.yml @@ -0,0 +1,43 @@ +name: Bump version + +# Controls when the action will run. Workflow runs when manually triggered using the UI +# or API. +on: + workflow_dispatch: + inputs: + version: + description: 'Semver type of new version (major / minor / patch)' + required: true + +jobs: + bump-version: + runs-on: ubuntu-latest + + steps: + # Check out the content (source branch). Use a deploy key so that + # when we push changes, it will trigger the release workflow + # run that runs on: tag. (Using the GitHub token would + # not run the workflow to prevent infinite recursion.) + - name: Check out source + uses: actions/checkout@v2 + with: + ssh-key: ${{ secrets.DEPLOY_KEY }} + + - name: Setup Node.js + uses: actions/setup-node@v2 + with: + node-version: '16' + cache: 'npm' + + - name: Install npm packages + run: npm ci + + - name: Setup Git + run: | + git config user.name 'Actions Auto Build' + git config user.email 'actions@github.com' + - name: bump version + run: npm version ${{ github.event.inputs.version }} + + - name: Push latest version + run: git push origin main --follow-tags From c91fd8fe07a64b4d0902b43e0e698aaee558a1ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Thu, 21 Oct 2021 13:32:36 +0100 Subject: [PATCH 3/5] Update and rename create-release.yml to release.yml --- .github/workflows/create-release.yml | 41 --------------- .github/workflows/release.yml | 77 ++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 41 deletions(-) delete mode 100644 .github/workflows/create-release.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml deleted file mode 100644 index bb5e155..0000000 --- a/.github/workflows/create-release.yml +++ /dev/null @@ -1,41 +0,0 @@ -on: - push: - tags: - - 'v*' - -name: Create Release - -jobs: - publish: - name: Publish to npm - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 - with: - node-version: '16' - cache: 'npm' - - name: Publish - run: | - npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN} - npm ci - npm publish - env: - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - - create-github-release: - name: Create GitHub Release - runs-on: ubuntu-latest - needs: publish - steps: - - name: Checkout code - uses: actions/checkout@v2 - - name: Create Release Notes - uses: actions/github-script@v4.0.2 - with: - github-token: ${{secrets.GITHUB_TOKEN}} - script: | - await github.request(`POST /repos/${{ github.repository }}/releases`, { - tag_name: "${{ github.ref }}", - generate_release_notes: true - }); diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..04074c3 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,77 @@ +name: Release and publish + +# Inspired by https://github.com/MylesBorins/node-osc/blob/959b9c83972a67390a351d333b23db3972ca7b46/.github/workflows/bump-version.yml and +# https://github.com/MylesBorins/node-osc/blob/74b563c83736a04c4a37acbff9d7bb1f01a00f57/.github/workflows/create-release.yml + +on: + workflow_dispatch: + inputs: + version: + description: Semver descriptor for new version ("major", "minor", or "patch") + required: true + +jobs: + bump-version: + name: Bump package version + runs-on: ubuntu-latest + outputs: + new-tag: ${{ steps.new-tag.outputs.new-tag }} + steps: + - name: Checkout ref + uses: actions/checkout@v2 + - name: Preparation + uses: ./.github/actions/setup + - name: Perform last-minute checks + run: npm run check + - name: Perform last-minute tests + run: npm test + - name: Configure Git + run: | + git config user.name "GitHub Actions" + git config user.email "actions@github.com" + - name: Bump package version + run: npm version ${{ github.event.inputs.version }} + - name: Push back to GitHub + run: git push origin main --follow-tags + - name: Set output to new version + id: new-tag + run: | + version=$(jq -r .version < package.json) + echo "::set-output name=new-tag::v$version" + create-release: + name: Create GitHub release + runs-on: ubuntu-latest + needs: bump-version + steps: + - name: Checkout ref + uses: actions/checkout@v2 + with: + ref: ${{ needs.bump-version.outputs.new-tag }} + - name: Preparation + uses: ./.github/actions/setup + - name: Create release + uses: actions/github-script@v5 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + await github.request(`POST /repos/${{ github.repository }}/releases`, { + tag_name: "${{ needs.bump-version.outputs.new-tag }}", + generate_release_notes: true + }) + publish: + name: Publish to npm + runs-on: ubuntu-latest + needs: [bump-version, create-release] + steps: + - name: Checkout ref + uses: actions/checkout@v2 + with: + ref: ${{ needs.bump-version.outputs.new-tag }} + - name: Preparation + uses: ./.github/actions/setup + - name: Build package + run: npm run build + - name: Publish + run: npm publish --access public + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} From 71fb823c4a08d8875c80425bdca8b8c1057e43df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Thu, 21 Oct 2021 13:32:58 +0100 Subject: [PATCH 4/5] Delete bump-version.yml --- .github/workflows/bump-version.yml | 43 ------------------------------ 1 file changed, 43 deletions(-) delete mode 100644 .github/workflows/bump-version.yml diff --git a/.github/workflows/bump-version.yml b/.github/workflows/bump-version.yml deleted file mode 100644 index ef82937..0000000 --- a/.github/workflows/bump-version.yml +++ /dev/null @@ -1,43 +0,0 @@ -name: Bump version - -# Controls when the action will run. Workflow runs when manually triggered using the UI -# or API. -on: - workflow_dispatch: - inputs: - version: - description: 'Semver type of new version (major / minor / patch)' - required: true - -jobs: - bump-version: - runs-on: ubuntu-latest - - steps: - # Check out the content (source branch). Use a deploy key so that - # when we push changes, it will trigger the release workflow - # run that runs on: tag. (Using the GitHub token would - # not run the workflow to prevent infinite recursion.) - - name: Check out source - uses: actions/checkout@v2 - with: - ssh-key: ${{ secrets.DEPLOY_KEY }} - - - name: Setup Node.js - uses: actions/setup-node@v2 - with: - node-version: '16' - cache: 'npm' - - - name: Install npm packages - run: npm ci - - - name: Setup Git - run: | - git config user.name 'Actions Auto Build' - git config user.email 'actions@github.com' - - name: bump version - run: npm version ${{ github.event.inputs.version }} - - - name: Push latest version - run: git push origin main --follow-tags From 3f9a6f701f72b5dea81b75cf6cec5a7185a4cde0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Thu, 21 Oct 2021 13:35:05 +0100 Subject: [PATCH 5/5] Create action.yml --- .github/actions/setup/action.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .github/actions/setup/action.yml diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml new file mode 100644 index 0000000..373a9f9 --- /dev/null +++ b/.github/actions/setup/action.yml @@ -0,0 +1,15 @@ +name: Setup project +description: Sets up the repo code, Node.js, and npm dependencies + +runs: + using: composite + steps: + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: '16.x' + cache: npm + registry-url: https://registry.npmjs.org + - name: Install npm dependencies + run: npm ci + shell: bash