11name : Release
22
33on :
4- push :
5- branches : [ master ]
64 workflow_dispatch :
75 inputs :
86 version :
1311jobs :
1412 release :
1513 runs-on : ubuntu-latest
16- if : github.ref == 'refs/heads/master ' && github.event_name == 'workflow_dispatch'
14+ if : github.ref == 'refs/heads/main ' && github.event_name == 'workflow_dispatch'
1715 permissions :
1816 contents : write
1917 pull-requests : write
3129 - name : Setup Bun
3230 uses : oven-sh/setup-bun@v2
3331 with :
34- bun-version : latest
32+ bun-version : 1.3.10
3533
3634 - name : Install dependencies
3735 run : bun install --frozen-lockfile
7371 echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
7472 echo "version_number=${NEW_VERSION#v}" >> $GITHUB_OUTPUT
7573
74+ - name : Type check
75+ run : bun run tsc --noEmit
76+
77+ - name : Run backend tests
78+ run : bun run test:unit
79+
7680 - name : Build application
7781 run : bun run build
7882
@@ -83,25 +87,45 @@ jobs:
8387 echo "# CHANGELOG" > CHANGELOG.md
8488 echo "" >> CHANGELOG.md
8589 fi
86-
87- # Add new version entry
90+
91+ VERSION="${{ steps.new_version.outputs.version_number }}"
8892 DATE=$(date +%Y-%m-%d)
89- sed -i "3i\\## [${{ steps.new_version.outputs.version_number }}] - $DATE\\n" CHANGELOG.md
90-
91- # Add commit messages since last tag
93+ if ! grep -Fq "## [${VERSION}]" CHANGELOG.md; then
94+ awk -v version="$VERSION" -v date="$DATE" '
95+ NR == 1 { print; print ""; print "## [" version "] - " date; print ""; next }
96+ { print }
97+ ' CHANGELOG.md > CHANGELOG.md.tmp
98+ mv CHANGELOG.md.tmp CHANGELOG.md
99+ fi
100+
101+ temp_changelog="$(mktemp)"
102+
103+ # Add commit messages since last tag (safe for special chars in subjects)
92104 LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
93105 if [ -n "$LAST_TAG" ]; then
94- echo "### Changes since $LAST_TAG:" >> temp_changelog.md
95- git log --pretty=format:"- %s" $LAST_TAG..HEAD >> temp_changelog.md
106+ printf '### Changes since %s:\n' "$LAST_TAG" > "$temp_changelog"
107+ git log --pretty=format:'%s%x00' "$LAST_TAG..HEAD" \
108+ | tr '\0' '\n' \
109+ | awk 'NF { print "- " $0 }' >> "$temp_changelog"
96110 else
97- echo "### Changes:" >> temp_changelog.md
98- git log --pretty=format:"- %s" -n 10 >> temp_changelog.md
111+ printf '### Changes:\n' > "$temp_changelog"
112+ git log --pretty=format:'%s%x00' -n 10 \
113+ | tr '\0' '\n' \
114+ | awk 'NF { print "- " $0 }' >> "$temp_changelog"
99115 fi
100- echo "" >> temp_changelog.md
101-
102- # Insert changes into changelog
103- sed -i "/## \[${{ steps.new_version.outputs.version_number }}\]/r temp_changelog.md" CHANGELOG.md
104- rm temp_changelog.md
116+ printf '\n' >> "$temp_changelog"
117+
118+ # Insert changes into changelog after the current version heading
119+ awk -v target="## [${VERSION}]" -v insert_file="$temp_changelog" '
120+ { print }
121+ $0 == target && !inserted {
122+ while ((getline line < insert_file) > 0) print line
123+ close(insert_file)
124+ inserted = 1
125+ }
126+ ' CHANGELOG.md > CHANGELOG.md.tmp
127+ mv CHANGELOG.md.tmp CHANGELOG.md
128+ rm -f "$temp_changelog"
105129
106130 - name : Create release archive
107131 run : |
@@ -122,28 +146,33 @@ jobs:
122146 --exclude=.git \
123147 --exclude=release \
124148 --exclude=frontend \
125- src static package.json bun.lock tsconfig.json dockerfile compose.yml README.md LICENSE
149+ src static package.json bun.lock tsconfig.json Dockerfile compose.yml README.md LICENSE
126150
127151 - name : Create release tag
128152 run : |
129153 # Create git tag for release (works with branch protection)
130- # Note: Version changes are not committed back to master due to branch protection
154+ # Note: Version changes are not committed back to main due to branch protection
131155 # The release archives will contain the correct versions
132- git tag ${{ steps.new_version.outputs.new_version }}
133- git push origin ${{ steps.new_version.outputs.new_version }}
156+ TAG="${{ steps.new_version.outputs.new_version }}"
157+ git fetch --tags origin
158+ if git rev-parse -q --verify "refs/tags/${TAG}" >/dev/null; then
159+ echo "Tag ${TAG} already exists, skipping tag creation"
160+ else
161+ git tag "${TAG}"
162+ git push origin "${TAG}"
163+ fi
134164
135- - name : Create GitHub Release
136- uses : actions/create-release@v1
137- id : create_release
165+ - name : Create GitHub release and upload assets
166+ uses : softprops/action-gh-release@v2
138167 env :
139168 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
140169 with :
141170 tag_name : ${{ steps.new_version.outputs.new_version }}
142- release_name : Release ${{ steps.new_version.outputs.new_version }}
171+ name : Release ${{ steps.new_version.outputs.new_version }}
143172 body : |
144173 ## Changes in ${{ steps.new_version.outputs.new_version }}
145174
146- See [CHANGELOG.md](https://github.com/FROSTR-ORG/igloo-server/blob/master /CHANGELOG.md) for full details.
175+ See [CHANGELOG.md](https://github.com/FROSTR-ORG/igloo-server/blob/main /CHANGELOG.md) for full details.
147176
148177 ### Installation
149178
@@ -162,36 +191,21 @@ jobs:
162191 ```
163192 draft : false
164193 prerelease : false
165-
166- - name : Upload source archive
167- uses : actions/upload-release-asset@v1
168- env :
169- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
170- with :
171- upload_url : ${{ steps.create_release.outputs.upload_url }}
172- asset_path : ./release/igloo-server-${{ steps.new_version.outputs.version_number }}-src.tar.gz
173- asset_name : igloo-server-${{ steps.new_version.outputs.version_number }}-src.tar.gz
174- asset_content_type : application/gzip
175-
176- - name : Upload binary archive
177- uses : actions/upload-release-asset@v1
178- env :
179- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
180- with :
181- upload_url : ${{ steps.create_release.outputs.upload_url }}
182- asset_path : ./release/igloo-server-${{ steps.new_version.outputs.version_number }}.tar.gz
183- asset_name : igloo-server-${{ steps.new_version.outputs.version_number }}.tar.gz
184- asset_content_type : application/gzip
194+ files : |
195+ ./release/igloo-server-${{ steps.new_version.outputs.version_number }}-src.tar.gz
196+ ./release/igloo-server-${{ steps.new_version.outputs.version_number }}.tar.gz
185197
186198 docker :
187199 runs-on : ubuntu-latest
188200 needs : release
201+ permissions :
202+ packages : write
189203
190204 steps :
191205 - name : Checkout code
192206 uses : actions/checkout@v4
193207 with :
194- ref : master
208+ ref : refs/tags/${{ needs.release.outputs.new_version }}
195209
196210 - name : Set up Docker Buildx
197211 uses : docker/setup-buildx-action@v3
0 commit comments