|
| 1 | +name: Release & Publish |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - master |
| 8 | + paths: |
| 9 | + - 'VERSION' |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: write |
| 13 | + |
| 14 | +jobs: |
| 15 | + check-version: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + outputs: |
| 18 | + version: ${{ steps.get_version.outputs.version }} |
| 19 | + tag_exists: ${{ steps.check_tag.outputs.exists }} |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@v4 |
| 22 | + - name: Get version |
| 23 | + id: get_version |
| 24 | + run: | |
| 25 | + VERSION=$(cat VERSION | tr -d '[:space:]') |
| 26 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 27 | + - name: Check Tag |
| 28 | + id: check_tag |
| 29 | + run: | |
| 30 | + git fetch --tags |
| 31 | + if git rev-parse "v${{ steps.get_version.outputs.version }}" >/dev/null 2>&1; then |
| 32 | + echo "exists=true" >> $GITHUB_OUTPUT |
| 33 | + else |
| 34 | + echo "exists=false" >> $GITHUB_OUTPUT |
| 35 | + fi |
| 36 | +
|
| 37 | + build-binaries: |
| 38 | + needs: check-version |
| 39 | + if: needs.check-version.outputs.tag_exists == 'false' |
| 40 | + name: Build ${{ matrix.asset_name }} |
| 41 | + runs-on: ${{ matrix.os }} |
| 42 | + strategy: |
| 43 | + fail-fast: false |
| 44 | + matrix: |
| 45 | + include: |
| 46 | + # --- LINUX --- |
| 47 | + # Standard Server/Desktop (x86_64) |
| 48 | + - os: ubuntu-latest |
| 49 | + asset_name: autolinux-linux-x86_64 |
| 50 | + goos: linux |
| 51 | + goarch: amd64 |
| 52 | + |
| 53 | + # ARM64 (Raspberry Pi 4, AWS Graviton) |
| 54 | + - os: ubuntu-latest |
| 55 | + asset_name: autolinux-linux-aarch64 |
| 56 | + goos: linux |
| 57 | + goarch: arm64 |
| 58 | + |
| 59 | + # ARMv7 (Raspberry Pi 2/3) |
| 60 | + - os: ubuntu-latest |
| 61 | + asset_name: autolinux-linux-armv7 |
| 62 | + goos: linux |
| 63 | + goarch: arm |
| 64 | + goarm: "7" |
| 65 | + |
| 66 | + # --- MACOS --- |
| 67 | + # Apple Silicon (M1/M2/M3) |
| 68 | + - os: macos-latest |
| 69 | + asset_name: autolinux-darwin-aarch64 |
| 70 | + goos: darwin |
| 71 | + goarch: arm64 |
| 72 | + |
| 73 | + # Intel Mac |
| 74 | + - os: macos-latest |
| 75 | + asset_name: autolinux-darwin-x86_64 |
| 76 | + goos: darwin |
| 77 | + goarch: amd64 |
| 78 | + |
| 79 | + steps: |
| 80 | + - uses: actions/checkout@v4 |
| 81 | + |
| 82 | + - name: Set up Go |
| 83 | + uses: actions/setup-go@v5 |
| 84 | + with: |
| 85 | + go-version: '1.25' |
| 86 | + |
| 87 | + - name: Build Binary |
| 88 | + env: |
| 89 | + GOOS: ${{ matrix.goos }} |
| 90 | + GOARCH: ${{ matrix.goarch }} |
| 91 | + GOARM: ${{ matrix.goarm || '' }} |
| 92 | + run: | |
| 93 | + mkdir -p build |
| 94 | + go build -ldflags="-s -w" -o build/${{ matrix.asset_name }} ./cmd/autolinux |
| 95 | +
|
| 96 | + - name: Prepare Asset |
| 97 | + shell: bash |
| 98 | + run: | |
| 99 | + chmod +x build/${{ matrix.asset_name }} |
| 100 | +
|
| 101 | + - name: Upload Artifact |
| 102 | + uses: actions/upload-artifact@v4 |
| 103 | + with: |
| 104 | + name: binary-${{ matrix.asset_name }} |
| 105 | + path: build/${{ matrix.asset_name }} |
| 106 | + |
| 107 | + create-release: |
| 108 | + needs: [check-version, build-binaries] |
| 109 | + runs-on: ubuntu-latest |
| 110 | + steps: |
| 111 | + - uses: actions/checkout@v4 |
| 112 | + with: |
| 113 | + fetch-depth: 0 |
| 114 | + |
| 115 | + - name: Download Artifacts |
| 116 | + uses: actions/download-artifact@v4 |
| 117 | + with: |
| 118 | + pattern: binary-* |
| 119 | + merge-multiple: true |
| 120 | + path: build |
| 121 | + |
| 122 | + - name: Generate Changelog |
| 123 | + uses: orhun/git-cliff-action@v4 |
| 124 | + id: git_cliff |
| 125 | + with: |
| 126 | + config: .github/external/cliff.toml |
| 127 | + args: --verbose --tag ${{ needs.check-version.outputs.version }} --strip header |
| 128 | + env: |
| 129 | + OUTPUT: CHANGELOG.md |
| 130 | + |
| 131 | + - name: Create Release |
| 132 | + uses: softprops/action-gh-release@v1 |
| 133 | + with: |
| 134 | + tag_name: ${{ needs.check-version.outputs.version }} |
| 135 | + name: Release ${{ needs.check-version.outputs.version }} |
| 136 | + body: ${{ steps.git_cliff.outputs.content }} |
| 137 | + files: | |
| 138 | + build/autolinux-linux-x86_64 |
| 139 | + build/autolinux-linux-aarch64 |
| 140 | + build/autolinux-linux-armv7 |
| 141 | + build/autolinux-darwin-aarch64 |
| 142 | + build/autolinux-darwin-x86_64 |
| 143 | + draft: false |
| 144 | + env: |
| 145 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments