-
Notifications
You must be signed in to change notification settings - Fork 0
137 lines (115 loc) · 4.51 KB
/
Copy pathrelease.yml
File metadata and controls
137 lines (115 loc) · 4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
name: Release
on:
push:
branches:
- main
- beta
- alpha
workflow_dispatch:
permissions:
contents: write
id-token: write
jobs:
release:
name: Release
runs-on: ubuntu-latest
outputs:
release_branch: ${{ github.ref_name }}
should_publish: ${{ steps.release_meta.outputs.should_publish }}
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
deploy_docs:
name: Deploy docs to Cloudflare Pages
needs: release
if: needs.release.result == 'success'
uses: ./.github/workflows/deploy-docs-pages.yml
with:
target: ${{ needs.release.outputs.release_branch == 'main' && 'production' || 'preview' }}
preview_branch: ${{ needs.release.outputs.release_branch != 'main' && needs.release.outputs.release_branch || '' }}
secrets: inherit