|
| 1 | +name: build-release-packages |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + build: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + env: |
| 15 | + HUSKY: '0' |
| 16 | + CI: 'true' |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Checkout repository |
| 20 | + uses: actions/checkout@v4 |
| 21 | + with: |
| 22 | + fetch-depth: 0 |
| 23 | + |
| 24 | + - name: Set up Node.js |
| 25 | + uses: actions/setup-node@v4 |
| 26 | + with: |
| 27 | + node-version: 20 |
| 28 | + cache: npm |
| 29 | + |
| 30 | + - name: Install dependencies |
| 31 | + run: npm ci |
| 32 | + |
| 33 | + - name: Verify project |
| 34 | + run: npm run verify |
| 35 | + |
| 36 | + - name: Build npm package |
| 37 | + run: npm run pack:local |
| 38 | + |
| 39 | + - name: Prepare package artifact directory |
| 40 | + shell: bash |
| 41 | + run: | |
| 42 | + mkdir -p dist/package |
| 43 | + mv ./*.tgz dist/package/ |
| 44 | +
|
| 45 | + - name: Generate package checksums |
| 46 | + shell: bash |
| 47 | + run: | |
| 48 | + cd dist/package |
| 49 | + sha256sum ./*.tgz > SHA256SUMS.txt |
| 50 | +
|
| 51 | + - name: Upload build artifact |
| 52 | + uses: actions/upload-artifact@v4 |
| 53 | + with: |
| 54 | + name: atlas-lab-package |
| 55 | + path: | |
| 56 | + dist/package/*.tgz |
| 57 | + dist/package/SHA256SUMS.txt |
| 58 | + 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