|
| 1 | +name:Build and Publish Binary |
| 2 | + |
| 3 | +on: |
| 4 | +push: |
| 5 | +tags: |
| 6 | + -"v*.*.*"# Trigger on tag creation with versioning pattern |
| 7 | +workflow_dispatch:# Allow manual runs from the GitHub Actions UI |
| 8 | + |
| 9 | +jobs: |
| 10 | +build: |
| 11 | +runs-on:ubuntu-latest |
| 12 | + |
| 13 | +steps: |
| 14 | + -name:Checkout code |
| 15 | +uses:actions/checkout@v3 |
| 16 | + |
| 17 | + -name:Set up Go |
| 18 | +uses:actions/setup-go@v4 |
| 19 | +with: |
| 20 | +go-version:1.18# Use the Go version required by your project |
| 21 | + |
| 22 | + -name:Install Dependencies |
| 23 | +run:go mod tidy# Ensures dependencies are properly installed |
| 24 | + |
| 25 | + -name:Build the binary |
| 26 | +run:| |
| 27 | + go build -o dist/image-optimizer # Build binary with the name image-optimizer |
| 28 | +env: |
| 29 | +GOOS:linux# You can specify other OS like windows or darwin (Mac) |
| 30 | +GOARCH:amd64# Architecture type |
| 31 | + |
| 32 | + -name:Upload binary as artifact |
| 33 | +uses:actions/upload-artifact@v3 |
| 34 | +with: |
| 35 | +name:image-optimizer |
| 36 | +path:dist/image-optimizer |
| 37 | + |
| 38 | +release: |
| 39 | +needs:build |
| 40 | +runs-on:ubuntu-latest |
| 41 | +if:startsWith(github.ref, 'refs/tags/') |
| 42 | + |
| 43 | +steps: |
| 44 | + -name:Download built binary |
| 45 | +uses:actions/download-artifact@v3 |
| 46 | +with: |
| 47 | +name:image-optimizer |
| 48 | + |
| 49 | + -name:Create GitHub Release |
| 50 | +uses:softprops/action-gh-release@v1 |
| 51 | +with: |
| 52 | +files:dist/image-optimizer |
| 53 | +env: |
| 54 | +GITHUB_TOKEN:${{ secrets.GITHUB_TOKEN }} |