github.com/goreleaser/goreleaser@v1.25.1/www/docs/ci/cloudbuild.md (about) 1 # Google CloudBuild 2 3 CloudBuild works off a different clone than your GitHub repo: it seems that 4 your changes are pulled to a repo like 5 `source.developers.google.com/p/YourProjectId/r/github-YourGithubUser-YourGithubRepo`, 6 and that's what you're building off. 7 8 This repo has the wrong name, so to prevent GoReleaser from publishing to 9 the wrong GitHub repo, add to your `.goreleaser.yaml` file's release section: 10 11 ```yaml 12 release: 13 github: 14 owner: YourGithubUser 15 name: YourGithubRepo 16 ``` 17 18 Create two build triggers: 19 20 - a "push to any branch" trigger for your regular CI (doesn't invoke GoReleaser) 21 - a "push to tag" trigger which invokes GoReleaser 22 23 The push to any branch trigger could use a `Dockerfile` or a `cloudbuild.yaml`, 24 whichever you prefer. 25 26 You should have a dedicated `cloudbuild.release.yaml` that is only used by the 27 "push to tag" trigger. 28 29 In this example we're creating a new release every time a new tag is pushed. 30 See [Using Encrypted Resources](https://cloud.google.com/cloud-build/docs/securing-builds/use-encrypted-secrets-credentials) 31 for how to encrypt and base64-encode your github token. 32 33 The clone that the build uses 34 [has no tags](https://issuetracker.google.com/u/1/issues/113668706), 35 which is why we must explicitly run `git tag $TAG_NAME` (note that `$TAG_NAME` 36 is only set when your build is triggered by a "push to tag".) 37 This will allow GoReleaser to create a release with that version, 38 but it won't be able to build a proper 39 changelog containing just the messages from the commits since the prior tag. 40 Note that the build performs a shallow clone of git repositories and will 41 only contain tags that reference the latest commit. 42 43 ```yaml 44 steps: 45 # Setup the workspace so we have a viable place to point GOPATH at. 46 - name: gcr.io/cloud-builders/go 47 env: ['PROJECT_ROOT=github.com/YourGithubUser/YourGithubRepo'] 48 args: ['env'] 49 50 # Create github release. 51 - name: goreleaser/goreleaser 52 entrypoint: /bin/sh 53 dir: gopath/src/github.com 54 env: ['GOPATH=/workspace/gopath'] 55 args: ['-c', 'cd YourGithubUser/YourGithubRepo && git tag $TAG_NAME && /goreleaser' ] 56 secretEnv: ['GITHUB_TOKEN'] 57 58 secrets: 59 - kmsKeyName: projects/YourProjectId/locations/global/keyRings/YourKeyRing/cryptoKeys/YourKey 60 secretEnv: 61 GITHUB_TOKEN: | 62 ICAgICAgICBDaVFBZUhVdUVoRUtBdmZJSGxVWnJDZ0hOU2NtMG1ES0k4WjF3L04zT3pEazhRbDZr 63 QVVTVVFEM3dVYXU3cVJjK0g3T25UVW82YjJaCiAgICAgICAgREtBMWVNS0hOZzcyOUtmSGoyWk1x 64 ICAgICAgIEgwYndIaGUxR1E9PQo= 65 66 ``` 67