|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main, dev] |
| 6 | + |
| 7 | +jobs: |
| 8 | + release: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + permissions: |
| 11 | + contents: write |
| 12 | + |
| 13 | + steps: |
| 14 | + - uses: actions/checkout@v4 |
| 15 | + with: |
| 16 | + fetch-depth: 0 |
| 17 | + |
| 18 | + - name: Set up Go |
| 19 | + uses: actions/setup-go@v5 |
| 20 | + with: |
| 21 | + go-version-file: go.mod |
| 22 | + |
| 23 | + - name: Read version |
| 24 | + id: version |
| 25 | + run: | |
| 26 | + if [ ! -f VERSION ]; then |
| 27 | + echo "ERROR: VERSION file not found" |
| 28 | + exit 1 |
| 29 | + fi |
| 30 | + VERSION=$(cat VERSION | tr -d '[:space:]') |
| 31 | + if [ -z "$VERSION" ]; then |
| 32 | + echo "ERROR: VERSION file is empty" |
| 33 | + exit 1 |
| 34 | + fi |
| 35 | + if [ "${{ github.ref_name }}" != "main" ]; then |
| 36 | + VERSION="dev" |
| 37 | + fi |
| 38 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 39 | + echo "short_sha=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT" |
| 40 | +
|
| 41 | + - name: Build binary |
| 42 | + run: | |
| 43 | + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \ |
| 44 | + -ldflags="-w -s -X main.version=${{ steps.version.outputs.version }}" \ |
| 45 | + -o growcast-linux-amd64 \ |
| 46 | + ./cmd/growcast/... |
| 47 | +
|
| 48 | + - name: Log in to Docker Hub |
| 49 | + uses: docker/login-action@v3 |
| 50 | + with: |
| 51 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 52 | + password: ${{ secrets.DOCKER_PASSWORD }} |
| 53 | + |
| 54 | + - name: Set up Docker Buildx |
| 55 | + uses: docker/setup-buildx-action@v3 |
| 56 | + |
| 57 | + # --- main branch: versioned + latest tags --- |
| 58 | + |
| 59 | + - name: Build and push CPU image (main) |
| 60 | + if: github.ref_name == 'main' |
| 61 | + uses: docker/build-push-action@v6 |
| 62 | + with: |
| 63 | + context: . |
| 64 | + file: Dockerfile |
| 65 | + push: true |
| 66 | + tags: | |
| 67 | + dwot/growcast:${{ steps.version.outputs.version }} |
| 68 | + dwot/growcast:latest |
| 69 | + cache-from: type=gha |
| 70 | + cache-to: type=gha,mode=max |
| 71 | + |
| 72 | + - name: Build and push GPU image (main) |
| 73 | + if: github.ref_name == 'main' |
| 74 | + uses: docker/build-push-action@v6 |
| 75 | + with: |
| 76 | + context: . |
| 77 | + file: Dockerfile.gpu |
| 78 | + push: true |
| 79 | + tags: | |
| 80 | + dwot/growcast:${{ steps.version.outputs.version }}-gpu |
| 81 | + dwot/growcast:gpu-latest |
| 82 | + cache-from: type=gha |
| 83 | + cache-to: type=gha,mode=max |
| 84 | + |
| 85 | + - name: Generate release notes |
| 86 | + if: github.ref_name == 'main' |
| 87 | + id: release_notes |
| 88 | + run: | |
| 89 | + VERSION=${{ steps.version.outputs.version }} |
| 90 | + PREV_TAG=$(git tag --sort=-version:refname | grep -v "^v${VERSION}$" | head -n1) |
| 91 | + if [ -z "$PREV_TAG" ]; then |
| 92 | + RANGE="HEAD" |
| 93 | + else |
| 94 | + RANGE="${PREV_TAG}..HEAD" |
| 95 | + fi |
| 96 | + NOTES=$(git log $RANGE --pretty=format:"- %s (%h)" --no-merges) |
| 97 | + if [ -z "$NOTES" ]; then |
| 98 | + NOTES="- Initial release" |
| 99 | + fi |
| 100 | + { |
| 101 | + echo "notes<<EOF" |
| 102 | + echo "## What's Changed" |
| 103 | + echo "" |
| 104 | + echo "$NOTES" |
| 105 | + echo "EOF" |
| 106 | + } >> "$GITHUB_OUTPUT" |
| 107 | +
|
| 108 | + - name: Create git tag |
| 109 | + if: github.ref_name == 'main' |
| 110 | + run: | |
| 111 | + VERSION=${{ steps.version.outputs.version }} |
| 112 | + if git rev-parse "v${VERSION}" >/dev/null 2>&1; then |
| 113 | + echo "Tag v${VERSION} already exists, skipping" |
| 114 | + else |
| 115 | + git config user.name "github-actions[bot]" |
| 116 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 117 | + git tag "v${VERSION}" |
| 118 | + git push origin "v${VERSION}" |
| 119 | + fi |
| 120 | +
|
| 121 | + - name: Create GitHub Release |
| 122 | + if: github.ref_name == 'main' |
| 123 | + uses: softprops/action-gh-release@v2 |
| 124 | + with: |
| 125 | + tag_name: v${{ steps.version.outputs.version }} |
| 126 | + name: v${{ steps.version.outputs.version }} |
| 127 | + body: ${{ steps.release_notes.outputs.notes }} |
| 128 | + files: growcast-linux-amd64 |
| 129 | + |
| 130 | + # --- dev branch: dev + sha tags, no release --- |
| 131 | + |
| 132 | + - name: Build and push CPU image (dev) |
| 133 | + if: github.ref_name != 'main' |
| 134 | + uses: docker/build-push-action@v6 |
| 135 | + with: |
| 136 | + context: . |
| 137 | + file: Dockerfile |
| 138 | + push: true |
| 139 | + tags: | |
| 140 | + dwot/growcast:dev |
| 141 | + dwot/growcast:dev-${{ steps.version.outputs.short_sha }} |
| 142 | + cache-from: type=gha |
| 143 | + cache-to: type=gha,mode=max |
| 144 | + |
| 145 | + - name: Build and push GPU image (dev) |
| 146 | + if: github.ref_name != 'main' |
| 147 | + uses: docker/build-push-action@v6 |
| 148 | + with: |
| 149 | + context: . |
| 150 | + file: Dockerfile.gpu |
| 151 | + push: true |
| 152 | + tags: | |
| 153 | + dwot/growcast:dev-gpu |
| 154 | + dwot/growcast:dev-${{ steps.version.outputs.short_sha }}-gpu |
| 155 | + cache-from: type=gha |
| 156 | + cache-to: type=gha,mode=max |
0 commit comments