|
1 |
| -name: Auto-Tag, Release & Docker Push |
| 1 | +name: Build, Test, and Release |
2 | 2 |
|
3 | 3 | on:
|
4 | 4 | push:
|
5 | 5 | branches: [ "main" ]
|
| 6 | + pull_request: |
| 7 | + branches: [ "main" ] |
6 | 8 |
|
7 | 9 | jobs:
|
8 | 10 | release:
|
9 | 11 | runs-on: ubuntu-latest
|
10 |
| - |
11 | 12 | steps:
|
12 |
| - |
| 13 | + # Check out the repository. |
13 | 14 | - name: Check out repository
|
14 | 15 | uses: actions/checkout@v4
|
15 | 16 |
|
| 17 | + # Set up Go. |
16 | 18 | - name: Set up Go
|
17 | 19 | uses: actions/setup-go@v5
|
18 | 20 | with:
|
19 | 21 | go-version: '1.24'
|
20 | 22 |
|
| 23 | + # Cache Go modules. |
| 24 | + - name: Cache Go modules |
| 25 | + uses: actions/cache@v4 |
| 26 | + with: |
| 27 | + path: ~/go/pkg/mod |
| 28 | + key: ${{ runner.os }}-go-${{ hashFiles('go.sum') }} |
| 29 | + restore-keys: | |
| 30 | + ${{ runner.os }}-go- |
| 31 | +
|
| 32 | + # # Run tests. |
| 33 | + # - name: Run Tests |
| 34 | + # run: go test -v ./... |
| 35 | + |
| 36 | + # Bump version and create tag. |
21 | 37 | - name: Bump Version and Create Tag
|
22 | 38 | id: bump_version
|
23 | 39 | uses: anothrnick/[email protected]
|
24 | 40 | env:
|
25 | 41 | GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
|
26 |
| - DEFAULT_BRANCH: "main" |
| 42 | + DEFAULT_BRANCH: "main" |
27 | 43 | RELEASE_BRANCHES: "main"
|
28 |
| - WITH_V: true |
| 44 | + WITH_V: true |
| 45 | + |
| 46 | + # Build the kpeek binary with the version injected. |
| 47 | + - name: Build kpeek with version |
| 48 | + run: | |
| 49 | + echo "Building kpeek with version: ${{ steps.bump_version.outputs.new_tag }}" |
| 50 | + go build -ldflags "-X github.com/hacktivist123/kpeek/cmd.version=${{ steps.bump_version.outputs.new_tag }}" -o kpeek . |
29 | 51 |
|
| 52 | + # Set up QEMU for multi-arch builds. |
30 | 53 | - name: Set up QEMU
|
31 | 54 | uses: docker/setup-qemu-action@v2
|
32 | 55 |
|
| 56 | + # Set up Docker Buildx. |
33 | 57 | - name: Set up Docker Buildx
|
34 | 58 | uses: docker/setup-buildx-action@v3
|
35 | 59 |
|
| 60 | + # Log in to Docker Hub. |
36 | 61 | - name: Log in to Docker Hub
|
37 | 62 | uses: docker/login-action@v3
|
38 | 63 | with:
|
39 | 64 | username: ${{ secrets.DOCKERHUB_USERNAME }}
|
40 | 65 | password: ${{ secrets.DOCKERHUB_PASSWORD }}
|
41 | 66 |
|
42 |
| - - name: Build kpeek with version |
43 |
| - run: | |
44 |
| - echo "Building kpeek with version: ${{ steps.bump_version.outputs.new_tag }}" |
45 |
| - go build -ldflags "-X github.com/hacktivist123/kpeek/cmd.version=${{ steps.bump_version.outputs.new_tag }}" -o kpeek . |
46 |
| -
|
| 67 | + # Build and push the Docker image using the locally built binary. |
47 | 68 | - name: Build and push Docker image
|
48 | 69 | uses: docker/build-push-action@v5
|
49 | 70 | with:
|
|
57 | 78 | secrets: |
|
58 | 79 | GIT_AUTH_TOKEN=${{ secrets.ACCESS_TOKEN }}
|
59 | 80 |
|
| 81 | + # Create GitHub Release. |
60 | 82 | - name: Create GitHub Release
|
61 | 83 | if: ${{ success() }}
|
62 | 84 | id: create_release
|
|
0 commit comments