Skip to content

ci: improve release process (#68) #4

ci: improve release process (#68)

ci: improve release process (#68) #4

Workflow file for this run

---
name: Publish
on:
push:
branches:
- main
permissions:
contents: write
jobs:
publish:
runs-on: ubuntu-latest
environment: Production
steps:
- uses: GitHubSecurityLab/actions-permissions/monitor@v1
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version-file: package.json
registry-url: "https://registry.npmjs.org"
cache: "npm"
- name: Get version
id: get-version
shell: bash
run: |
set +e
VERSION=v$(jq -r '.version' < package.json)
echo "VERSION=${VERSION}" >> "$GITHUB_OUTPUT"
- name: Check if version already exists
id: check-version
shell: bash
run: |
set +e
git rev-parse "${{ steps.get-version.outputs.VERSION }}" >/dev/null 2>&1
if [[ $? -eq 0 ]]; then
echo "VERSION_EXISTS=true" >> "$GITHUB_OUTPUT"
else
echo "VERSION_EXISTS=false" >> "$GITHUB_OUTPUT"
fi
- name: Build package
if: steps.check-version.outputs.VERSION_EXISTS == 'false'
run: |
npm ci
npm run build
- name: Publish to NPM
if: steps.check-version.outputs.VERSION_EXISTS == 'false'
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish git tag
if: steps.check-version.outputs.VERSION_EXISTS == 'false'
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com'
git tag ${{ steps.get-version.outputs.VERSION }}
git push origin --tags
- name: Publish git release
if: steps.check-version.outputs.VERSION_EXISTS == 'false'
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release create ${{ github.env.VERSION }} --title "${{ github.env.VERSION }}" --generate-notes