|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' # Triggers on tags like v1.0.0, v0.2.1, etc. |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write # Required for creating releases and uploading assets |
| 10 | + |
| 11 | +jobs: |
| 12 | + build: |
| 13 | + name: Build |
| 14 | + runs-on: ubuntu-latest |
| 15 | + |
| 16 | + strategy: |
| 17 | + matrix: |
| 18 | + include: |
| 19 | + - goos: linux |
| 20 | + goarch: amd64 |
| 21 | + binary_name: que |
| 22 | + - goos: linux |
| 23 | + goarch: arm64 |
| 24 | + binary_name: que |
| 25 | + - goos: darwin |
| 26 | + goarch: amd64 |
| 27 | + binary_name: que |
| 28 | + - goos: darwin |
| 29 | + goarch: arm64 |
| 30 | + binary_name: que |
| 31 | + - goos: windows |
| 32 | + goarch: amd64 |
| 33 | + binary_name: que.exe |
| 34 | + - goos: windows |
| 35 | + goarch: arm64 |
| 36 | + binary_name: que.exe |
| 37 | + |
| 38 | + steps: |
| 39 | + - name: Checkout code |
| 40 | + uses: actions/checkout@v4 |
| 41 | + |
| 42 | + - name: Set up Go |
| 43 | + uses: actions/setup-go@v5 |
| 44 | + with: |
| 45 | + go-version-file: 'go.mod' |
| 46 | + |
| 47 | + - name: Get tag name |
| 48 | + id: tag |
| 49 | + run: echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT |
| 50 | + |
| 51 | + - name: Build binary |
| 52 | + env: |
| 53 | + GOOS: ${{ matrix.goos }} |
| 54 | + GOARCH: ${{ matrix.goarch }} |
| 55 | + CGO_ENABLED: 0 |
| 56 | + run: | |
| 57 | + go build -ldflags="-s -w -X main.Version=${{ steps.tag.outputs.TAG_NAME }}" \ |
| 58 | + -o ${{ matrix.binary_name }} \ |
| 59 | + ./cmd/que |
| 60 | +
|
| 61 | + - name: Create archive |
| 62 | + shell: bash |
| 63 | + run: | |
| 64 | + if [ "${{ matrix.goos }}" == "windows" ]; then |
| 65 | + zip que-${{ matrix.goos }}-${{ matrix.goarch }}.zip ${{ matrix.binary_name }} |
| 66 | + else |
| 67 | + tar -czf que-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz ${{ matrix.binary_name }} |
| 68 | + fi |
| 69 | +
|
| 70 | + - name: Upload artifacts |
| 71 | + uses: actions/upload-artifact@v4 |
| 72 | + with: |
| 73 | + name: que-${{ matrix.goos }}-${{ matrix.goarch }} |
| 74 | + path: | |
| 75 | + ${{ matrix.binary_name }} |
| 76 | + que-${{ matrix.goos }}-${{ matrix.goarch }}.* |
| 77 | +
|
| 78 | + release: |
| 79 | + name: Create Release |
| 80 | + needs: build |
| 81 | + runs-on: ubuntu-latest |
| 82 | + if: startsWith(github.ref, 'refs/tags/') |
| 83 | + |
| 84 | + steps: |
| 85 | + - name: Checkout code |
| 86 | + uses: actions/checkout@v4 |
| 87 | + |
| 88 | + - name: Get tag name |
| 89 | + id: tag |
| 90 | + run: echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT |
| 91 | + |
| 92 | + - name: Download all artifacts |
| 93 | + uses: actions/download-artifact@v4 |
| 94 | + with: |
| 95 | + path: ./artifacts |
| 96 | + |
| 97 | + - name: Create checksums |
| 98 | + shell: bash |
| 99 | + working-directory: artifacts |
| 100 | + run: | |
| 101 | + find . -type f \( -name "que" -o -name "que.exe" -o -name "*.tar.gz" -o -name "*.zip" \) | while read file; do |
| 102 | + if command -v sha256sum > /dev/null; then |
| 103 | + sha256sum "$file" >> checksums.txt |
| 104 | + elif command -v shasum > /dev/null; then |
| 105 | + shasum -a 256 "$file" >> checksums.txt |
| 106 | + fi |
| 107 | + done |
| 108 | +
|
| 109 | + - name: Create Release |
| 110 | + uses: softprops/action-gh-release@v2 |
| 111 | + with: |
| 112 | + tag_name: ${{ steps.tag.outputs.TAG_NAME }} |
| 113 | + name: Release ${{ steps.tag.outputs.TAG_NAME }} |
| 114 | + files: | |
| 115 | + artifacts/**/* |
| 116 | + generate_release_notes: true |
| 117 | + draft: false |
| 118 | + prerelease: ${{ contains(steps.tag.outputs.TAG_NAME, '-') }} |
| 119 | + |
0 commit comments