ci: prepare Cloudflare Pages deployments #50
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: | |
| push: | |
| branches: | |
| - main | |
| - beta | |
| - alpha | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| id-token: write | |
| jobs: | |
| release: | |
| name: Release | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: '24' | |
| registry-url: 'https://registry.npmjs.org' | |
| - name: Setup Bun | |
| uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: latest | |
| - name: Install dependencies | |
| run: bun install --frozen-lockfile | |
| - name: Resolve release metadata | |
| id: release_meta | |
| run: | | |
| set -euo pipefail | |
| VERSION="$(node -p "JSON.parse(require('node:fs').readFileSync('packages/astro-gravatar/package.json', 'utf8')).version")" | |
| BRANCH="${GITHUB_REF_NAME}" | |
| case "$BRANCH" in | |
| main) DIST_TAG="latest" ;; | |
| beta) DIST_TAG="beta" ;; | |
| alpha) DIST_TAG="alpha" ;; | |
| *) | |
| echo "Unsupported release branch: $BRANCH" >&2 | |
| exit 1 | |
| ;; | |
| esac | |
| NPM_VERSION="$(npm view astro-gravatar version --tag "$DIST_TAG" 2>/dev/null || true)" | |
| TAG_NAME="v$VERSION" | |
| if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then | |
| TAG_EXISTS="true" | |
| else | |
| TAG_EXISTS="false" | |
| fi | |
| if [ "$VERSION" = "$NPM_VERSION" ]; then | |
| SHOULD_PUBLISH="false" | |
| else | |
| SHOULD_PUBLISH="true" | |
| fi | |
| if [ "$BRANCH" = "main" ]; then | |
| PRERELEASE="false" | |
| else | |
| PRERELEASE="true" | |
| fi | |
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | |
| echo "dist_tag=$DIST_TAG" >> "$GITHUB_OUTPUT" | |
| echo "npm_version=$NPM_VERSION" >> "$GITHUB_OUTPUT" | |
| echo "tag_name=$TAG_NAME" >> "$GITHUB_OUTPUT" | |
| echo "tag_exists=$TAG_EXISTS" >> "$GITHUB_OUTPUT" | |
| echo "should_publish=$SHOULD_PUBLISH" >> "$GITHUB_OUTPUT" | |
| echo "prerelease=$PRERELEASE" >> "$GITHUB_OUTPUT" | |
| - name: No release needed | |
| if: steps.release_meta.outputs.should_publish != 'true' | |
| run: | | |
| echo "npm already has astro-gravatar@${{ steps.release_meta.outputs.version }} for tag ${{ steps.release_meta.outputs.dist_tag }}." | |
| echo "Skipping publish." | |
| - name: Run release checks | |
| if: steps.release_meta.outputs.should_publish == 'true' | |
| run: bun run release:check | |
| - name: Publish to npm | |
| if: steps.release_meta.outputs.should_publish == 'true' | |
| run: npm publish --provenance --access public --tag "${{ steps.release_meta.outputs.dist_tag }}" | |
| working-directory: packages/astro-gravatar | |
| - name: Create and push git tag | |
| if: steps.release_meta.outputs.should_publish == 'true' && steps.release_meta.outputs.tag_exists != 'true' | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git tag -a "${{ steps.release_meta.outputs.tag_name }}" -m "Release ${{ steps.release_meta.outputs.tag_name }}" | |
| git push origin "${{ steps.release_meta.outputs.tag_name }}" | |
| - name: Create GitHub release | |
| if: steps.release_meta.outputs.should_publish == 'true' | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| if gh release view "${{ steps.release_meta.outputs.tag_name }}" >/dev/null 2>&1; then | |
| echo "GitHub release already exists for ${{ steps.release_meta.outputs.tag_name }}." | |
| exit 0 | |
| fi | |
| if [ "${{ steps.release_meta.outputs.prerelease }}" = "true" ]; then | |
| gh release create "${{ steps.release_meta.outputs.tag_name }}" --generate-notes --prerelease | |
| else | |
| gh release create "${{ steps.release_meta.outputs.tag_name }}" --generate-notes | |
| fi |