|
7 | 7 | types: [created] |
8 | 8 |
|
9 | 9 | jobs: |
| 10 | + |
| 11 | + determine-version: |
| 12 | + name: Determine version |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - id: determine_version |
| 16 | + run: | |
| 17 | + if [ ${{ github.event_name }} == "release" ]; then |
| 18 | + echo "version=${{ github.ref_name }}" >> "$GITHUB_OUTPUT" |
| 19 | + else |
| 20 | + echo "version=${{ github.sha }}" >> "$GITHUB_OUTPUT" |
| 21 | + fi |
| 22 | + cat "$GITHUB_OUTPUT" |
| 23 | + outputs: |
| 24 | + version: ${{ steps.determine_version.outputs.version }} |
| 25 | + |
10 | 26 | build: |
11 | 27 | name: Build |
12 | 28 | runs-on: ubuntu-latest |
| 29 | + needs: [ determine-version ] |
13 | 30 | steps: |
14 | | - - uses: actions/setup-go@v4 |
| 31 | + - uses: actions/setup-go@v5 |
15 | 32 | with: |
16 | 33 | go-version: '1.24' |
| 34 | + - uses: docker/setup-qemu-action@v3 |
| 35 | + - uses: docker/setup-buildx-action@v3 |
| 36 | + |
17 | 37 | - uses: actions/checkout@v4 |
18 | | - - name: Lint, test and build |
19 | | - run: | |
20 | 38 |
|
21 | | - # Get staticcheck |
22 | | - export PATH=$PATH:$(go env GOPATH)/bin |
| 39 | + - name: Lint |
| 40 | + run: make lint |
23 | 41 |
|
24 | | - # Lint and test |
25 | | - make lint |
26 | | - make format |
| 42 | + - name: Format |
| 43 | + run: make format && git diff --exit-code |
27 | 44 |
|
28 | | - # Exit if after formatting there are any code differences |
29 | | - git diff --exit-code |
| 45 | + - name: Test |
| 46 | + run: make test |
30 | 47 |
|
31 | | - make test |
| 48 | + - name: Build |
| 49 | + run: make package_all VERSION=${{ needs.determine-version.outputs.version }} |
32 | 50 |
|
33 | | - # Build |
34 | | - if [ ${{ github.event_name }} == "release" ]; then |
35 | | - # github.ref is in the form refs/tags/VERSION, so apply regex to just get version |
36 | | - VERSION=$(echo "${{ github.ref }}" | grep -P '([^\/]+$)' -o) |
37 | | - else |
38 | | - VERSION=$(git rev-parse --short ${{ github.sha }}) |
39 | | - fi |
40 | | - make docker VERSION=${VERSION} |
41 | | - - name: Deploy |
42 | | - env: |
43 | | - DOCKER_USER: ${{ secrets.DOCKER_USER }} |
44 | | - DOCKER_PASS: ${{ secrets.DOCKER_PASS }} |
| 51 | + - name: Docker Hub authentication |
45 | 52 | if: github.event_name != 'pull_request' && github.repository == 'jthomperoo/custom-pod-autoscaler' |
46 | | - run: | |
47 | | -
|
48 | | - # Array of images to publish |
49 | | - declare -a IMAGES=(python python-3-12 python-3-13 alpine) |
50 | | - echo "$DOCKER_PASS" | docker login --username=$DOCKER_USER --password-stdin |
51 | | -
|
52 | | - if [ ${{ github.event_name }} == "release" ]; then |
| 53 | + uses: docker/login-action@v3 |
| 54 | + with: |
| 55 | + username: ${{ secrets.DOCKER_USER }} |
| 56 | + password: ${{ secrets.DOCKER_PASS }} |
53 | 57 |
|
54 | | - # This needs to be determined again, due to env vars not being shared between steps |
55 | | - # https://github.com/actions/starter-workflows/issues/68 |
56 | | - VERSION=$(echo "${{ github.ref }}" | grep -P '([^\/]+$)' -o) |
| 58 | + - name: Build Docker images |
| 59 | + if: github.event_name != 'pull_request' && github.repository == 'jthomperoo/custom-pod-autoscaler' |
| 60 | + run: make docker_multi_platform VERSION=${{ needs.determine-version.outputs.version }} |
57 | 61 |
|
58 | | - # Go through each image type and publish each one individually |
59 | | - for image in "${IMAGES[@]}"; do |
60 | | - docker tag custompodautoscaler/${image}:${VERSION} custompodautoscaler/${image}:latest |
61 | | - docker push custompodautoscaler/${image}:${VERSION} |
62 | | - docker push custompodautoscaler/${image}:latest |
63 | | - done |
| 62 | + - name: Tag latest Docker images |
| 63 | + if: github.event_name == 'release' |
| 64 | + run: make docker_tag_latest |
64 | 65 |
|
65 | | - # Package binary |
66 | | - tar -czvf custom-pod-autoscaler.tar.gz dist/* |
67 | | - else |
68 | | - for image in "${IMAGES[@]}"; do |
69 | | - docker push custompodautoscaler/${image}:$(git rev-parse --short ${{ github.sha }}) |
70 | | - done |
71 | | - fi |
72 | | - - name: Deploy binary |
73 | | - if: github.event_name == 'release' && github.repository == 'jthomperoo/custom-pod-autoscaler' |
74 | | - |
| 66 | + - name: Publish binaries |
| 67 | + if: github.event_name == 'release' |
| 68 | + uses: softprops/action-gh-release@v2 |
75 | 69 | with: |
76 | | - name: custom-pod-autoscaler.tar.gz |
77 | | - path: custom-pod-autoscaler.tar.gz |
78 | | - repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 70 | + files: | |
| 71 | + custom-pod-autoscaler.tar.gz |
| 72 | + custom-pod-autoscaler-linux-386.tar.gz |
| 73 | + custom-pod-autoscaler-linux-amd64.tar.gz |
| 74 | + custom-pod-autoscaler-linux-arm.tar.gz |
| 75 | + custom-pod-autoscaler-linux-arm64.tar.gz |
| 76 | + custom-pod-autoscaler-darwin-amd64.tar.gz |
| 77 | + custom-pod-autoscaler-darwin-arm64.tar.gz |
| 78 | + custom-pod-autoscaler-windows-386.tar.gz |
| 79 | + custom-pod-autoscaler-windows-amd64.tar.gz |
0 commit comments