github.com/spinnaker/spin@v1.30.0/.github/workflows/build.yml (about) 1 name: Branch Build 2 3 on: 4 push: 5 branches: 6 - master 7 - release-* 8 9 env: 10 CONTAINER_REGISTRY: us-docker.pkg.dev/spinnaker-community/docker 11 12 jobs: 13 lint: 14 # Only run this on repositories in the 'spinnaker' org, not on forks. 15 if: startsWith(github.repository, 'spinnaker/') 16 runs-on: ubuntu-latest 17 steps: 18 - name: Checkout code 19 uses: actions/checkout@v3 20 - uses: actions/setup-go@v4 21 with: 22 go-version-file: go.mod 23 cache: false 24 - name: Ensure code formatting and style is consistent 25 uses: golangci/golangci-lint-action@v3 26 with: 27 version: v1.45.2 28 29 branch-build: 30 # Only run this on repositories in the 'spinnaker' org, not on forks. 31 if: startsWith(github.repository, 'spinnaker/') 32 runs-on: ubuntu-latest 33 steps: 34 - uses: actions/checkout@v3 35 - name: Prepare build variables 36 id: build_variables 37 run: | 38 echo REPO="${GITHUB_REPOSITORY##*/}" >> $GITHUB_OUTPUT 39 echo VERSION="${GITHUB_REF_NAME}-$(git rev-parse --short HEAD)-$(date --utc +'%Y%m%d%H%M')" >> $GITHUB_OUTPUT 40 echo VERSION_WITHOUT_BRANCH="$(git rev-parse --short HEAD)-$(date --utc +'%Y%m%d%H%M')" >> $GITHUB_OUTPUT 41 42 - uses: actions/setup-go@v4 43 with: 44 go-version-file: go.mod 45 cache: false 46 - uses: actions/cache@v3 47 with: 48 path: ~/go/pkg/mod 49 key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} 50 restore-keys: | 51 ${{ runner.os }}-go- 52 - name: Fetch dependencies 53 run: go get -d -v 54 - name: Test 55 run: go test -v ./... 56 - name: Build binaries 57 env: 58 LDFLAGS: "-X github.com/spinnaker/spin/version.Version=${{ steps.build_variables.outputs.VERSION }}" 59 run: | 60 GOARCH=amd64 GOOS=darwin go build -ldflags "${LDFLAGS}" -o dist/${{ github.ref_name }}/${{ steps.build_variables.outputs.VERSION_WITHOUT_BRANCH }}/darwin/amd64/spin . 61 GOARCH=amd64 GOOS=linux go build -ldflags "${LDFLAGS}" -o dist/${{ github.ref_name }}/${{ steps.build_variables.outputs.VERSION_WITHOUT_BRANCH }}/linux/amd64/spin . 62 GOARCH=arm64 GOOS=linux go build -ldflags "${LDFLAGS}" -o dist/${{ github.ref_name }}/${{ steps.build_variables.outputs.VERSION_WITHOUT_BRANCH }}/linux/arm64/spin . 63 GOARCH=amd64 GOOS=windows go build -ldflags "${LDFLAGS}" -o dist/${{ github.ref_name }}/${{ steps.build_variables.outputs.VERSION_WITHOUT_BRANCH }}/windows/amd64/spin.exe . 64 GOARCH=arm64 GOOS=darwin go build -ldflags "${LDFLAGS}" -o dist/${{ github.ref_name }}/${{ steps.build_variables.outputs.VERSION_WITHOUT_BRANCH }}/darwin/arm64/spin . 65 dist/${{ github.ref_name }}/${{ steps.build_variables.outputs.VERSION_WITHOUT_BRANCH }}/linux/amd64/spin --version 66 - name: Login to Google Cloud 67 uses: 'google-github-actions/auth@v1' 68 # use service account flow defined at: https://github.com/google-github-actions/upload-cloud-storage#authenticating-via-service-account-key-json 69 with: 70 credentials_json: '${{ secrets.GAR_JSON_KEY }}' 71 - name: Upload spin CLI binaries to GCS 72 uses: 'google-github-actions/upload-cloud-storage@v1' 73 with: 74 path: 'dist/' 75 destination: 'spinnaker-artifacts/spin' 76 parent: false 77 78 - name: Login to GAR 79 # Only run this on repositories in the 'spinnaker' org, not on forks. 80 if: startsWith(github.repository, 'spinnaker/') 81 uses: docker/login-action@v2 82 # use service account flow defined at: https://github.com/docker/login-action#service-account-based-authentication-1 83 with: 84 registry: us-docker.pkg.dev 85 username: _json_key 86 password: ${{ secrets.GAR_JSON_KEY }} 87 - name: Build and publish container image 88 # Only run this on repositories in the 'spinnaker' org, not on forks. 89 if: startsWith(github.repository, 'spinnaker/') 90 uses: docker/build-push-action@v4 91 with: 92 context: . 93 file: Dockerfile 94 push: true 95 build-args: | 96 "VERSION=${{ steps.build_variables.outputs.VERSION }}" 97 tags: | 98 "${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:latest" 99 "${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ github.ref_name }}-latest" 100 "${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ steps.build_variables.outputs.VERSION }}"