|
1 | | -name: Build and Release |
| 1 | +name: Release |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
5 | 5 | tags: |
6 | | - - 'v*.*.*' # e.g. v1.1.1, v2.0.0 |
| 6 | + - 'v*.*.*' # Matches tags like v1.1.1 or v2.0.0 |
7 | 7 |
|
8 | 8 | jobs: |
9 | 9 | build: |
| 10 | + name: Build & Release Binaries |
10 | 11 | runs-on: ubuntu-latest |
11 | | - strategy: |
12 | | - matrix: |
13 | | - os: [linux, macos, windows] |
14 | | - arch: [amd64] |
| 12 | + |
| 13 | + permissions: |
| 14 | + contents: write # Required to upload release assets |
15 | 15 |
|
16 | 16 | steps: |
17 | | - - name: Checkout code |
18 | | - uses: actions/checkout@v3 |
| 17 | + - name: ⬇️ Checkout code |
| 18 | + uses: actions/checkout@v4 |
19 | 19 |
|
20 | | - - name: Set up Go |
21 | | - uses: actions/setup-go@v4 |
| 20 | + - name: 🛠️ Set up Go |
| 21 | + uses: actions/setup-go@v5 |
22 | 22 | with: |
23 | | - go-version: '1.20' |
| 23 | + go-version: '1.21' |
| 24 | + |
| 25 | + - name: 🧼 Clean previous builds |
| 26 | + run: rm -rf dist && mkdir dist |
24 | 27 |
|
25 | | - - name: Build binary |
| 28 | + - name: 📦 Build for Linux |
26 | 29 | run: | |
27 | | - mkdir -p dist/${{ matrix.os }} |
28 | | - if [[ "${{ matrix.os }}" == "linux" ]]; then |
29 | | - GOOS=linux GOARCH=${{ matrix.arch }} CGO_ENABLED=0 \ |
30 | | - go build -ldflags="-s -w" -o dist/linux/smartcommit-linux . |
31 | | - elif [[ "${{ matrix.os }}" == "macos" ]]; then |
32 | | - GOOS=darwin GOARCH=${{ matrix.arch }} CGO_ENABLED=0 \ |
33 | | - go build -ldflags="-s -w" -o dist/macos/smartcommit-macos . |
34 | | - else |
35 | | - GOOS=windows GOARCH=${{ matrix.arch }} CGO_ENABLED=0 \ |
36 | | - go build -ldflags="-s -w" -o dist/windows/smartcommit-windows.exe . |
37 | | - fi |
| 30 | + VERSION=${GITHUB_REF#refs/tags/} |
| 31 | + GOOS=linux GOARCH=amd64 go build -ldflags "-X 'smartcommit/cmd.version=${VERSION}'" -o dist/smartcommit-linux |
38 | 32 |
|
39 | | - - name: Package archives |
| 33 | + - name: 📦 Build for macOS |
40 | 34 | run: | |
41 | | - if [[ "${{ matrix.os }}" == "linux" ]]; then |
42 | | - tar -czvf dist/smartcommit-linux.tar.gz -C dist/linux smartcommit-linux |
43 | | - elif [[ "${{ matrix.os }}" == "macos" ]]; then |
44 | | - tar -czvf dist/smartcommit-macos.tar.gz -C dist/macos smartcommit-macos |
45 | | - else |
46 | | - tar -czvf dist/smartcommit-windows.tar.gz -C dist/windows smartcommit-windows.exe |
47 | | - fi |
| 35 | + VERSION=${GITHUB_REF#refs/tags/} |
| 36 | + GOOS=darwin GOARCH=amd64 go build -ldflags "-X 'smartcommit/cmd.version=${VERSION}'" -o dist/smartcommit-macos |
48 | 37 |
|
49 | | - - name: Create GitHub Release |
50 | | - id: create_release |
51 | | - uses: softprops/action-gh-release@v1 |
52 | | - with: |
53 | | - tag_name: ${{ github.ref_name }} |
54 | | - env: |
55 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 38 | + - name: 📦 Build for Windows |
| 39 | + run: | |
| 40 | + VERSION=${GITHUB_REF#refs/tags/} |
| 41 | + GOOS=windows GOARCH=amd64 go build -ldflags "-X 'smartcommit/cmd.version=${VERSION}'" -o dist/smartcommit-windows.exe |
56 | 42 |
|
57 | | - - name: Upload Release Assets |
58 | | - uses: softprops/action-gh-release@v1 |
| 43 | + - name: 📚 Package binaries |
| 44 | + run: | |
| 45 | + cd dist |
| 46 | + tar -czf smartcommit-linux.tar.gz smartcommit-linux |
| 47 | + tar -czf smartcommit-macos.tar.gz smartcommit-macos |
| 48 | + tar -czf smartcommit-windows.tar.gz smartcommit-windows.exe |
| 49 | +
|
| 50 | + - name: 🚀 Create GitHub Release and Upload Assets |
| 51 | + uses: softprops/action-gh-release@v2 |
59 | 52 | with: |
| 53 | + name: ${{ github.ref_name }} |
| 54 | + tag_name: ${{ github.ref_name }} |
60 | 55 | files: | |
61 | 56 | dist/smartcommit-linux.tar.gz |
62 | 57 | dist/smartcommit-macos.tar.gz |
|
0 commit comments