From 70b72f26b74f3d999efbdbbd937c422adba27701 Mon Sep 17 00:00:00 2001 From: Trevor Whitney Date: Mon, 22 Jan 2024 14:59:43 -0700 Subject: [PATCH] feat: release the correct sha (#47) --- .github/workflows/release-pr.yml | 66 ++-- .github/workflows/release.yml | 9 +- .release-please-manifest.json | 2 +- CHANGELOG.md | 105 +++++ .../should-release/__tests__/release.test.ts | 80 +++- actions/should-release/dist/index.js | 33 +- actions/should-release/src/main.ts | 1 + actions/should-release/src/release.ts | 45 ++- cmd/main.go | 16 + go.mod | 7 + go.sum | 2 + release-please-config.json | 6 +- .../github.com/hashicorp/go-uuid/.travis.yml | 12 + vendor/github.com/hashicorp/go-uuid/LICENSE | 365 ++++++++++++++++++ vendor/github.com/hashicorp/go-uuid/README.md | 8 + vendor/github.com/hashicorp/go-uuid/uuid.go | 83 ++++ vendor/modules.txt | 3 + workflows/lib/build.libsonnet | 17 +- workflows/lib/common.libsonnet | 4 +- workflows/lib/release.libsonnet | 28 +- 20 files changed, 798 insertions(+), 94 deletions(-) create mode 100644 cmd/main.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 vendor/github.com/hashicorp/go-uuid/.travis.yml create mode 100644 vendor/github.com/hashicorp/go-uuid/LICENSE create mode 100644 vendor/github.com/hashicorp/go-uuid/README.md create mode 100644 vendor/github.com/hashicorp/go-uuid/uuid.go create mode 100644 vendor/modules.txt diff --git a/.github/workflows/release-pr.yml b/.github/workflows/release-pr.yml index 3b768996..7fa34d7a 100644 --- a/.github/workflows/release-pr.yml +++ b/.github/workflows/release-pr.yml @@ -18,8 +18,8 @@ jobs: - name: "setup go" uses: "actions/setup-go@v4" with: - cache-dependency-path: "loki/go.sum" - go-version-file: "loki/go.mod" + cache-dependency-path: "release/go.sum" + go-version-file: "release/go.mod" - name: "setup node" uses: "actions/setup-node@v4" with: @@ -134,14 +134,18 @@ jobs: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT shell: "bash" working-directory: "release" - - id: "release" + - env: + SHA: "${{ github.sha }}" + id: "release" name: "release please" run: | npm install npm exec -- release-please release-pr \ - --token="${{ secrets.GH_TOKEN }}" \ + --pull-request-footer "Merging this PR will release the [artifacts](https://console.cloud.google.com/storage/browser/loki-build-artifacts/${SHA}) of ${SHA}" \ + --release-type simple \ --repo-url="${{ inputs.release_repo }}" \ - --target-branch "${{ steps.extract_branch.outputs.branch }}" + --target-branch "${{ steps.extract_branch.outputs.branch }}" \ + --token="${{ secrets.GH_TOKEN }}" shell: "bash" working-directory: "lib" dist: @@ -159,8 +163,8 @@ jobs: - name: "setup go" uses: "actions/setup-go@v4" with: - cache-dependency-path: "loki/go.sum" - go-version-file: "loki/go.mod" + cache-dependency-path: "release/go.sum" + go-version-file: "release/go.mod" - env: ACTIONS_STEP_DEBUG: "true" name: "auth gcs" @@ -184,16 +188,12 @@ jobs: run: "make BUILD_IN_CONTAINER=false SKIP_ARM=true dist" shell: "bash" working-directory: "release" - - name: "pacakge artifacts" - run: | - tar -czf dist.tar.gz dist - shell: "bash" - working-directory: "release" - name: "upload build artifacts" uses: "google-github-actions/upload-cloud-storage@v1" with: - destination: "loki-build-artifacts/${{ github.sha }}/dist.tar.gz" - path: "release/dist.tar.gz" + destination: "loki-build-artifacts/${{ github.sha }}" + path: "release/dist" + process_gcloudignore: false lint: if: "${{ !fromJSON(inputs.skip_validation) }}" runs-on: "ubuntu-latest" @@ -211,8 +211,8 @@ jobs: - name: "setup go" uses: "actions/setup-go@v4" with: - cache-dependency-path: "loki/go.sum" - go-version-file: "loki/go.mod" + cache-dependency-path: "release/go.sum" + go-version-file: "release/go.mod" - name: "setup node" uses: "actions/setup-node@v4" with: @@ -285,7 +285,6 @@ jobs: shell: "bash" working-directory: "release" loki-image: - if: "${{ inputs.release_repo }} == grafana/loki" needs: - "test" - "lint" @@ -300,8 +299,8 @@ jobs: - name: "setup go" uses: "actions/setup-go@v4" with: - cache-dependency-path: "loki/go.sum" - go-version-file: "loki/go.mod" + cache-dependency-path: "release/go.sum" + go-version-file: "release/go.mod" - name: "Set up QEMU" uses: "docker/setup-qemu-action@v3" - name: "set up docker buildx" @@ -318,19 +317,21 @@ jobs: echo "version=${version}" >> $GITHUB_OUTPUT shell: "bash" working-directory: "release" - - name: "Build and export" + - if: "${{ inputs.release_repo == 'grafana/loki' }}" + name: "Build and export" uses: "docker/build-push-action@v5" with: context: "release" file: "release/cmd/loki/Dockerfile" - outputs: "type=docker,dest=release/dist/loki-${{ steps.parse-metadata.outputs.version}}-${{ steps.parse-metadata.outputs.platform }}.tar" + outputs: "type=docker,dest=release/images/loki-${{ steps.parse-metadata.outputs.version}}-${{ steps.parse-metadata.outputs.platform }}.tar" platforms: "${{ matrix.platform }}" tags: "grafana/loki:${{ steps.parse-metadata.outputs.version }}" - - name: "upload artifacts" + - if: "${{ inputs.release_repo == 'grafana/loki' }}" + name: "upload artifacts" uses: "actions/upload-artifact@v3" with: name: "loki-image-${{ steps.parse-metadata.outputs.version}}-${{ steps.parse-metadata.outputs.platform }}" - path: "release/dist/loki-${{ steps.parse-metadata.outputs.version}}-${{ steps.parse-metadata.outputs.platform }}.tar" + path: "release/images/loki-${{ steps.parse-metadata.outputs.version}}-${{ steps.parse-metadata.outputs.platform }}.tar" strategy: fail-fast: true matrix: @@ -339,7 +340,6 @@ jobs: - "linux/arm64" - "linux/arm" promtail-image: - if: "${{ inputs.release_repo }} == grafana/loki" needs: - "test" - "lint" @@ -354,8 +354,8 @@ jobs: - name: "setup go" uses: "actions/setup-go@v4" with: - cache-dependency-path: "loki/go.sum" - go-version-file: "loki/go.mod" + cache-dependency-path: "release/go.sum" + go-version-file: "release/go.mod" - name: "Set up QEMU" uses: "docker/setup-qemu-action@v3" - name: "set up docker buildx" @@ -372,19 +372,21 @@ jobs: echo "version=${version}" >> $GITHUB_OUTPUT shell: "bash" working-directory: "release" - - name: "Build and export" + - if: "${{ inputs.release_repo == 'grafana/loki' }}" + name: "Build and export" uses: "docker/build-push-action@v5" with: context: "release" file: "release/clients/cmd/promtail/Dockerfile" - outputs: "type=docker,dest=release/dist/promtail-${{ steps.parse-metadata.outputs.version}}-${{ steps.parse-metadata.outputs.platform }}.tar" + outputs: "type=docker,dest=release/images/promtail-${{ steps.parse-metadata.outputs.version}}-${{ steps.parse-metadata.outputs.platform }}.tar" platforms: "${{ matrix.platform }}" tags: "grafana/promtail:${{ steps.parse-metadata.outputs.version }}" - - name: "upload artifacts" + - if: "${{ inputs.release_repo == 'grafana/loki' }}" + name: "upload artifacts" uses: "actions/upload-artifact@v3" with: name: "promtail-image-${{ steps.parse-metadata.outputs.version}}-${{ steps.parse-metadata.outputs.platform }}" - path: "release/dist/promtail-${{ steps.parse-metadata.outputs.version}}-${{ steps.parse-metadata.outputs.platform }}.tar" + path: "release/images/promtail-${{ steps.parse-metadata.outputs.version}}-${{ steps.parse-metadata.outputs.platform }}.tar" strategy: fail-fast: true matrix: @@ -409,8 +411,8 @@ jobs: - name: "setup go" uses: "actions/setup-go@v4" with: - cache-dependency-path: "loki/go.sum" - go-version-file: "loki/go.mod" + cache-dependency-path: "release/go.sum" + go-version-file: "release/go.mod" - name: "setup node" uses: "actions/setup-node@v4" with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f9043b74..d125d4f2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -42,20 +42,21 @@ jobs: - if: "${{ fromJSON(steps.should_release.outputs.shouldRelease) }}" name: "download build artifacts" run: | - gsutil cp -r gs://loki-build-artifacts/${{ steps.prepare.outputs.sha }}/dist . + gsutil cp -r gs://loki-build-artifacts/${{ steps.should_release.outputs.sha }}/dist . ls dist shell: "bash" working-directory: "release" - id: "release" - if: "${{ fromJSON(steps.prepare.should_release.shouldRelease) }}" + if: "${{ fromJSON(steps.should_release.outputs.shouldRelease) }}" name: "release please" run: | npm install npm exec -- release-please github-release \ - --token="${{ secrets.GH_TOKEN }}" \ + --draft \ + --release-type simple \ --repo-url="${{ inputs.release_repo }}" \ --target-branch "${{ steps.extract_branch.outputs.branch }}" \ - --draft + --token="${{ secrets.GH_TOKEN }}" shell: "bash" working-directory: "release" - env: diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 1adaf630..0d1bebe1 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "1.5.3" + ".": "1.6.0" } diff --git a/CHANGELOG.md b/CHANGELOG.md index 329f9fd0..57d4e1fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,110 @@ # Changelog +## [1.6.0](https://github.com/grafana/loki-release/compare/v1.6.0...v1.6.0) (2024-01-19) + + +### Features + +* add a go.mod and go file ([3713672](https://github.com/grafana/loki-release/commit/3713672ba00937015fb97fcc1efb26acfe5e5a7b)) +* add artifacts to release ([4fea492](https://github.com/grafana/loki-release/commit/4fea4927fe360ce4031fa0553f6536d8fd980d17)) +* add backport action ([4df43c6](https://github.com/grafana/loki-release/commit/4df43c665e46daa36fca0b9be0932b2393ebb5c7)) +* add correct updaters to release pull request ([d50db7a](https://github.com/grafana/loki-release/commit/d50db7a6ce579a8b21c0f84b3767eb6f9c24f9dc)) +* add create release step ([fe8c2fb](https://github.com/grafana/loki-release/commit/fe8c2fbe3d6bd7617226b6e7e9f5abdd77aec483)) +* add install binary action ([947ed95](https://github.com/grafana/loki-release/commit/947ed95bf340634e24bfc316eda4f20d356190de)) +* add more cli flags to get the others to work? ([8e8a635](https://github.com/grafana/loki-release/commit/8e8a6354757fad3cc91b20ce575ec20e4dc28685)) +* add more functionality from release please ([6c871fc](https://github.com/grafana/loki-release/commit/6c871fc3368e4eece45c7fa807e1831164f4debe)) +* add release steps to jsonnet-build workflow ([55a14d6](https://github.com/grafana/loki-release/commit/55a14d67b6cdbda880abe16ed3cd1db969714b1c)) +* added github interactions to release plugin ([808c34a](https://github.com/grafana/loki-release/commit/808c34aa4bc81a523683b2b345eccff75e628e2f)) +* bring back all steps ([ab86186](https://github.com/grafana/loki-release/commit/ab86186caf0e7218e9be1fd7a84df58545c08517)) +* build images for multiple platforms ([49a846e](https://github.com/grafana/loki-release/commit/49a846e2da75e56cd22fd4bbadb2469919afed2e)) +* build pipeline using jsonnet for re-use ([b6cc287](https://github.com/grafana/loki-release/commit/b6cc2876ac3a593ede5644ca2e5a3bbec5572837)) +* **ci:** add prepare workflow ([b100d6f](https://github.com/grafana/loki-release/commit/b100d6fe25669928cb023e4b869af0cfe353b7b1)) +* **ci:** add release-please action ([b994e1b](https://github.com/grafana/loki-release/commit/b994e1bb5a36e7f6e1f0134a1ea104143d0bce3f)) +* **ci:** bump minor for k branches ([44d573d](https://github.com/grafana/loki-release/commit/44d573d107dd71ae26e2884a8d5e75c2e7a6d76f)) +* **ci:** fix default-branch ([fe48dc3](https://github.com/grafana/loki-release/commit/fe48dc34c4e9cbfc42d5afff5ad79c0b1daf464a)) +* **ci:** try to move versioning into workflow definition ([d66d51a](https://github.com/grafana/loki-release/commit/d66d51a562d6384e2966acd1cbf3755b99ff93a4)) +* create release branch from k release ([07f2b06](https://github.com/grafana/loki-release/commit/07f2b064a9a0234a0cfe87cf390bb6f055dff967)) +* create release first ([e2d4e73](https://github.com/grafana/loki-release/commit/e2d4e7318ec2f581296b5341363698c222352536)) +* exclude component from tag for better release notes ([9841d98](https://github.com/grafana/loki-release/commit/9841d98bbfefd2a1d972c4bb81f5a4d6bcffc5e7)) +* first try at storing build artifacts in GCS ([8801d68](https://github.com/grafana/loki-release/commit/8801d686e7b4084bb8e82f5776c8a7148fa219a5)) +* fix typo in versioing-strategy ([5a47a62](https://github.com/grafana/loki-release/commit/5a47a62cdea90bbf21cefd8085eaf8b47650bd51)) +* fix versioning strategy ([0008487](https://github.com/grafana/loki-release/commit/0008487cad2fe5e54fdacde3ff0b2724c21db979)) +* make footer more informative ([d922830](https://github.com/grafana/loki-release/commit/d922830c6c7bd5293e09140e8245efa29f5dc7cb)) +* make it a dry run ([4d63549](https://github.com/grafana/loki-release/commit/4d63549df4170dc67b4fe6a31175693504bab47a)) +* make workflow re-usable ([c01b721](https://github.com/grafana/loki-release/commit/c01b7213100dca261ddf9cad255cf4428bebd8a7)) +* nest workflows in folder ([2eab631](https://github.com/grafana/loki-release/commit/2eab6317c6381b2827dac7409bfd8dfcaf96f4eb)) +* output created/updated PR ([3d76523](https://github.com/grafana/loki-release/commit/3d76523376309db2e95d8f05716aa0c3d1b228e7)) +* put images in different subfolder in bucket ([b4c9364](https://github.com/grafana/loki-release/commit/b4c9364a822bda9f6a85537deddf8056b75788f3)) +* remove unused code ([0ad335c](https://github.com/grafana/loki-release/commit/0ad335cf7b13c6cb374d85ec05d127300c01edba)) +* run create release on release branches ([c8ba75f](https://github.com/grafana/loki-release/commit/c8ba75ffe27b6288de7b048b716173a131352ddc)) +* skip steps not jobs ([de6deb3](https://github.com/grafana/loki-release/commit/de6deb38dc877630ad77c70b0176e679509f9308)) +* store sha in footer ([983a9d6](https://github.com/grafana/loki-release/commit/983a9d6dfa14bc53e0f306d46aa390f36a676f7c)) +* try a merge to main w/ backport strategy ([cf996f4](https://github.com/grafana/loki-release/commit/cf996f4cb2366df03c668af2b572f845c904e7ac)) +* try using release-please for release again ([3ca6579](https://github.com/grafana/loki-release/commit/3ca6579cb00cde5843021c5ccd99c83139db54ed)) + + +### Bug Fixes + +* add actual dependency to fake go program ([f9bed84](https://github.com/grafana/loki-release/commit/f9bed846d0377edcc5347a58ea564e3cdbe7619f)) +* fix step reference ([2fdb566](https://github.com/grafana/loki-release/commit/2fdb56609031e06c252ba026b072f84546b1abe0)) +* go.mod file reference ([1bde062](https://github.com/grafana/loki-release/commit/1bde0628c59950dc3169984c7492728b5a0a85a0)) +* image conditional ([966a394](https://github.com/grafana/loki-release/commit/966a394de4b4a67b41e36010840a9b465753d526)) + + +### Miscellaneous Chores + +* release 1.6.0 ([623481c](https://github.com/grafana/loki-release/commit/623481cf6788df9495affd69b292973fcbc16e6e)) + +## [1.6.0](https://github.com/grafana/loki-release/compare/v1.6.0...v1.6.0) (2024-01-19) + + +### Features + +* add a go.mod and go file ([3713672](https://github.com/grafana/loki-release/commit/3713672ba00937015fb97fcc1efb26acfe5e5a7b)) +* add artifacts to release ([4fea492](https://github.com/grafana/loki-release/commit/4fea4927fe360ce4031fa0553f6536d8fd980d17)) +* add backport action ([4df43c6](https://github.com/grafana/loki-release/commit/4df43c665e46daa36fca0b9be0932b2393ebb5c7)) +* add correct updaters to release pull request ([d50db7a](https://github.com/grafana/loki-release/commit/d50db7a6ce579a8b21c0f84b3767eb6f9c24f9dc)) +* add create release step ([fe8c2fb](https://github.com/grafana/loki-release/commit/fe8c2fbe3d6bd7617226b6e7e9f5abdd77aec483)) +* add install binary action ([947ed95](https://github.com/grafana/loki-release/commit/947ed95bf340634e24bfc316eda4f20d356190de)) +* add more functionality from release please ([6c871fc](https://github.com/grafana/loki-release/commit/6c871fc3368e4eece45c7fa807e1831164f4debe)) +* add release steps to jsonnet-build workflow ([55a14d6](https://github.com/grafana/loki-release/commit/55a14d67b6cdbda880abe16ed3cd1db969714b1c)) +* added github interactions to release plugin ([808c34a](https://github.com/grafana/loki-release/commit/808c34aa4bc81a523683b2b345eccff75e628e2f)) +* bring back all steps ([ab86186](https://github.com/grafana/loki-release/commit/ab86186caf0e7218e9be1fd7a84df58545c08517)) +* build images for multiple platforms ([49a846e](https://github.com/grafana/loki-release/commit/49a846e2da75e56cd22fd4bbadb2469919afed2e)) +* build pipeline using jsonnet for re-use ([b6cc287](https://github.com/grafana/loki-release/commit/b6cc2876ac3a593ede5644ca2e5a3bbec5572837)) +* **ci:** add release-please action ([b994e1b](https://github.com/grafana/loki-release/commit/b994e1bb5a36e7f6e1f0134a1ea104143d0bce3f)) +* **ci:** bump minor for k branches ([44d573d](https://github.com/grafana/loki-release/commit/44d573d107dd71ae26e2884a8d5e75c2e7a6d76f)) +* **ci:** fix default-branch ([fe48dc3](https://github.com/grafana/loki-release/commit/fe48dc34c4e9cbfc42d5afff5ad79c0b1daf464a)) +* **ci:** try to move versioning into workflow definition ([d66d51a](https://github.com/grafana/loki-release/commit/d66d51a562d6384e2966acd1cbf3755b99ff93a4)) +* create release branch from k release ([07f2b06](https://github.com/grafana/loki-release/commit/07f2b064a9a0234a0cfe87cf390bb6f055dff967)) +* create release first ([e2d4e73](https://github.com/grafana/loki-release/commit/e2d4e7318ec2f581296b5341363698c222352536)) +* exclude component from tag for better release notes ([9841d98](https://github.com/grafana/loki-release/commit/9841d98bbfefd2a1d972c4bb81f5a4d6bcffc5e7)) +* first try at storing build artifacts in GCS ([8801d68](https://github.com/grafana/loki-release/commit/8801d686e7b4084bb8e82f5776c8a7148fa219a5)) +* fix typo in versioing-strategy ([5a47a62](https://github.com/grafana/loki-release/commit/5a47a62cdea90bbf21cefd8085eaf8b47650bd51)) +* fix versioning strategy ([0008487](https://github.com/grafana/loki-release/commit/0008487cad2fe5e54fdacde3ff0b2724c21db979)) +* make it a dry run ([4d63549](https://github.com/grafana/loki-release/commit/4d63549df4170dc67b4fe6a31175693504bab47a)) +* make workflow re-usable ([c01b721](https://github.com/grafana/loki-release/commit/c01b7213100dca261ddf9cad255cf4428bebd8a7)) +* nest workflows in folder ([2eab631](https://github.com/grafana/loki-release/commit/2eab6317c6381b2827dac7409bfd8dfcaf96f4eb)) +* output created/updated PR ([3d76523](https://github.com/grafana/loki-release/commit/3d76523376309db2e95d8f05716aa0c3d1b228e7)) +* put images in different subfolder in bucket ([b4c9364](https://github.com/grafana/loki-release/commit/b4c9364a822bda9f6a85537deddf8056b75788f3)) +* remove unused code ([0ad335c](https://github.com/grafana/loki-release/commit/0ad335cf7b13c6cb374d85ec05d127300c01edba)) +* run create release on release branches ([c8ba75f](https://github.com/grafana/loki-release/commit/c8ba75ffe27b6288de7b048b716173a131352ddc)) +* skip steps not jobs ([de6deb3](https://github.com/grafana/loki-release/commit/de6deb38dc877630ad77c70b0176e679509f9308)) +* try a merge to main w/ backport strategy ([cf996f4](https://github.com/grafana/loki-release/commit/cf996f4cb2366df03c668af2b572f845c904e7ac)) +* try using release-please for release again ([3ca6579](https://github.com/grafana/loki-release/commit/3ca6579cb00cde5843021c5ccd99c83139db54ed)) + + +### Bug Fixes + +* add actual dependency to fake go program ([f9bed84](https://github.com/grafana/loki-release/commit/f9bed846d0377edcc5347a58ea564e3cdbe7619f)) +* go.mod file reference ([1bde062](https://github.com/grafana/loki-release/commit/1bde0628c59950dc3169984c7492728b5a0a85a0)) +* image conditional ([966a394](https://github.com/grafana/loki-release/commit/966a394de4b4a67b41e36010840a9b465753d526)) + + +### Miscellaneous Chores + +* release 1.6.0 ([623481c](https://github.com/grafana/loki-release/commit/623481cf6788df9495affd69b292973fcbc16e6e)) + ## [1.5.3](https://github.com/grafana/loki-release/compare/v1.5.2...v1.5.3) (2024-01-19) diff --git a/actions/should-release/__tests__/release.test.ts b/actions/should-release/__tests__/release.test.ts index 09ff1ed0..fcec25db 100644 --- a/actions/should-release/__tests__/release.test.ts +++ b/actions/should-release/__tests__/release.test.ts @@ -16,11 +16,13 @@ const sandbox = createSandbox() let findMergedReleasePullRequests: SinonStub let fakeGitHub: GitHub let defaultPRNotes: string -let defaultPRBody: PullRequestBody let defaultPRTitle: string const defaultNextVersion = Version.parse('1.3.2') +const footer = + 'Merging this PR will release the [artifacts](https://loki-build-artifacts.storage.googleapis.com/def456) of def456' + const commits = parseConventionalCommits([ // This feature will be release in 1.3.2 { @@ -80,13 +82,6 @@ describe('release', () => { commits }) - defaultPRBody = new PullRequestBody([ - { - version: defaultNextVersion, - notes: defaultPRNotes - } - ]) - defaultPRTitle = PullRequestTitle.ofVersion(defaultNextVersion).toString() }) @@ -103,7 +98,17 @@ describe('release', () => { sha: 'abc123', number: 42, title: defaultPRTitle, - body: defaultPRBody.toString(), + body: new PullRequestBody( + [ + { + version: defaultNextVersion, + notes: defaultPRNotes + } + ], + { + footer + } + ).toString(), labels: [], files: [] } @@ -113,5 +118,62 @@ describe('release', () => { expect(release).toBeDefined() expect(release?.name).toEqual('v1.3.2') }) + + it('parses the sha to release from the pull request footer', async () => { + findMergedReleasePullRequests.resolves([ + { + headBranchName: `release-please--branches--release-1.3.x`, + baseBranchName: 'release-1.3.x', + sha: 'abc123', + number: 42, + title: defaultPRTitle, + body: new PullRequestBody( + [ + { + version: defaultNextVersion, + notes: defaultPRNotes + } + ], + { + footer + } + ).toString(), + labels: [], + files: [] + } + ]) + + const release = await shouldRelease('main') + expect(release).toBeDefined() + expect(release?.sha).toEqual('def456') + }) + + it('returns undefined if it cannot parse a sha from the footer', async () => { + findMergedReleasePullRequests.resolves([ + { + headBranchName: `release-please--branches--release-1.3.x`, + baseBranchName: 'release-1.3.x', + sha: 'abc123', + number: 42, + title: defaultPRTitle, + body: new PullRequestBody( + [ + { + version: defaultNextVersion, + notes: defaultPRNotes + } + ], + { + footer: `not a valid footer` + } + ).toString(), + labels: [], + files: [] + } + ]) + + const release = await shouldRelease('main') + expect(release).not.toBeDefined() + }) }) }) diff --git a/actions/should-release/dist/index.js b/actions/should-release/dist/index.js index 36101f20..80c31fd2 100644 --- a/actions/should-release/dist/index.js +++ b/actions/should-release/dist/index.js @@ -103331,6 +103331,7 @@ async function run() { (0, core_1.setOutput)('shouldRelease', false); return; } + (0, core_1.info)(`releasing ${release.sha} as ${release.name}`); (0, core_1.setOutput)('shouldRelease', true); (0, core_1.setOutput)('sha', JSON.stringify(release.sha)); (0, core_1.setOutput)('name', JSON.stringify(release.name)); @@ -103355,7 +103356,9 @@ Object.defineProperty(exports, "__esModule", ({ value: true })); exports.shouldRelease = void 0; const github_1 = __nccwpck_require__(26851); const pull_request_title_1 = __nccwpck_require__(1158); +const pull_request_body_1 = __nccwpck_require__(70774); const core_1 = __nccwpck_require__(42186); +const logger_1 = __nccwpck_require__(68809); async function shouldRelease(baseBranch) { const gh = await (0, github_1.createGitHubInstance)(baseBranch); const mergedReleasePRs = await (0, github_1.findMergedReleasePullRequests)(baseBranch, gh); @@ -103365,13 +103368,7 @@ async function shouldRelease(baseBranch) { //not a PR we can make a release from continue; } - const prTitle = pull_request_title_1.PullRequestTitle.parse(pullRequest.title); - const version = prTitle?.getVersion(); - if (version === undefined) { - continue; - } - const release = await prepareSingleRelease(pullRequest, version); - (0, core_1.info)(`release: ${release}`); + const release = await prepareSingleRelease(pullRequest); if (release !== undefined) { candidateReleases.push({ ...release @@ -103387,14 +103384,30 @@ async function shouldRelease(baseBranch) { return candidateReleases[0]; } exports.shouldRelease = shouldRelease; -async function prepareSingleRelease(mergedPullRequest, version) { - if (!mergedPullRequest.sha) { +const footerPattern = /^Merging this PR will release the \[artifacts\]\(.*\) of (?\S+)$/; +async function prepareSingleRelease(pullRequest) { + if (!pullRequest.sha) { (0, core_1.error)('Pull request should have been merged'); return; } + const prTitle = pull_request_title_1.PullRequestTitle.parse(pullRequest.title); + const version = prTitle?.getVersion(); + if (version === undefined) { + return; + } + const pullRequestBody = pull_request_body_1.PullRequestBody.parse(pullRequest.body, new logger_1.CheckpointLogger()); + if (!pullRequestBody) { + (0, core_1.error)('Could not parse pull request body as a release PR'); + return; + } + const footer = pullRequestBody.footer; + const match = footer?.match(footerPattern); + if (!match?.groups?.sha) { + return; + } return { name: `v${version.toString()}`, - sha: mergedPullRequest.sha + sha: match.groups.sha }; } diff --git a/actions/should-release/src/main.ts b/actions/should-release/src/main.ts index 6885dc0e..d65e8f9f 100644 --- a/actions/should-release/src/main.ts +++ b/actions/should-release/src/main.ts @@ -19,6 +19,7 @@ export async function run(): Promise { return } + info(`releasing ${release.sha} as ${release.name}`) setOutput('shouldRelease', true) setOutput('sha', JSON.stringify(release.sha)) setOutput('name', JSON.stringify(release.name)) diff --git a/actions/should-release/src/release.ts b/actions/should-release/src/release.ts index cdecfb7a..f37a0d54 100644 --- a/actions/should-release/src/release.ts +++ b/actions/should-release/src/release.ts @@ -1,10 +1,11 @@ import { createGitHubInstance, findMergedReleasePullRequests } from './github' -import { Version } from 'release-please/build/src/version' import { PullRequest } from 'release-please/build/src/pull-request' import { PullRequestTitle } from 'release-please/build/src/util/pull-request-title' +import { PullRequestBody } from 'release-please/build/src/util/pull-request-body' -import { error, info, warning } from '@actions/core' +import { error, warning } from '@actions/core' +import { CheckpointLogger } from 'release-please/build/src/util/logger' export async function shouldRelease( baseBranch: string @@ -19,14 +20,7 @@ export async function shouldRelease( continue } - const prTitle = PullRequestTitle.parse(pullRequest.title) - const version = prTitle?.getVersion() - if (version === undefined) { - continue - } - - const release = await prepareSingleRelease(pullRequest, version) - info(`release: ${release}`) + const release = await prepareSingleRelease(pullRequest) if (release !== undefined) { candidateReleases.push({ @@ -53,17 +47,40 @@ type ReleaseMeta = { sha?: string | undefined } +const footerPattern = + /^Merging this PR will release the \[artifacts\]\(.*\) of (?\S+)$/ + async function prepareSingleRelease( - mergedPullRequest: PullRequest, - version: Version + pullRequest: PullRequest ): Promise { - if (!mergedPullRequest.sha) { + if (!pullRequest.sha) { error('Pull request should have been merged') return } + const prTitle = PullRequestTitle.parse(pullRequest.title) + const version = prTitle?.getVersion() + if (version === undefined) { + return + } + + const pullRequestBody = PullRequestBody.parse( + pullRequest.body, + new CheckpointLogger() + ) + if (!pullRequestBody) { + error('Could not parse pull request body as a release PR') + return + } + + const footer = pullRequestBody.footer + const match = footer?.match(footerPattern) + if (!match?.groups?.sha) { + return + } + return { name: `v${version.toString()}`, - sha: mergedPullRequest.sha + sha: match.groups.sha } } diff --git a/cmd/main.go b/cmd/main.go new file mode 100644 index 00000000..f51317ea --- /dev/null +++ b/cmd/main.go @@ -0,0 +1,16 @@ +package main + +import ( + "fmt" + + "github.com/hashicorp/go-uuid" +) + +func main() { + + uid, err := uuid.GenerateUUID() + if err != nil { + fmt.Println("Error generating UUID") + } + fmt.Println("This is not really a go program, just meant to look like one. Here's a UUID: ", uid) +} diff --git a/go.mod b/go.mod new file mode 100644 index 00000000..a051ab55 --- /dev/null +++ b/go.mod @@ -0,0 +1,7 @@ +module github.com/grafana/loki-release + +go 1.21 + +toolchain go1.21.3 + +require github.com/hashicorp/go-uuid v1.0.3 diff --git a/go.sum b/go.sum new file mode 100644 index 00000000..bad48921 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8= +github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= diff --git a/release-please-config.json b/release-please-config.json index 43ae61ba..e708dc3e 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -1,11 +1,7 @@ { "bootstrap-sha": "b100d6fe25669928cb023e4b869af0cfe353b7b1", "versioning": "always-bump-patch", - "release-type": "simple", - "bump-minor-pre-major": false, - "bump-patch-for-minor-pre-major": false, - "draft": false, - "prerelease": false, + "draft": true, "include-component-in-tag": false, "packages": { ".": { diff --git a/vendor/github.com/hashicorp/go-uuid/.travis.yml b/vendor/github.com/hashicorp/go-uuid/.travis.yml new file mode 100644 index 00000000..76984907 --- /dev/null +++ b/vendor/github.com/hashicorp/go-uuid/.travis.yml @@ -0,0 +1,12 @@ +language: go + +sudo: false + +go: + - 1.4 + - 1.5 + - 1.6 + - tip + +script: + - go test -bench . -benchmem -v ./... diff --git a/vendor/github.com/hashicorp/go-uuid/LICENSE b/vendor/github.com/hashicorp/go-uuid/LICENSE new file mode 100644 index 00000000..a320b309 --- /dev/null +++ b/vendor/github.com/hashicorp/go-uuid/LICENSE @@ -0,0 +1,365 @@ +Copyright © 2015-2022 HashiCorp, Inc. + +Mozilla Public License, version 2.0 + +1. Definitions + +1.1. "Contributor" + + means each individual or legal entity that creates, contributes to the + creation of, or owns Covered Software. + +1.2. "Contributor Version" + + means the combination of the Contributions of others (if any) used by a + Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + + means Source Code Form to which the initial Contributor has attached the + notice in Exhibit A, the Executable Form of such Source Code Form, and + Modifications of such Source Code Form, in each case including portions + thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + a. that the initial Contributor has attached the notice described in + Exhibit B to the Covered Software; or + + b. that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the terms of + a Secondary License. + +1.6. "Executable Form" + + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + + means a work that combines Covered Software with other material, in a + separate file or files, that is not Covered Software. + +1.8. "License" + + means this document. + +1.9. "Licensable" + + means having the right to grant, to the maximum extent possible, whether + at the time of the initial grant or subsequently, any and all of the + rights conveyed by this License. + +1.10. "Modifications" + + means any of the following: + + a. any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered Software; or + + b. any new file in Source Code Form that contains any Covered Software. + +1.11. "Patent Claims" of a Contributor + + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the License, + by the making, using, selling, offering for sale, having made, import, + or transfer of either its Contributions or its Contributor Version. + +1.12. "Secondary License" + + means either the GNU General Public License, Version 2.0, the GNU Lesser + General Public License, Version 2.1, the GNU Affero General Public + License, Version 3.0, or any later versions of those licenses. + +1.13. "Source Code Form" + + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that controls, is + controlled by, or is under common control with You. For purposes of this + definition, "control" means (a) the power, direct or indirect, to cause + the direction or management of such entity, whether by contract or + otherwise, or (b) ownership of more than fifty percent (50%) of the + outstanding shares or beneficial ownership of such entity. + + +2. License Grants and Conditions + +2.1. Grants + + Each Contributor hereby grants You a world-wide, royalty-free, + non-exclusive license: + + a. under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + + b. under Patent Claims of such Contributor to make, use, sell, offer for + sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + + The licenses granted in Section 2.1 with respect to any Contribution + become effective for each Contribution on the date the Contributor first + distributes such Contribution. + +2.3. Limitations on Grant Scope + + The licenses granted in this Section 2 are the only rights granted under + this License. No additional rights or licenses will be implied from the + distribution or licensing of Covered Software under this License. + Notwithstanding Section 2.1(b) above, no patent license is granted by a + Contributor: + + a. for any code that a Contributor has removed from Covered Software; or + + b. for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + + c. under Patent Claims infringed by Covered Software in the absence of + its Contributions. + + This License does not grant any rights in the trademarks, service marks, + or logos of any Contributor (except as may be necessary to comply with + the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + + No Contributor makes additional grants as a result of Your choice to + distribute the Covered Software under a subsequent version of this + License (see Section 10.2) or under the terms of a Secondary License (if + permitted under the terms of Section 3.3). + +2.5. Representation + + Each Contributor represents that the Contributor believes its + Contributions are its original creation(s) or it has sufficient rights to + grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + + This License is not intended to limit any rights You have under + applicable copyright doctrines of fair use, fair dealing, or other + equivalents. + +2.7. Conditions + + Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in + Section 2.1. + + +3. Responsibilities + +3.1. Distribution of Source Form + + All distribution of Covered Software in Source Code Form, including any + Modifications that You create or to which You contribute, must be under + the terms of this License. You must inform recipients that the Source + Code Form of the Covered Software is governed by the terms of this + License, and how they can obtain a copy of this License. You may not + attempt to alter or restrict the recipients' rights in the Source Code + Form. + +3.2. Distribution of Executable Form + + If You distribute Covered Software in Executable Form then: + + a. such Covered Software must also be made available in Source Code Form, + as described in Section 3.1, and You must inform recipients of the + Executable Form how they can obtain a copy of such Source Code Form by + reasonable means in a timely manner, at a charge no more than the cost + of distribution to the recipient; and + + b. You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter the + recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + + You may create and distribute a Larger Work under terms of Your choice, + provided that You also comply with the requirements of this License for + the Covered Software. If the Larger Work is a combination of Covered + Software with a work governed by one or more Secondary Licenses, and the + Covered Software is not Incompatible With Secondary Licenses, this + License permits You to additionally distribute such Covered Software + under the terms of such Secondary License(s), so that the recipient of + the Larger Work may, at their option, further distribute the Covered + Software under the terms of either this License or such Secondary + License(s). + +3.4. Notices + + You may not remove or alter the substance of any license notices + (including copyright notices, patent notices, disclaimers of warranty, or + limitations of liability) contained within the Source Code Form of the + Covered Software, except that You may alter any license notices to the + extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + + You may choose to offer, and to charge a fee for, warranty, support, + indemnity or liability obligations to one or more recipients of Covered + Software. However, You may do so only on Your own behalf, and not on + behalf of any Contributor. You must make it absolutely clear that any + such warranty, support, indemnity, or liability obligation is offered by + You alone, and You hereby agree to indemnify every Contributor for any + liability incurred by such Contributor as a result of warranty, support, + indemnity or liability terms You offer. You may include additional + disclaimers of warranty and limitations of liability specific to any + jurisdiction. + +4. Inability to Comply Due to Statute or Regulation + + If it is impossible for You to comply with any of the terms of this License + with respect to some or all of the Covered Software due to statute, + judicial order, or regulation then You must: (a) comply with the terms of + this License to the maximum extent possible; and (b) describe the + limitations and the code they affect. Such description must be placed in a + text file included with all distributions of the Covered Software under + this License. Except to the extent prohibited by statute or regulation, + such description must be sufficiently detailed for a recipient of ordinary + skill to be able to understand it. + +5. Termination + +5.1. The rights granted under this License will terminate automatically if You + fail to comply with any of its terms. However, if You become compliant, + then the rights granted under this License from a particular Contributor + are reinstated (a) provisionally, unless and until such Contributor + explicitly and finally terminates Your grants, and (b) on an ongoing + basis, if such Contributor fails to notify You of the non-compliance by + some reasonable means prior to 60 days after You have come back into + compliance. Moreover, Your grants from a particular Contributor are + reinstated on an ongoing basis if such Contributor notifies You of the + non-compliance by some reasonable means, this is the first time You have + received notice of non-compliance with this License from such + Contributor, and You become compliant prior to 30 days after Your receipt + of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent + infringement claim (excluding declaratory judgment actions, + counter-claims, and cross-claims) alleging that a Contributor Version + directly or indirectly infringes any patent, then the rights granted to + You by any and all Contributors for the Covered Software under Section + 2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user + license agreements (excluding distributors and resellers) which have been + validly granted by You or Your distributors under this License prior to + termination shall survive termination. + +6. Disclaimer of Warranty + + Covered Software is provided under this License on an "as is" basis, + without warranty of any kind, either expressed, implied, or statutory, + including, without limitation, warranties that the Covered Software is free + of defects, merchantable, fit for a particular purpose or non-infringing. + The entire risk as to the quality and performance of the Covered Software + is with You. Should any Covered Software prove defective in any respect, + You (not any Contributor) assume the cost of any necessary servicing, + repair, or correction. This disclaimer of warranty constitutes an essential + part of this License. No use of any Covered Software is authorized under + this License except under this disclaimer. + +7. Limitation of Liability + + Under no circumstances and under no legal theory, whether tort (including + negligence), contract, or otherwise, shall any Contributor, or anyone who + distributes Covered Software as permitted above, be liable to You for any + direct, indirect, special, incidental, or consequential damages of any + character including, without limitation, damages for lost profits, loss of + goodwill, work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses, even if such party shall have been + informed of the possibility of such damages. This limitation of liability + shall not apply to liability for death or personal injury resulting from + such party's negligence to the extent applicable law prohibits such + limitation. Some jurisdictions do not allow the exclusion or limitation of + incidental or consequential damages, so this exclusion and limitation may + not apply to You. + +8. Litigation + + Any litigation relating to this License may be brought only in the courts + of a jurisdiction where the defendant maintains its principal place of + business and such litigation shall be governed by laws of that + jurisdiction, without reference to its conflict-of-law provisions. Nothing + in this Section shall prevent a party's ability to bring cross-claims or + counter-claims. + +9. Miscellaneous + + This License represents the complete agreement concerning the subject + matter hereof. If any provision of this License is held to be + unenforceable, such provision shall be reformed only to the extent + necessary to make it enforceable. Any law or regulation which provides that + the language of a contract shall be construed against the drafter shall not + be used to construe this License against a Contributor. + + +10. Versions of the License + +10.1. New Versions + + Mozilla Foundation is the license steward. Except as provided in Section + 10.3, no one other than the license steward has the right to modify or + publish new versions of this License. Each version will be given a + distinguishing version number. + +10.2. Effect of New Versions + + You may distribute the Covered Software under the terms of the version + of the License under which You originally received the Covered Software, + or under the terms of any subsequent version published by the license + steward. + +10.3. Modified Versions + + If you create software not governed by this License, and you want to + create a new license for such software, you may create and use a + modified version of this License if you rename the license and remove + any references to the name of the license steward (except to note that + such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary + Licenses If You choose to distribute Source Code Form that is + Incompatible With Secondary Licenses under the terms of this version of + the License, the notice described in Exhibit B of this License must be + attached. + +Exhibit A - Source Code Form License Notice + + This Source Code Form is subject to the + terms of the Mozilla Public License, v. + 2.0. If a copy of the MPL was not + distributed with this file, You can + obtain one at + http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular file, +then You may include the notice in a location (such as a LICENSE file in a +relevant directory) where a recipient would be likely to look for such a +notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice + + This Source Code Form is "Incompatible + With Secondary Licenses", as defined by + the Mozilla Public License, v. 2.0. + diff --git a/vendor/github.com/hashicorp/go-uuid/README.md b/vendor/github.com/hashicorp/go-uuid/README.md new file mode 100644 index 00000000..fbde8b9a --- /dev/null +++ b/vendor/github.com/hashicorp/go-uuid/README.md @@ -0,0 +1,8 @@ +# uuid [![Build Status](https://travis-ci.org/hashicorp/go-uuid.svg?branch=master)](https://travis-ci.org/hashicorp/go-uuid) + +Generates UUID-format strings using high quality, _purely random_ bytes. It is **not** intended to be RFC compliant, merely to use a well-understood string representation of a 128-bit value. It can also parse UUID-format strings into their component bytes. + +Documentation +============= + +The full documentation is available on [Godoc](http://godoc.org/github.com/hashicorp/go-uuid). diff --git a/vendor/github.com/hashicorp/go-uuid/uuid.go b/vendor/github.com/hashicorp/go-uuid/uuid.go new file mode 100644 index 00000000..0c10c4e9 --- /dev/null +++ b/vendor/github.com/hashicorp/go-uuid/uuid.go @@ -0,0 +1,83 @@ +package uuid + +import ( + "crypto/rand" + "encoding/hex" + "fmt" + "io" +) + +// GenerateRandomBytes is used to generate random bytes of given size. +func GenerateRandomBytes(size int) ([]byte, error) { + return GenerateRandomBytesWithReader(size, rand.Reader) +} + +// GenerateRandomBytesWithReader is used to generate random bytes of given size read from a given reader. +func GenerateRandomBytesWithReader(size int, reader io.Reader) ([]byte, error) { + if reader == nil { + return nil, fmt.Errorf("provided reader is nil") + } + buf := make([]byte, size) + if _, err := io.ReadFull(reader, buf); err != nil { + return nil, fmt.Errorf("failed to read random bytes: %v", err) + } + return buf, nil +} + + +const uuidLen = 16 + +// GenerateUUID is used to generate a random UUID +func GenerateUUID() (string, error) { + return GenerateUUIDWithReader(rand.Reader) +} + +// GenerateUUIDWithReader is used to generate a random UUID with a given Reader +func GenerateUUIDWithReader(reader io.Reader) (string, error) { + if reader == nil { + return "", fmt.Errorf("provided reader is nil") + } + buf, err := GenerateRandomBytesWithReader(uuidLen, reader) + if err != nil { + return "", err + } + return FormatUUID(buf) +} + +func FormatUUID(buf []byte) (string, error) { + if buflen := len(buf); buflen != uuidLen { + return "", fmt.Errorf("wrong length byte slice (%d)", buflen) + } + + return fmt.Sprintf("%x-%x-%x-%x-%x", + buf[0:4], + buf[4:6], + buf[6:8], + buf[8:10], + buf[10:16]), nil +} + +func ParseUUID(uuid string) ([]byte, error) { + if len(uuid) != 2 * uuidLen + 4 { + return nil, fmt.Errorf("uuid string is wrong length") + } + + if uuid[8] != '-' || + uuid[13] != '-' || + uuid[18] != '-' || + uuid[23] != '-' { + return nil, fmt.Errorf("uuid is improperly formatted") + } + + hexStr := uuid[0:8] + uuid[9:13] + uuid[14:18] + uuid[19:23] + uuid[24:36] + + ret, err := hex.DecodeString(hexStr) + if err != nil { + return nil, err + } + if len(ret) != uuidLen { + return nil, fmt.Errorf("decoded hex is the wrong length") + } + + return ret, nil +} diff --git a/vendor/modules.txt b/vendor/modules.txt new file mode 100644 index 00000000..a1b9ac6b --- /dev/null +++ b/vendor/modules.txt @@ -0,0 +1,3 @@ +# github.com/hashicorp/go-uuid v1.0.3 +## explicit +github.com/hashicorp/go-uuid diff --git a/workflows/lib/build.libsonnet b/workflows/lib/build.libsonnet index 6fd21510..a8e4bf5d 100644 --- a/workflows/lib/build.libsonnet +++ b/workflows/lib/build.libsonnet @@ -16,7 +16,6 @@ local releaseStep = common.releaseStep; ], }, }) - + job.withIf('${{ inputs.release_repo }} == grafana/loki') + job.withSteps([ common.fetchReleaseRepo, common.setupGo, @@ -34,17 +33,19 @@ local releaseStep = common.releaseStep; echo "version=${version}" >> $GITHUB_OUTPUT ||| % path), step.new('Build and export', 'docker/build-push-action@v5') + + step.withIf("${{ inputs.release_repo == 'grafana/loki' }}") + step.with({ context: 'release', file: 'release/%s/Dockerfile' % path, platforms: '${{ matrix.platform }}', tags: 'grafana/%s:${{ steps.parse-metadata.outputs.version }}' % name, - outputs: 'type=docker,dest=release/dist/%s-${{ steps.parse-metadata.outputs.version}}-${{ steps.parse-metadata.outputs.platform }}.tar' % name, + outputs: 'type=docker,dest=release/images/%s-${{ steps.parse-metadata.outputs.version}}-${{ steps.parse-metadata.outputs.platform }}.tar' % name, }), step.new('upload artifacts', 'actions/upload-artifact@v3') + + step.withIf("${{ inputs.release_repo == 'grafana/loki' }}") + step.with({ name: '%s-image-${{ steps.parse-metadata.outputs.version}}-${{ steps.parse-metadata.outputs.platform }}' % name, - path: 'release/dist/%s-${{ steps.parse-metadata.outputs.version}}-${{ steps.parse-metadata.outputs.platform }}.tar' % name, + path: 'release/images/%s-${{ steps.parse-metadata.outputs.version}}-${{ steps.parse-metadata.outputs.platform }}.tar' % name, }), ]), @@ -71,15 +72,11 @@ local releaseStep = common.releaseStep; releaseStep('build artifacts') + step.withRun('make BUILD_IN_CONTAINER=false SKIP_ARM=true dist'), - releaseStep('pacakge artifacts') - + step.withRun(||| - tar -czf dist.tar.gz dist - |||), - step.new('upload build artifacts', 'google-github-actions/upload-cloud-storage@v1') + step.with({ - path: 'release/dist.tar.gz', - destination: 'loki-build-artifacts/${{ github.sha }}/dist.tar.gz', //TODO: make bucket configurable + path: 'release/dist', + destination: 'loki-build-artifacts/${{ github.sha }}', //TODO: make bucket configurable + process_gcloudignore: false, }), ]), } diff --git a/workflows/lib/common.libsonnet b/workflows/lib/common.libsonnet index f7133b12..358e2ff1 100644 --- a/workflows/lib/common.libsonnet +++ b/workflows/lib/common.libsonnet @@ -63,8 +63,8 @@ }), setupGo: $.step.new('setup go', 'actions/setup-go@v4') + $.step.with({ - 'go-version-file': 'loki/go.mod', - 'cache-dependency-path': 'loki/go.sum', + 'go-version-file': 'release/go.mod', + 'cache-dependency-path': 'release/go.sum', }), setupNode: $.step.new('setup node', 'actions/setup-node@v4') diff --git a/workflows/lib/release.libsonnet b/workflows/lib/release.libsonnet index 4e2a394a..51f29b31 100644 --- a/workflows/lib/release.libsonnet +++ b/workflows/lib/release.libsonnet @@ -4,6 +4,13 @@ local step = common.step; local releaseStep = common.releaseStep; local releaseLibStep = common.releaseLibStep; +// DO NOT MODIFY THIS FOOTER TEMPLATE +// This template is matched by the should-release action to detect the correct +// sha to release and pull aritfacts from. If you need to change this, make sure +// to change it in both places. +//TODO: make bucket configurable +local pullRequestFooter = 'Merging this PR will release the [artifacts](https://console.cloud.google.com/storage/browser/loki-build-artifacts/${SHA}) of ${SHA}'; + { createReleasePR: job.new() @@ -20,13 +27,19 @@ local releaseLibStep = common.releaseLibStep; releaseLibStep('release please') + step.withId('release') + + step.withEnv({ + SHA: '${{ github.sha }}', + }) + //TODO make bucket configurable + step.withRun(||| npm install npm exec -- release-please release-pr \ - --token="${{ secrets.GH_TOKEN }}" \ + --pull-request-footer "%s" \ + --release-type simple \ --repo-url="${{ inputs.release_repo }}" \ - --target-branch "${{ steps.extract_branch.outputs.branch }}" - |||), + --target-branch "${{ steps.extract_branch.outputs.branch }}" \ + --token="${{ secrets.GH_TOKEN }}" + ||| % pullRequestFooter), ]), release: job.new() @@ -59,20 +72,21 @@ local releaseLibStep = common.releaseLibStep; releaseStep('download build artifacts') + step.withIf('${{ fromJSON(steps.should_release.outputs.shouldRelease) }}') + step.withRun(||| - gsutil cp -r gs://loki-build-artifacts/${{ steps.prepare.outputs.sha }}/dist . + gsutil cp -r gs://loki-build-artifacts/${{ steps.should_release.outputs.sha }}/dist . ls dist |||), releaseStep('release please') - + step.withIf('${{ fromJSON(steps.prepare.should_release.shouldRelease) }}') + + step.withIf('${{ fromJSON(steps.should_release.outputs.shouldRelease) }}') + step.withId('release') + step.withRun(||| npm install npm exec -- release-please github-release \ - --token="${{ secrets.GH_TOKEN }}" \ + --draft \ + --release-type simple \ --repo-url="${{ inputs.release_repo }}" \ --target-branch "${{ steps.extract_branch.outputs.branch }}" \ - --draft + --token="${{ secrets.GH_TOKEN }}" |||), releaseStep('upload artifacts')