|
| 1 | +name: Build and Release Dave |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - master |
| 8 | + paths: |
| 9 | + - VERSION |
| 10 | + - .github/workflows/release.yml |
| 11 | + |
| 12 | +jobs: |
| 13 | + build: |
| 14 | + name: Build Go Project |
| 15 | + runs-on: ubuntu-latest |
| 16 | + |
| 17 | + steps: |
| 18 | + - name: Checkout repository |
| 19 | + uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - name: Set up Go |
| 22 | + uses: actions/setup-go@v5 |
| 23 | + with: |
| 24 | + go-version: 'stable' |
| 25 | + - name: Install Mage |
| 26 | + run: | |
| 27 | + go install github.com/magefile/mage@latest |
| 28 | + echo "$(go env GOPATH)/bin" >> $GITHUB_PATH |
| 29 | +
|
| 30 | + - name: Build |
| 31 | + run: | |
| 32 | + go mod tidy |
| 33 | + mage buildreleases |
| 34 | +
|
| 35 | + - name: Upload artifacts |
| 36 | + uses: actions/upload-artifact@v4 |
| 37 | + with: |
| 38 | + name: binaries |
| 39 | + path: dist/ |
| 40 | + |
| 41 | + release: |
| 42 | + name: Create GitHub Release |
| 43 | + needs: build |
| 44 | + runs-on: ubuntu-latest |
| 45 | + |
| 46 | + steps: |
| 47 | + - name: Checkout repository |
| 48 | + uses: actions/checkout@v4 |
| 49 | + |
| 50 | + - name: Read version from VERSION file |
| 51 | + id: version |
| 52 | + run: echo "VERSION=$(cat VERSION)" >> $GITHUB_ENV |
| 53 | + |
| 54 | + - name: Check if release already exists |
| 55 | + run: | |
| 56 | + RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" \ |
| 57 | + -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ |
| 58 | + -H "Accept: application/vnd.github.v3+json" \ |
| 59 | + https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ env.VERSION }}) |
| 60 | +
|
| 61 | + if [ "$RESPONSE" == "200" ]; then |
| 62 | + echo "⚠️ Release ${{ env.VERSION }} already exists. Exiting..." |
| 63 | + exit 1 |
| 64 | + else |
| 65 | + echo "✅ No existing release found. Proceeding..." |
| 66 | + fi |
| 67 | +
|
| 68 | + - name: Download artifacts |
| 69 | + uses: actions/download-artifact@v4 |
| 70 | + with: |
| 71 | + name: binaries |
| 72 | + path: dist/ |
| 73 | + |
| 74 | + - name: Create GitHub Release |
| 75 | + uses: softprops/action-gh-release@v2 |
| 76 | + with: |
| 77 | + tag_name: ${{ env.VERSION }} |
| 78 | + name: Release ${{ env.VERSION }} |
| 79 | + files: dist/* |
| 80 | + body: "Automated release for version ${{ env.VERSION }}" |
| 81 | + env: |
| 82 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments