fix: release
R
Rüdiger Küpper
<rpr@9it.de>
committete am 19.02.2026 07:12
40228e654ec3e606f7646b1c4f4b75b6a53eb998
| @@ -0,0 +1,335 @@ | ||
| 1 | +name: build-and-release |
|
| 2 | + | |
| 3 | +on: |
|
| 4 | +push: |
|
| 5 | +branches: [main] |
|
| 6 | +workflow_dispatch: |
|
| 7 | +# tags: |
|
| 8 | +# - 'v*' # z.B. v1.2.3 |
|
| 9 | + | |
| 10 | +permissions: |
|
| 11 | +contents: write |
|
| 12 | +packages: write |
|
| 13 | +id-token: write |
|
| 14 | +issues: write |
|
| 15 | +pull-requests: write |
|
| 16 | + | |
| 17 | +env: |
|
| 18 | +# Hier kannst du einen Default-Name definieren, der in die Artefakte wandert |
|
| 19 | + APP_VERSION: ${{ github.ref_name }} |
|
| 20 | + GH_TOKEN: ${{ secrets.RELEASE_TOKEN }} |
|
| 21 | +TARGET_REPO: owner/target-repo |
|
| 22 | + TAG: ${{ github.ref_name }} |
|
| 23 | +REGISTRY: ghcr.io |
|
| 24 | + IMAGE_NAME: ${{ github.repository }}-2 |
|
| 25 | + | |
| 26 | +jobs: |
|
| 27 | + | |
| 28 | +# Job 1: Automatisches Semver Tagging |
|
| 29 | +# create-version-tag: |
|
| 30 | +# name: Create Version Tag |
|
| 31 | +# # runs-on: ubuntu-latest |
|
| 32 | +# # runs-on: [self-hosted, macbook] |
|
| 33 | +# runs-on: [self-hosted] |
|
| 34 | +# outputs: |
|
| 35 | + # new_tag: ${{ steps.tag_version.outputs.new_tag }} |
|
| 36 | + # changelog: ${{ steps.tag_version.outputs.changelog }} |
|
| 37 | +# permissions: |
|
| 38 | +# contents: write |
|
| 39 | +# steps: |
|
| 40 | +# - name: Checkout |
|
| 41 | +# uses: actions/checkout@v6 |
|
| 42 | +# with: |
|
| 43 | +# fetch-depth: 0 |
|
| 44 | + | |
| 45 | +# - name: Bump version and push tag |
|
| 46 | +# id: tag_version |
|
| 47 | +# uses: mathieudutour/github-tag-action@v6.2 |
|
| 48 | +# with: |
|
| 49 | + # github_token: ${{ secrets.GITHUB_TOKEN }} |
|
| 50 | +# default_bump: patch |
|
| 51 | +# release_branches: main |
|
| 52 | +# # fix: = patch (0.0.1) |
|
| 53 | +# # feat: = minor (0.1.0) |
|
| 54 | +# # BREAKING CHANGE: = major (1.0.0) |
|
| 55 | + | |
| 56 | +# - name: Show new version |
|
| 57 | +# run: | |
|
| 58 | + # echo "New version: ${{ steps.tag_version.outputs.new_tag }}" |
|
| 59 | + # echo "Changelog: ${{ steps.tag_version.outputs.changelog }}" |
|
| 60 | + | |
| 61 | +create-version-tag: |
|
| 62 | +uses: 9it-full-service/shared-workflows/.github/workflows/prepare.yml@main |
|
| 63 | +with: |
|
| 64 | + version_override: ${{ github.event.inputs.version || '' }} |
|
| 65 | +default_version: 'dev' |
|
| 66 | + | |
| 67 | +build: |
|
| 68 | +runs-on: [ arc-runner-set-arm64 ] |
|
| 69 | +# runs-on: [ self-hosted ] |
|
| 70 | +needs: [ "create-version-tag" ] |
|
| 71 | +strategy: |
|
| 72 | +fail-fast: false |
|
| 73 | +matrix: |
|
| 74 | +# goos: [linux,] |
|
| 75 | +# goarch: [arm64] |
|
| 76 | +goos: [linux, darwin] |
|
| 77 | +goarch: [amd64, arm64] |
|
| 78 | +# goos: [linux, darwin, windows] |
|
| 79 | +# goarch: [amd64, arm64,arm] |
|
| 80 | +# exclude: |
|
| 81 | +# # ARM 32-bit ist nur für Linux sinnvoll |
|
| 82 | +# - goos: darwin |
|
| 83 | +# goarch: arm |
|
| 84 | +# - goos: windows |
|
| 85 | +# goarch: arm |
|
| 86 | + | |
| 87 | +steps: |
|
| 88 | +- uses: actions/checkout@v6 |
|
| 89 | + | |
| 90 | +- name: Setup Go |
|
| 91 | +uses: actions/setup-go@v6 |
|
| 92 | +with: |
|
| 93 | +go-version: '1.25' |
|
| 94 | +cache: true |
|
| 95 | + | |
| 96 | +# - name: Print build matrix |
|
| 97 | +# run: | |
|
| 98 | + # echo "GOOS=${{ matrix.goos }}" |
|
| 99 | + # echo "GOARCH=${{ matrix.goarch }}" |
|
| 100 | + # echo "TAG=${{ github.ref_name }}" |
|
| 101 | + | |
| 102 | +- name: Set build timestamp |
|
| 103 | +id: timestamp |
|
| 104 | +run: echo "BUILD_TIMESTAMP=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> $GITHUB_OUTPUT |
|
| 105 | + | |
| 106 | +- name: Print build matrix |
|
| 107 | +run: | |
|
| 108 | + echo "GOOS=${{ matrix.goos }}" |
|
| 109 | + echo "GOARCH=${{ matrix.goarch }}" |
|
| 110 | + echo "TAG=${{ needs.create-version-tag.outputs.version }}" |
|
| 111 | + echo "VERSION=${{ needs.create-version-tag.outputs.version }}" |
|
| 112 | + echo "COMMIT=${{ github.sha }}" |
|
| 113 | + echo "BUILD_TIMESTAMP=${{ steps.timestamp.outputs.BUILD_TIMESTAMP }}" |
|
| 114 | + | |
| 115 | +- name: Build quilldrop |
|
| 116 | +env: |
|
| 117 | + GOOS: ${{ matrix.goos }} |
|
| 118 | + GOARCH: ${{ matrix.goarch }} |
|
| 119 | + VERSION: ${{ needs.create-version-tag.outputs.version }} |
|
| 120 | + COMMIT: ${{ github.sha }} |
|
| 121 | + BUILD_TIMESTAMP: ${{ steps.timestamp.outputs.BUILD_TIMESTAMP }} |
|
| 122 | +run: | |
|
| 123 | +set -euo pipefail |
|
| 124 | +mkdir -p dist |
|
| 125 | + BIN_NAME="quilldrop-${GOOS}-${GOARCH}" |
|
| 126 | + OUT="dist/${BIN_NAME}" |
|
| 127 | +# Windows: .exe |
|
| 128 | + if [ "${GOOS}" = "windows" ]; then OUT="${OUT}.exe"; fi |
|
| 129 | +# Build (im Unterordner) |
|
| 130 | +(cd . && CGO_ENABLED=0 go build -trimpath -ldflags="-s -w \ |
|
| 131 | + -X 'main.version=${VERSION}' \ |
|
| 132 | + -X 'main.commit=${COMMIT}' \ |
|
| 133 | + -X 'main.date=${BUILD_TIMESTAMP}'" -o "../${OUT}") |
|
| 134 | +# go mod init quilldrop && go mod tidy && \ |
|
| 135 | +go mod tidy && \ |
|
| 136 | +# CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo \ |
|
| 137 | +# -ldflags="-s -w \ |
|
| 138 | + # -X 'main.version=${VERSION}' \ |
|
| 139 | + # -X 'main.commit=${COMMIT}' \ |
|
| 140 | + # -X 'main.date=${BUILD_TIMESTAMP}'" \ |
|
| 141 | +# -o vm-tracker-api main.go |
|
| 142 | +# Paket |
|
| 143 | + if [[ "${OUT}" == *.exe ]]; then |
|
| 144 | + (cd dist && zip "${BIN_NAME}.zip" "${BIN_NAME}.exe") |
|
| 145 | +else |
|
| 146 | + (cd dist && tar -czf "${BIN_NAME}.tar.gz" "${BIN_NAME}") |
|
| 147 | +fi |
|
| 148 | + | |
| 149 | +- name: Build vm-tracker-client |
|
| 150 | +env: |
|
| 151 | + GOOS: ${{ matrix.goos }} |
|
| 152 | + GOARCH: ${{ matrix.goarch }} |
|
| 153 | + VERSION: ${{ needs.create-version-tag.outputs.version }} # ← hinzufügen |
|
| 154 | + COMMIT: ${{ github.sha }} # ← hinzufügen |
|
| 155 | + # BUILD_TIMESTAMP: ${{ github.event.head_commit.timestamp }} |
|
| 156 | +BUILD_TIMESTAMP: $(date -u +%Y-%m-%dT%H:%M:%SZ) |
|
| 157 | +run: | |
|
| 158 | +set -euo pipefail |
|
| 159 | +mkdir -p dist |
|
| 160 | + BIN_NAME="quilldrop-${GOOS}-${GOARCH}" |
|
| 161 | + OUT="dist/${BIN_NAME}" |
|
| 162 | + if [ "${GOOS}" = "windows" ]; then OUT="${OUT}.exe"; fi |
|
| 163 | +(cd . && CGO_ENABLED=0 go build -trimpath -ldflags="-s -w \ |
|
| 164 | + -X 'main.version=${VERSION}' \ |
|
| 165 | + -X 'main.commit=${COMMIT}' \ |
|
| 166 | + -X 'main.date=${BUILD_TIMESTAMP}'" -o "../${OUT}") |
|
| 167 | + if [[ "${OUT}" == *.exe ]]; then |
|
| 168 | + (cd dist && zip "${BIN_NAME}.zip" "${BIN_NAME}.exe") |
|
| 169 | +else |
|
| 170 | + (cd dist && tar -czf "${BIN_NAME}.tar.gz" "${BIN_NAME}") |
|
| 171 | +fi |
|
| 172 | + | |
| 173 | +- name: Checksums erzeugen |
|
| 174 | +run: | |
|
| 175 | +set -euo pipefail |
|
| 176 | +cd dist |
|
| 177 | +# Ein Checksum-File pro Matrix-Kombination |
|
| 178 | + # FILE="CHECKSUMS-${{ env.APP_VERSION }}-${{ matrix.goos }}-${{ matrix.goarch }}.txt" |
|
| 179 | + FILE="CHECKSUMS-${{ needs.create-version-tag.outputs.version }}-${{ matrix.goos }}-${{ matrix.goarch }}.txt" |
|
| 180 | +shopt -s nullglob |
|
| 181 | +for f in *.tar.gz *.zip; do |
|
| 182 | +sha256sum "$f" >> "$FILE" |
|
| 183 | +done |
|
| 184 | +cat "$FILE" |
|
| 185 | + | |
| 186 | +- name: Upload artifacts (unique per matrix) |
|
| 187 | +uses: actions/upload-artifact@v5 |
|
| 188 | +with: |
|
| 189 | + name: release-bundles-${{ matrix.goos }}-${{ matrix.goarch }}-${{ github.run_attempt }} |
|
| 190 | +path: | |
|
| 191 | +dist/*.tar.gz |
|
| 192 | +dist/*.zip |
|
| 193 | +dist/CHECKSUMS-*.txt |
|
| 194 | +if-no-files-found: error |
|
| 195 | +compression-level: 6 |
|
| 196 | + | |
| 197 | +release: |
|
| 198 | +needs: [ "build", "create-version-tag" ] |
|
| 199 | +runs-on: ubuntu-latest |
|
| 200 | +steps: |
|
| 201 | +- name: Download all build artifacts (merged) |
|
| 202 | +uses: actions/download-artifact@v6 |
|
| 203 | +with: |
|
| 204 | +pattern: release-bundles-* |
|
| 205 | +merge-multiple: true |
|
| 206 | +path: dist |
|
| 207 | + | |
| 208 | +- name: Übersicht |
|
| 209 | +run: ls -la dist |
|
| 210 | + | |
| 211 | +# --- Option A: Release in anderes Repo via gh CLI --- |
|
| 212 | +- name: Create release in target repo |
|
| 213 | +env: |
|
| 214 | + GH_TOKEN: ${{ secrets.RELEASE_TOKEN }} # 👈 wichtig: GH_TOKEN, nicht RELEASE_TOKEN |
|
| 215 | +TARGET_REPO: 9it-full-service/quilldrop |
|
| 216 | + TAG: ${{ needs.create-version-tag.outputs.version }} |
|
| 217 | + # TAG: ${{ github.ref_name }} |
|
| 218 | +run: | |
|
| 219 | +set -euo pipefail |
|
| 220 | +gh release create "$TAG" \ |
|
| 221 | +--repo "$TARGET_REPO" \ |
|
| 222 | +--title "$TAG" \ |
|
| 223 | + --notes "Automated release from ${GITHUB_REPOSITORY}@${GITHUB_SHA}" \ |
|
| 224 | +|| echo "Release exists, continue to upload assets." |
|
| 225 | + | |
| 226 | +gh release upload "$TAG" dist/* --repo "$TARGET_REPO" --clobber |
|
| 227 | + | |
| 228 | +# build-and-push-docker: |
|
| 229 | +# name: Build Multi-arch Docker |
|
| 230 | +# needs: [create-version-tag, build] |
|
| 231 | +# runs-on: [self-hosted] |
|
| 232 | +# permissions: |
|
| 233 | +# contents: read |
|
| 234 | +# packages: write |
|
| 235 | +# steps: |
|
| 236 | +# - name: Checkout repository |
|
| 237 | +# uses: actions/checkout@v6 |
|
| 238 | + | |
| 239 | +# # Alle Artifacts herunterladen |
|
| 240 | +# - name: Download build artifacts |
|
| 241 | +# uses: actions/download-artifact@v6 |
|
| 242 | +# with: |
|
| 243 | +# path: ./artifacts |
|
| 244 | + | |
| 245 | +# # Übersicht was heruntergeladen wurde |
|
| 246 | +# - name: List downloaded artifacts |
|
| 247 | +# run: | |
|
| 248 | +# echo "=== Downloaded artifacts ===" |
|
| 249 | +# ls -laR artifacts/ |
|
| 250 | + | |
| 251 | +# # Binaries für Docker vorbereiten |
|
| 252 | +# - name: Prepare binaries for Docker |
|
| 253 | +# run: | |
|
| 254 | +# set -euo pipefail |
|
| 255 | + # mkdir -p docker-bin/{amd64,arm64} |
|
| 256 | + |
|
| 257 | +# # Suche und extrahiere amd64 binary |
|
| 258 | +# echo "Searching for amd64 binary..." |
|
| 259 | +# AMD64_TAR=$(find artifacts -name "vm-tracker-api-linux-amd64.tar.gz" -type f | head -1) |
|
| 260 | +# if [ -n "$AMD64_TAR" ]; then |
|
| 261 | +# echo "Found: $AMD64_TAR" |
|
| 262 | +# tar -xzf "$AMD64_TAR" -C docker-bin/amd64/ |
|
| 263 | +# mv docker-bin/amd64/vm-tracker-api-linux-amd64 docker-bin/amd64/vm-tracker-api |
|
| 264 | +# chmod +x docker-bin/amd64/vm-tracker-api |
|
| 265 | +# else |
|
| 266 | +# echo "ERROR: amd64 binary not found!" |
|
| 267 | +# exit 1 |
|
| 268 | +# fi |
|
| 269 | + |
|
| 270 | +# # Suche und extrahiere arm64 binary |
|
| 271 | +# echo "Searching for arm64 binary..." |
|
| 272 | +# ARM64_TAR=$(find artifacts -name "vm-tracker-api-linux-arm64.tar.gz" -type f | head -1) |
|
| 273 | +# if [ -n "$ARM64_TAR" ]; then |
|
| 274 | +# echo "Found: $ARM64_TAR" |
|
| 275 | +# tar -xzf "$ARM64_TAR" -C docker-bin/arm64/ |
|
| 276 | +# mv docker-bin/arm64/vm-tracker-api-linux-arm64 docker-bin/arm64/vm-tracker-api |
|
| 277 | +# chmod +x docker-bin/arm64/vm-tracker-api |
|
| 278 | +# else |
|
| 279 | +# echo "ERROR: arm64 binary not found!" |
|
| 280 | +# exit 1 |
|
| 281 | +# fi |
|
| 282 | + |
|
| 283 | +# echo "=== Prepared binaries ===" |
|
| 284 | +# ls -la docker-bin/*/ |
|
| 285 | +# file docker-bin/*/vm-tracker-api |
|
| 286 | + | |
| 287 | +# - name: Set up QEMU |
|
| 288 | +# uses: docker/setup-qemu-action@v3 |
|
| 289 | + | |
| 290 | +# - name: Set up Docker Buildx |
|
| 291 | +# uses: docker/setup-buildx-action@v3 |
|
| 292 | + | |
| 293 | +# - name: Log in to Container Registry |
|
| 294 | +# uses: docker/login-action@v3 |
|
| 295 | +# with: |
|
| 296 | + # registry: ${{ env.REGISTRY }} |
|
| 297 | + # username: ${{ github.actor }} |
|
| 298 | + # password: ${{ secrets.GITHUB_TOKEN }} |
|
| 299 | + | |
| 300 | +# - name: Set build metadata |
|
| 301 | +# id: meta |
|
| 302 | +# run: | |
|
| 303 | + # echo "VERSION=${{ needs.create-version-tag.outputs.new_tag }}" >> $GITHUB_ENV |
|
| 304 | + # echo "COMMIT=${GITHUB_SHA}" >> $GITHUB_ENV |
|
| 305 | +# echo "BUILD_TIMESTAMP=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> $GITHUB_ENV |
|
| 306 | + | |
| 307 | +# - name: Build and push Docker image |
|
| 308 | +# uses: docker/build-push-action@v6 |
|
| 309 | +# with: |
|
| 310 | +# context: . |
|
| 311 | +# platforms: linux/amd64,linux/arm64 |
|
| 312 | +# push: true |
|
| 313 | +# tags: | |
|
| 314 | + # ghcr.io/9it-full-service/vm-tracker-api:${{ needs.create-version-tag.outputs.new_tag }} |
|
| 315 | +# ghcr.io/9it-full-service/vm-tracker-api:latest |
|
| 316 | +# labels: | |
|
| 317 | + # org.opencontainers.image.version=${{ needs.create-version-tag.outputs.new_tag }} |
|
| 318 | + # org.opencontainers.image.created=${{ env.BUILD_TIMESTAMP }} |
|
| 319 | + # org.opencontainers.image.revision=${{ github.sha }} |
|
| 320 | +# build-args: | |
|
| 321 | + # VERSION=${{ env.VERSION }} |
|
| 322 | + # COMMIT=${{ env.COMMIT }} |
|
| 323 | + # BUILD_TIMESTAMP=${{ env.BUILD_TIMESTAMP }} |
|
| 324 | +# # cache-from: type=gha |
|
| 325 | +# # cache-to: type=gha,mode=max |
|
| 326 | +# provenance: false |
|
| 327 | + | |
| 328 | +# # - name: Clean up Docker images |
|
| 329 | +# # if: always() # Also run in case of errors |
|
| 330 | +# # run: | |
|
| 331 | +# # # remove dangling images |
|
| 332 | + # # docker rmi ghcr.io/9it-full-service/vm-tracker-api:${{ needs.create-version-tag.outputs.new_tag }} |
|
| 333 | +# # docker rmi ghcr.io/9it-full-service/vm-tracker-api:latest |
|
| 334 | +# # # docker image prune -f |
|
| 335 | + |