|
4 | 4 | push: |
5 | 5 | branches: |
6 | 6 | - main |
| 7 | + workflow_dispatch: |
7 | 8 |
|
8 | 9 | permissions: |
9 | | - contents: write |
| 10 | + contents: read |
10 | 11 |
|
11 | 12 | jobs: |
12 | 13 | build: |
@@ -56,192 +57,3 @@ jobs: |
56 | 57 | dist/package/*.tgz |
57 | 58 | dist/package/SHA256SUMS.txt |
58 | 59 | if-no-files-found: error |
59 | | - |
60 | | - publish: |
61 | | - runs-on: ubuntu-latest |
62 | | - needs: build |
63 | | - env: |
64 | | - HUSKY: '0' |
65 | | - CI: 'true' |
66 | | - |
67 | | - steps: |
68 | | - - name: Checkout repository |
69 | | - uses: actions/checkout@v4 |
70 | | - with: |
71 | | - fetch-depth: 0 |
72 | | - |
73 | | - - name: Set up Node.js |
74 | | - uses: actions/setup-node@v4 |
75 | | - with: |
76 | | - node-version: 20 |
77 | | - |
78 | | - - name: Download package artifact |
79 | | - uses: actions/download-artifact@v4 |
80 | | - with: |
81 | | - name: atlas-lab-package |
82 | | - path: dist |
83 | | - |
84 | | - - name: Prepare source archive |
85 | | - run: | |
86 | | - mkdir -p dist |
87 | | - git archive --format=zip --output dist/source.zip HEAD |
88 | | - shell: bash |
89 | | - |
90 | | - - name: Resolve version and release channel |
91 | | - id: version |
92 | | - shell: bash |
93 | | - run: | |
94 | | - VERSION=$(node -p "JSON.parse(require('fs').readFileSync('package.json', 'utf8')).version") |
95 | | - RELEASE_TAG="v${VERSION}" |
96 | | - RELEASE_NAME="Atlas Lab v${VERSION}" |
97 | | - PRERELEASE="false" |
98 | | -
|
99 | | - echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT" |
100 | | - echo "RELEASE_TAG=$RELEASE_TAG" >> "$GITHUB_OUTPUT" |
101 | | - echo "RELEASE_NAME=$RELEASE_NAME" >> "$GITHUB_OUTPUT" |
102 | | - echo "PRERELEASE=$PRERELEASE" >> "$GITHUB_OUTPUT" |
103 | | -
|
104 | | - - name: Resolve release range |
105 | | - id: release-range |
106 | | - shell: bash |
107 | | - run: | |
108 | | - git fetch --tags --prune |
109 | | - LAST_TAG=$(git tag --list 'v[0-9]*.[0-9]*.[0-9]*' --sort=-v:refname | head -n 1) |
110 | | -
|
111 | | - if [ -z "$LAST_TAG" ]; then |
112 | | - BASE_SHA=$(git rev-list --max-parents=0 HEAD | tail -n 1) |
113 | | - else |
114 | | - BASE_SHA=$LAST_TAG |
115 | | - fi |
116 | | - echo "base_sha=$BASE_SHA" >> "$GITHUB_OUTPUT" |
117 | | -
|
118 | | - - name: Build release notes by category |
119 | | - id: notes |
120 | | - shell: bash |
121 | | - run: | |
122 | | - BASE_SHA="${{ steps.release-range.outputs.base_sha }}" |
123 | | - CHANGELOG="" |
124 | | - TOTAL_COMMITS=0 |
125 | | - REPO_URL="https://github.com/${GITHUB_REPOSITORY}" |
126 | | -
|
127 | | - declare -A buckets |
128 | | - declare -A counts |
129 | | - while IFS='|' read -r sha subject; do |
130 | | - [ -z "$subject" ] && continue |
131 | | - type=$(printf '%s' "$subject" | awk -F': ' '{print $1}') |
132 | | - type=${type%%(*} |
133 | | - type=$(printf '%s' "$type" | tr '[:upper:]' '[:lower:]' | tr -d ' ') |
134 | | - case "$type" in |
135 | | - feat|feature) |
136 | | - key="features" |
137 | | - ;; |
138 | | - fix|bugfix|hotfix) |
139 | | - key="fixes" |
140 | | - ;; |
141 | | - perf|performance) |
142 | | - key="performance" |
143 | | - ;; |
144 | | - refactor|refactoring) |
145 | | - key="refactor" |
146 | | - ;; |
147 | | - docs|doc) |
148 | | - key="docs" |
149 | | - ;; |
150 | | - test|tests) |
151 | | - key="tests" |
152 | | - ;; |
153 | | - chore|ci|build|builds) |
154 | | - key="chore" |
155 | | - ;; |
156 | | - revert) |
157 | | - key="reverts" |
158 | | - ;; |
159 | | - *) |
160 | | - key="other" |
161 | | - ;; |
162 | | - esac |
163 | | -
|
164 | | - display_subject="$subject" |
165 | | - if [[ "$subject" == *": "* ]]; then |
166 | | - prefix="${subject%%:*}" |
167 | | - message="${subject#*: }" |
168 | | - scope="" |
169 | | - if [[ "$prefix" == *"("*")" ]]; then |
170 | | - scope="${prefix#*(}" |
171 | | - scope="${scope%)}" |
172 | | - fi |
173 | | - if [ -n "$scope" ]; then |
174 | | - display_subject="[$scope] $message" |
175 | | - else |
176 | | - display_subject="$message" |
177 | | - fi |
178 | | - fi |
179 | | -
|
180 | | - buckets["$key"]+="- ${display_subject} ([${sha:0:7}](${REPO_URL}/commit/$sha))"$'\n' |
181 | | - counts["$key"]=$(( ${counts["$key"]:-0} + 1 )) |
182 | | - TOTAL_COMMITS=$((TOTAL_COMMITS + 1)) |
183 | | - done < <(git log --no-merges --pretty=format:"%H|%s" "$BASE_SHA"..HEAD) |
184 | | -
|
185 | | - add_section() { |
186 | | - local title="$1" |
187 | | - local key="$2" |
188 | | - local entries="${buckets[$key]}" |
189 | | - local count="${counts[$key]:-0}" |
190 | | - if [ "$count" -gt 0 ]; then |
191 | | - CHANGELOG+="### ${title} (${count})"$'\n'$'\n' |
192 | | - CHANGELOG+="${entries}"$'\n' |
193 | | - fi |
194 | | - } |
195 | | -
|
196 | | - add_section "Features" "features" |
197 | | - add_section "Fixes" "fixes" |
198 | | - add_section "Refactor" "refactor" |
199 | | - add_section "Performance" "performance" |
200 | | - add_section "Documentation" "docs" |
201 | | - add_section "Test" "tests" |
202 | | - add_section "CI / Maintenance" "chore" |
203 | | - add_section "Revert" "reverts" |
204 | | - add_section "Other" "other" |
205 | | -
|
206 | | - if [ "$TOTAL_COMMITS" -eq 0 ]; then |
207 | | - CHANGELOG="No relevant commits were detected for this release."$'\n' |
208 | | - fi |
209 | | -
|
210 | | - RELEASE_BODY="" |
211 | | - RELEASE_BODY+="## Changes"$'\n'$'\n' |
212 | | - if [ "$TOTAL_COMMITS" -gt 0 ]; then |
213 | | - RELEASE_BODY+="- Included commits: ${TOTAL_COMMITS}"$'\n' |
214 | | - RELEASE_BODY+="- Range: \`${BASE_SHA:0:7}..${GITHUB_SHA:0:7}\`"$'\n'$'\n' |
215 | | - fi |
216 | | - RELEASE_BODY+="${CHANGELOG}"$'\n' |
217 | | - RELEASE_BODY+="## Artifacts"$'\n' |
218 | | - RELEASE_BODY+="- Self-contained npm package (.tgz)"$'\n' |
219 | | - RELEASE_BODY+="- SHA256 checksums"$'\n' |
220 | | - RELEASE_BODY+="- Source zip" |
221 | | - printf 'RELEASE_BODY<<EOF\n%s\nEOF\n' "$RELEASE_BODY" >> "$GITHUB_OUTPUT" |
222 | | -
|
223 | | - - name: Skip if tag already exists |
224 | | - id: tag-guard |
225 | | - shell: bash |
226 | | - run: | |
227 | | - if git rev-parse "${{ steps.version.outputs.RELEASE_TAG }}" >/dev/null 2>&1; then |
228 | | - echo "skip=true" >> "$GITHUB_OUTPUT" |
229 | | - else |
230 | | - echo "skip=false" >> "$GITHUB_OUTPUT" |
231 | | - fi |
232 | | -
|
233 | | - - name: Publish GitHub release |
234 | | - if: steps.tag-guard.outputs.skip == 'false' |
235 | | - uses: softprops/action-gh-release@v2 |
236 | | - env: |
237 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
238 | | - with: |
239 | | - tag_name: ${{ steps.version.outputs.RELEASE_TAG }} |
240 | | - name: ${{ steps.version.outputs.RELEASE_NAME }} |
241 | | - draft: false |
242 | | - prerelease: ${{ steps.version.outputs.PRERELEASE == 'true' }} |
243 | | - body: ${{ steps.notes.outputs.RELEASE_BODY }} |
244 | | - files: | |
245 | | - dist/**/*.tgz |
246 | | - dist/**/SHA256SUMS.txt |
247 | | - dist/source.zip |
0 commit comments