|
| 1 | +--- |
| 2 | +name: Release |
| 3 | + |
| 4 | +run-name: release ${{ inputs.tag }} |
| 5 | + |
| 6 | +on: |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + tag: |
| 10 | + description: 'Tag to be released' |
| 11 | + required: true |
| 12 | + |
| 13 | +jobs: |
| 14 | + publish: |
| 15 | + permissions: |
| 16 | + packages: write |
| 17 | + id-token: write |
| 18 | + contents: read |
| 19 | + env: |
| 20 | + VERSION: ${{ inputs.tag }} |
| 21 | + runs-on: ubuntu-latest |
| 22 | + steps: |
| 23 | + - uses: actions/checkout@v4 |
| 24 | + with: |
| 25 | + fetch-depth: 0 |
| 26 | + - name: Set env vars |
| 27 | + run: | |
| 28 | + echo PKG_VERSION="$(jq -r .version < package.json)" >> $GITHUB_ENV |
| 29 | + echo PKG_NAME="$(jq -r .name < package.json)" >> $GITHUB_ENV |
| 30 | + echo PKG_BASENAME="$(basename $(jq -r .name < package.json))" >> $GITHUB_ENV |
| 31 | + - name: Ensure the branch is protected |
| 32 | + run: | |
| 33 | + if [[ "${{ github.ref_protected }}" = "false" ]]; then |
| 34 | + echo "::error::The branch ${{ github.ref }} is not protected" |
| 35 | + exit 1 |
| 36 | + fi |
| 37 | + - name: Ensure tag has not been released |
| 38 | + run: | |
| 39 | + TAG_EXISTS=$(git tag -l "${{ inputs.tag }}") |
| 40 | + if [[ -n "$TAG_EXISTS" ]]; then |
| 41 | + echo "::error::The tag ${{ inputs.tag }} already exists" |
| 42 | + exit 1 |
| 43 | + fi |
| 44 | + - name: Ensure version is properly set |
| 45 | + run: | |
| 46 | + if ! [[ "$PKG_VERSION" = "$VERSION" ]]; then |
| 47 | + echo "::error file=package.json,line=$(sed -n '/"version":/=' package.json)::The tag $VERSION must match the version $PKG_VERSION specified in package.json" |
| 48 | + exit 1 |
| 49 | + fi |
| 50 | + - name: Setup node with GitHub Packages |
| 51 | + uses: actions/setup-node@v4 |
| 52 | + with: |
| 53 | + cache: yarn |
| 54 | + node-version: '16' |
| 55 | + registry-url: https://npm.pkg.github.com |
| 56 | + - name: install dependencies |
| 57 | + run: yarn install --frozen-lockfile |
| 58 | + - name: Publish to GitHub Packages |
| 59 | + run: npm publish --provenance |
| 60 | + env: |
| 61 | + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 62 | + - name: Setup node with npmjs.org |
| 63 | + uses: actions/setup-node@v4 |
| 64 | + with: |
| 65 | + registry-url: https://registry.npmjs.org |
| 66 | + - name: Publish to npmjs.org |
| 67 | + run: npm publish --provenance |
| 68 | + env: |
| 69 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 70 | + - name: Create Release |
| 71 | + uses: softprops/action-gh-release@v2 |
| 72 | + env: |
| 73 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 74 | + with: |
| 75 | + tag_name: ${{ inputs.tag }} |
| 76 | + name: Release ${{ inputs.tag }} |
| 77 | + target_commitish: ${{ github.sha }} |
| 78 | + append_body: | |
| 79 | + Github Packages: https://github.com/${{ github.repository }}/pkgs/npm/${{ env.PKG_BASENAME }} |
| 80 | + npmjs: https://www.npmjs.com/package/${{ env.PKG_NAME }}/v/${{ env.PKG_VERSION }} |
0 commit comments