Release #7
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
| name: Release | |
| on: | |
| workflow_dispatch: | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| id-token: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22 | |
| registry-url: https://registry.npmjs.org | |
| cache: npm | |
| - run: npm install | |
| - run: npm run check | |
| - run: npm test | |
| - run: npm run build | |
| - name: Calculate calendar version | |
| id: version | |
| run: | | |
| today=$(date -u +"%Y.%-m.%-d") | |
| existing=$(git tag --list "v${today}*" | sort -V) | |
| if [ -z "$existing" ]; then | |
| version="$today" | |
| elif echo "$existing" | grep -qx "v${today}"; then | |
| version="${today}-1" | |
| else | |
| last=$(echo "$existing" | tail -1 | sed "s/v${today}-//") | |
| next=$((last + 1)) | |
| version="${today}-${next}" | |
| fi | |
| echo "version=$version" >> "$GITHUB_OUTPUT" | |
| echo "Releasing v${version}" | |
| - name: Bump version, commit, and tag | |
| env: | |
| VERSION: ${{ steps.version.outputs.version }} | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| sed -i "s/\"version\": \".*\"/\"version\": \"${VERSION}\"/" package.json | |
| git add package.json | |
| git diff --cached --quiet && echo "Version already ${VERSION}, skipping commit" || git commit -m "${VERSION}" | |
| git tag "v${VERSION}" | |
| git push origin main --tags | |
| - name: Publish to npm | |
| run: | | |
| echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" > ~/.npmrc | |
| npm publish --provenance --access public | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - name: Create GitHub Release | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| VERSION: ${{ steps.version.outputs.version }} | |
| run: gh release create "v${VERSION}" --title "v${VERSION}" --generate-notes |