diff --git a/.eslintrc.yml b/.eslintrc.yml index 8dfb7f9a..cd0fd998 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -14,6 +14,8 @@ ignorePatterns: - '**/coverage/.*' - '*.json' - '**/.direnv' + - .lintstagedrc.js + - commitlint.config.js parser: '@typescript-eslint/parser' diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml new file mode 100644 index 00000000..1dd6d689 --- /dev/null +++ b/.github/workflows/pr.yml @@ -0,0 +1,118 @@ +--- +name: Check PR +on: + pull_request: {} +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Use Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + - name: Cache node modules + id: cache-npm + uses: actions/cache@v3 + env: + cache-name: cache-node-modules + with: + # npm cache files are stored in `~/.npm` on Linux/macOS + path: ~/.npm + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- + + - if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }} + name: List the state of node modules + continue-on-error: true + run: npm list + + - run: npm install + - run: npm run lint + actions: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Use Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + - name: Cache node modules + id: cache-npm + uses: actions/cache@v3 + env: + cache-name: cache-node-modules + with: + # npm cache files are stored in `~/.npm` on Linux/macOS + path: ~/.npm + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- + + - if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }} + name: List the state of node modules + continue-on-error: true + run: npm list + + - run: npm install + - run: npm run actions + - run: | + git diff --name-only -- "actions/**/*.js" | xargs --no-run-if-empty git diff --exit-code -- \ + || (echo "Change to actions detected, please run 'npm run actions' and commit the changes" && false) + workflows: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Use Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + - uses: kobtea/setup-jsonnet-action@v1 + - run: npm run workflows + - run: | + git diff --name-only - w -- ".github/workflows/*.yml" | xargs --no-run-if-empty git diff -w --exit-code -- \ + || (echo "Change to workflows detected, please run 'npm run workflows' and commit the changes" && false) + test: + runs-on: ubuntu-latest + needs: + - lint + - actions + - workflows + steps: + - uses: actions/checkout@v4 + - name: Use Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + - name: Cache node modules + id: cache-npm + uses: actions/cache@v3 + env: + cache-name: cache-node-modules + with: + # npm cache files are stored in `~/.npm` on Linux/macOS + path: ~/.npm + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- + + - if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }} + name: List the state of node modules + continue-on-error: true + run: npm list + + - run: npm install + - run: npm run ci-test + check-title: + runs-on: ubuntu-latest + steps: + - uses: amannn/action-semantic-pull-request@v5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release-pr.yml b/.github/workflows/release-pr.yml index b71bdc74..e65c3a29 100644 --- a/.github/workflows/release-pr.yml +++ b/.github/workflows/release-pr.yml @@ -1,9 +1,11 @@ concurrency: group: "create-release-pr-${{ github.sha }}" env: + BUILD_ARTIFACTS_BUCKET: "loki-build-artifacts" BUILD_TIMEOUT: 25 CHANGELOG_PATH: "CHANGELOG.md" DOCKER_USERNAME: "grafana" + DRY_RUN: false IMAGE_PREFIX: "trevorwhitney075" RELEASE_LIB_REF: "release-1.12.x" RELEASE_REPO: "grafana/loki-release" @@ -73,14 +75,15 @@ jobs: --group-pull-request-title-pattern "chore\${scope}: release\${component} \${version}" \ --label "backport main,autorelease: pending,product-approved" \ --manifest-file .release-please-manifest.json \ - --pull-request-footer "Merging this PR will release the [artifacts](https://console.cloud.google.com/storage/browser/loki-build-artifacts/${SHA}) of ${SHA}" \ + --pull-request-footer "Merging this PR will release the [artifacts](https://console.cloud.google.com/storage/browser/${BUILD_ARTIFACTS_BUCKET}/${SHA}) of ${SHA}" \ --pull-request-title-pattern "chore\${scope}: release\${component} \${version}" \ --release-type simple \ --repo-url "${{ env.RELEASE_REPO }}" \ --separate-pull-requests false \ --target-branch "${{ steps.extract_branch.outputs.branch }}" \ --token "${{ steps.github_app_token.outputs.token }}" \ - --versioning-strategy "${{ env.VERSIONING_STRATEGY }}" + --versioning-strategy "${{ env.VERSIONING_STRATEGY }}" \ + --dry-run ${{ fromJSON(env.DRY_RUN) }} working-directory: "lib" dist: @@ -138,7 +141,7 @@ jobs: name: "upload artifacts" uses: "google-github-actions/upload-cloud-storage@v2" with: - destination: "loki-build-artifacts/${{ github.sha }}" + destination: "${{ env.BUILD_ARTIFACTS_BUCKET }}/${{ github.sha }}" path: "release/dist" process_gcloudignore: false loki: @@ -195,7 +198,7 @@ jobs: name: "upload artifacts" uses: "google-github-actions/upload-cloud-storage@v2" with: - destination: "loki-build-artifacts/${{ github.sha }}/images" + destination: "${{ env.BUILD_ARTIFACTS_BUCKET }}/${{ github.sha }}/images" path: "release/images/fake-loki-${{ needs.version.outputs.version}}-${{ steps.platform.outputs.platform }}.tar" process_gcloudignore: false strategy: @@ -284,7 +287,7 @@ jobs: echo "pr_created=true" >> $GITHUB_OUTPUT fi working-directory: "lib" -name: "create release PR" +name: "Create Release PR" "on": push: branches: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1e50e252..16009ce8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,6 +1,7 @@ concurrency: group: "create-release-${{ github.sha }}" env: + BUILD_ARTIFACTS_BUCKET: "loki-build-artifacts" IMAGE_PREFIX: "trevorwhitney075" PUBLISH_TO_GCS: false RELEASE_LIB_REF: "release-1.12.x" @@ -61,7 +62,7 @@ jobs: - name: "download binaries" run: | echo "downloading binaries to $(pwd)/dist" - gsutil cp -r gs://loki-build-artifacts/${{ needs.shouldRelease.outputs.sha }}/dist . + gsutil cp -r gs://${BUILD_ARTIFACTS_BUCKET}/${{ needs.shouldRelease.outputs.sha }}/dist . working-directory: "release" - env: GH_TOKEN: "${{ steps.github_app_token.outputs.token }}" @@ -208,8 +209,9 @@ jobs: uses: "./lib/actions/should-release" with: baseBranch: "${{ steps.extract_branch.outputs.branch }}" -name: "create release" +name: "Create Release" "on": + pull_request: {} push: branches: - "release-[0-9]+.[0-9]+.x" diff --git a/.github/workflows/test-release-pr.yml b/.github/workflows/test-release-pr.yml new file mode 100644 index 00000000..8326e93c --- /dev/null +++ b/.github/workflows/test-release-pr.yml @@ -0,0 +1,299 @@ +concurrency: + group: "create-release-pr-${{ github.sha }}" +env: + BUILD_ARTIFACTS_BUCKET: "loki-build-artifacts" + BUILD_TIMEOUT: 25 + CHANGELOG_PATH: "CHANGELOG.md" + DOCKER_USERNAME: "grafana" + DRY_RUN: true + IMAGE_PREFIX: "trevorwhitney075" + RELEASE_LIB_REF: "release-1.12.x" + RELEASE_REPO: "grafana/loki-release" + SKIP_VALIDATION: false + USE_GITHUB_APP_TOKEN: true + VERSIONING_STRATEGY: "always-bump-patch" +jobs: + check: + uses: "./.github/workflows/check.yml" + with: + build_image: "grafana/loki-build-image:0.33.0" + golang_ci_lint_version: "v1.55.1" + release_lib_ref: "release-1.12.x" + skip_validation: false + use_github_app_token: true + create-release-pr: + needs: + - "dist" + - "loki" + runs-on: "ubuntu-latest" + steps: + - name: "pull code to release" + uses: "actions/checkout@v4" + with: + path: "release" + repository: "${{ env.RELEASE_REPO }}" + - name: "pull release library code" + uses: "actions/checkout@v4" + with: + path: "lib" + ref: "${{ env.RELEASE_LIB_REF }}" + repository: "grafana/loki-release" + - name: "setup node" + uses: "actions/setup-node@v4" + with: + node-version: 20 + - id: "extract_branch" + name: "extract branch name" + run: | + echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT + working-directory: "release" + - id: "get_github_app_token" + if: "${{ fromJSON(env.USE_GITHUB_APP_TOKEN) }}" + name: "get github app token" + uses: "actions/github-app-token@v1" + with: + app-id: "${{ secrets.APP_ID }}" + owner: "${{ github.repository_owner }}" + private-key: "${{ secrets.APP_PRIVATE_KEY }}" + - id: "github_app_token" + name: "set github token" + run: | + if [[ "${USE_GITHUB_APP_TOKEN}" == "true" ]]; then + echo "token=${{ steps.get_github_app_token.outputs.token }}" >> $GITHUB_OUTPUT + else + echo "token=${{ secrets.GH_TOKEN }}" >> $GITHUB_OUTPUT + fi + - env: + SHA: "${{ github.sha }}" + id: "release" + name: "release please" + run: | + npm install + npm exec -- release-please release-pr \ + --changelog-path "${CHANGELOG_PATH}" \ + --consider-all-branches \ + --group-pull-request-title-pattern "chore\${scope}: release\${component} \${version}" \ + --label "backport main,autorelease: pending,product-approved" \ + --manifest-file .release-please-manifest.json \ + --pull-request-footer "Merging this PR will release the [artifacts](https://console.cloud.google.com/storage/browser/${BUILD_ARTIFACTS_BUCKET}/${SHA}) of ${SHA}" \ + --pull-request-title-pattern "chore\${scope}: release\${component} \${version}" \ + --release-type simple \ + --repo-url "${{ env.RELEASE_REPO }}" \ + --separate-pull-requests false \ + --target-branch "${{ steps.extract_branch.outputs.branch }}" \ + --token "${{ steps.github_app_token.outputs.token }}" \ + --versioning-strategy "${{ env.VERSIONING_STRATEGY }}" \ + --dry-run ${{ fromJSON(env.DRY_RUN) }} + + working-directory: "lib" + dist: + needs: + - "version" + runs-on: "ubuntu-latest" + steps: + - name: "pull code to release" + uses: "actions/checkout@v4" + with: + path: "release" + repository: "${{ env.RELEASE_REPO }}" + - name: "auth gcs" + uses: "google-github-actions/auth@v2" + with: + credentials_json: "${{ secrets.GCS_SERVICE_ACCOUNT_KEY }}" + - name: "Set up Cloud SDK" + uses: "google-github-actions/setup-gcloud@v2" + with: + version: ">= 452.0.0" + - id: "get-secrets" + name: "get nfpm signing keys" + uses: "grafana/shared-workflows/actions/get-vault-secrets@main" + with: + common_secrets: | + NFPM_SIGNING_KEY=packages-gpg:private-key + NFPM_PASSPHRASE=packages-gpg:passphrase + - env: + BUILD_IN_CONTAINER: false + DRONE_TAG: "${{ needs.version.outputs.version }}" + IMAGE_TAG: "${{ needs.version.outputs.version }}" + NFPM_SIGNING_KEY_FILE: "nfpm-private-key.key" + SKIP_ARM: false + if: "${{ fromJSON(needs.version.outputs.pr_created) }}" + name: "build artifacts" + run: | + cat < $NFPM_SIGNING_KEY_FILE + make dist packages + EOF + working-directory: "release" + - if: "${{ fromJSON(needs.version.outputs.pr_created) }}" + name: "upload artifacts" + uses: "google-github-actions/upload-cloud-storage@v2" + with: + destination: "${{ env.BUILD_ARTIFACTS_BUCKET }}/${{ github.sha }}" + path: "release/dist" + process_gcloudignore: false + loki: + needs: + - "version" + runs-on: "ubuntu-latest" + steps: + - name: "pull release library code" + uses: "actions/checkout@v4" + with: + path: "lib" + ref: "${{ env.RELEASE_LIB_REF }}" + repository: "grafana/loki-release" + - name: "pull code to release" + uses: "actions/checkout@v4" + with: + path: "release" + repository: "${{ env.RELEASE_REPO }}" + - name: "setup node" + uses: "actions/setup-node@v4" + with: + node-version: 20 + - name: "auth gcs" + uses: "google-github-actions/auth@v2" + with: + credentials_json: "${{ secrets.GCS_SERVICE_ACCOUNT_KEY }}" + - name: "Set up QEMU" + uses: "docker/setup-qemu-action@v3" + - name: "set up docker buildx" + uses: "docker/setup-buildx-action@v3" + - id: "platform" + name: "parse image platform" + run: | + mkdir -p images + + platform="$(echo "${{ matrix.platform}}" | sed "s/\(.*\)\/\(.*\)/\1-\2/")" + echo "platform=${platform}" >> $GITHUB_OUTPUT + echo "platform_short=$(echo ${{ matrix.platform }} | cut -d / -f 2)" >> $GITHUB_OUTPUT + working-directory: "release" + - env: + IMAGE_TAG: "${{ needs.version.outputs.version }}" + if: "${{ fromJSON(needs.version.outputs.pr_created) }}" + name: "Build and export" + timeout-minutes: "${{ fromJSON(env.BUILD_TIMEOUT) }}" + uses: "docker/build-push-action@v5" + with: + build-args: "IMAGE_TAG=${{ needs.version.outputs.version }}" + context: "release" + file: "release/cmd/loki/Dockerfile" + outputs: "type=docker,dest=release/images/fake-loki-${{ needs.version.outputs.version}}-${{ steps.platform.outputs.platform }}.tar" + platforms: "${{ matrix.platform }}" + tags: "${{ env.IMAGE_PREFIX }}/fake-loki:${{ needs.version.outputs.version }}-${{ steps.platform.outputs.platform_short }}" + - if: "${{ fromJSON(needs.version.outputs.pr_created) }}" + name: "upload artifacts" + uses: "google-github-actions/upload-cloud-storage@v2" + with: + destination: "${{ env.BUILD_ARTIFACTS_BUCKET }}/${{ github.sha }}/images" + path: "release/images/fake-loki-${{ needs.version.outputs.version}}-${{ steps.platform.outputs.platform }}.tar" + process_gcloudignore: false + strategy: + fail-fast: true + matrix: + platform: + - "linux/amd64" + - "linux/arm64" + - "linux/arm" + version: + needs: + - "check" + outputs: + pr_created: "${{ steps.version.outputs.pr_created }}" + version: "${{ steps.version.outputs.version }}" + runs-on: "ubuntu-latest" + steps: + - name: "pull release library code" + uses: "actions/checkout@v4" + with: + path: "lib" + ref: "${{ env.RELEASE_LIB_REF }}" + repository: "grafana/loki-release" + - name: "pull code to release" + uses: "actions/checkout@v4" + with: + path: "release" + repository: "${{ env.RELEASE_REPO }}" + - name: "setup node" + uses: "actions/setup-node@v4" + with: + node-version: 20 + - id: "extract_branch" + name: "extract branch name" + run: | + echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT + working-directory: "release" + - id: "get_github_app_token" + if: "${{ fromJSON(env.USE_GITHUB_APP_TOKEN) }}" + name: "get github app token" + uses: "actions/github-app-token@v1" + with: + app-id: "${{ secrets.APP_ID }}" + owner: "${{ github.repository_owner }}" + private-key: "${{ secrets.APP_PRIVATE_KEY }}" + - id: "github_app_token" + name: "set github token" + run: | + if [[ "${USE_GITHUB_APP_TOKEN}" == "true" ]]; then + echo "token=${{ steps.get_github_app_token.outputs.token }}" >> $GITHUB_OUTPUT + else + echo "token=${{ secrets.GH_TOKEN }}" >> $GITHUB_OUTPUT + fi + - id: "version" + name: "get release version" + run: | + npm install + npm exec -- release-please release-pr \ + --consider-all-branches \ + --dry-run \ + --dry-run-output release.json \ + --group-pull-request-title-pattern "chore\${scope}: release\${component} \${version}" \ + --manifest-file .release-please-manifest.json \ + --pull-request-title-pattern "chore\${scope}: release\${component} \${version}" \ + --release-type simple \ + --repo-url "${{ env.RELEASE_REPO }}" \ + --separate-pull-requests false \ + --target-branch "${{ steps.extract_branch.outputs.branch }}" \ + --token "${{ steps.github_app_token.outputs.token }}" \ + --versioning-strategy "${{ env.VERSIONING_STRATEGY }}" + + cat release.json + + if [[ `jq length release.json` -gt 1 ]]; then + echo 'release-please would create more than 1 PR, so cannot determine correct version' + echo "pr_created=false" >> $GITHUB_OUTPUT + exit 1 + fi + + if [[ `jq length release.json` -eq 0 ]]; then + echo "pr_created=false" >> $GITHUB_OUTPUT + else + version="$(npm run --silent get-version)" + echo "Parsed version: ${version}" + echo "version=${version}" >> $GITHUB_OUTPUT + echo "pr_created=true" >> $GITHUB_OUTPUT + fi + working-directory: "lib" +name: "Test Create Release PR Action" +"on": + pull_request: {} + push: + branches: + - "release-[0-9]+.[0-9]+.x" +permissions: + contents: "write" + id-token: "write" + pull-requests: "write" diff --git a/actions/should-release/__tests__/release.test.ts b/actions/should-release/__tests__/release.test.ts index ef6ee046..41632b0e 100644 --- a/actions/should-release/__tests__/release.test.ts +++ b/actions/should-release/__tests__/release.test.ts @@ -1,9 +1,10 @@ -import { createSandbox, SinonStub } from 'sinon' +import * as sinon from 'sinon' +import { createSandbox } from 'sinon' import { isLatestVersion, shouldRelease } from '../src/release' import * as github from '../src/github' -import { GitHub } from 'release-please/build/src/github' +import { GitHub, GitHubTag } from 'release-please/build/src/github' import { PullRequestBody } from 'release-please/build/src/util/pull-request-body' import { PullRequestTitle } from 'release-please/build/src/util/pull-request-title' import { Version } from 'release-please/build/src/version' @@ -13,14 +14,15 @@ import { parseConventionalCommits } from 'release-please/build/src/commit' const sandbox = createSandbox() -let findMergedReleasePullRequests: SinonStub +let findMergedReleasePullRequests: sinon.SinonStub +let tagIterator: sinon.SinonStub let fakeGitHub: GitHub let defaultPRNotes: string let defaultPRTitle: string const defaultNextVersion = Version.parse('1.3.2') -const footer = +const defaultFooter = 'Merging this PR will release the [artifacts](https://loki-build-artifacts.storage.googleapis.com/def456) of def456' const prTitlePattern = 'chore${scope}: release${component} ${version}' @@ -74,6 +76,7 @@ describe('release', () => { github, 'findMergedReleasePullRequests' ) + tagIterator = sandbox.stub(github, 'getAllTags') defaultPRNotes = await new DefaultChangelogNotes().buildNotes(commits, { owner: 'fake-owner', repository: 'fake-repo', @@ -91,8 +94,16 @@ describe('release', () => { sandbox.restore() }) - describe('prepareRelease', () => { - it('creates a release for each merged release PR', async () => { + describe('shouldRelease', () => { + const setup = ( + footer = defaultFooter, + tags = { + 'v1.3.1': { + name: 'v1.3.1', + sha: 'abs123' + } as GitHubTag + } + ): void => { findMergedReleasePullRequests.resolves([ { headBranchName: `release-please--branches--release-1.3.x`, @@ -116,34 +127,19 @@ describe('release', () => { } ]) + tagIterator.resolves(tags) + } + + it('creates a release for each merged release PR', async () => { + setup() + const release = await shouldRelease('main', prTitlePattern) 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: [] - } - ]) + setup() const release = await shouldRelease('main', prTitlePattern) expect(release).toBeDefined() @@ -151,32 +147,41 @@ describe('release', () => { }) 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: [] - } - ]) + setup('not a valid footer') const release = await shouldRelease('main', prTitlePattern) expect(release).not.toBeDefined() }) + + it('determines if the release is the latest version', async () => { + const tags = { + 'v1.3.1': { + name: 'v1.3.1', + sha: 'abs123' + } as GitHubTag + } + setup(defaultFooter, tags) + + const release = await shouldRelease('main', prTitlePattern) + expect(release?.isLatest).toEqual(true) + }) + + it('determines if the release is not the latest version', async () => { + const tags = { + 'v1.3.1': { + name: 'v1.3.1', + sha: 'abs123' + } as GitHubTag, + 'v1.4.1': { + name: 'v1.4.1', + sha: 'def456' + } as GitHubTag + } + setup(defaultFooter, tags) + + const release = await shouldRelease('main', prTitlePattern) + expect(release?.isLatest).toEqual(false) + }) }) describe('isLastestVersion', () => { diff --git a/actions/should-release/dist/index.js b/actions/should-release/dist/index.js index ec16daf3..dfef3e71 100644 --- a/actions/should-release/dist/index.js +++ b/actions/should-release/dist/index.js @@ -61922,6 +61922,13 @@ class PHPYoshi extends base_1.BaseStrategy { version, }), }); + updates.push({ + path: this.addPath(`${directory}/composer.json`), + createIfMissing: false, + updater: new root_composer_update_packages_1.RootComposerUpdatePackages({ + version, + }), + }); if ((_c = (_b = componentInfo.composer.extra) === null || _b === void 0 ? void 0 : _b.component) === null || _c === void 0 ? void 0 : _c.entry) { updates.push({ path: this.addPath(`${directory}/${componentInfo.composer.extra.component.entry}`), @@ -62060,7 +62067,6 @@ class PHP extends base_1.BaseStrategy { const updates = []; const version = options.newVersion; const versionsMap = new Map(); - versionsMap.set('version', version); updates.push({ path: this.addPath(this.changelogPath), createIfMissing: true, @@ -64732,11 +64738,17 @@ class RootComposerUpdatePackages extends default_1.DefaultUpdater { * @returns {string} The updated content */ updateContent(content, logger = logger_1.logger) { - if (!this.versionsMap || this.versionsMap.size === 0) { + if (!this.version && (!this.versionsMap || this.versionsMap.size === 0)) { logger.info('no updates necessary'); return content; } const parsed = JSON.parse(content); + if (parsed['version']) { + const fromVersion = parsed['version']; + const toVersion = this.version.toString() || '1.0.0'; + parsed['version'] = toVersion; + logger.info(`updating "version" from ${fromVersion} to ${toVersion}`); + } if (this.versionsMap) { for (const [key, version] of this.versionsMap.entries()) { const toVersion = version.toString() || '1.0.0'; @@ -117665,7 +117677,7 @@ module.exports = {}; /***/ ((module) => { "use strict"; -module.exports = {"i8":"16.7.0"}; +module.exports = {"i8":"16.9.0"}; /***/ }), diff --git a/package-lock.json b/package-lock.json index 7031c6c6..2175ef92 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "@actions/tool-cache": "^2.0.1", "chalk": "^4.0.0", "figures": "^3.0.0", - "release-please": "trevorwhitney/release-please#dry-run-output" + "release-please": "grafana/release-please" }, "devDependencies": { "@commitlint/cli": "^17.6.3", @@ -8622,8 +8622,8 @@ } }, "node_modules/release-please": { - "version": "16.7.0", - "resolved": "git+ssh://git@github.com/trevorwhitney/release-please.git#4c2c2259676e66b0f9cb449f8b91e9c6db670fdd", + "version": "16.9.0", + "resolved": "git+ssh://git@github.com/grafana/release-please.git#c70ff8a829adba3cd3e6dd42104d165920868204", "license": "Apache-2.0", "dependencies": { "@conventional-commits/parser": "^0.4.1", diff --git a/package.json b/package.json index 89e21db8..2d190dfe 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,7 @@ "@actions/tool-cache": "^2.0.1", "chalk": "^4.0.0", "figures": "^3.0.0", - "release-please": "trevorwhitney/release-please#dry-run-output" + "release-please": "grafana/release-please" }, "devDependencies": { "@commitlint/cli": "^17.6.3", diff --git a/workflows/build.libsonnet b/workflows/build.libsonnet index b2adca4d..aea4d657 100644 --- a/workflows/build.libsonnet +++ b/workflows/build.libsonnet @@ -59,7 +59,7 @@ local releaseLibStep = common.releaseLibStep; + step.withIf('${{ fromJSON(needs.version.outputs.pr_created) }}') + step.with({ path: 'release/images/%s-${{ needs.version.outputs.version}}-${{ steps.platform.outputs.platform }}.tar' % name, - destination: 'loki-build-artifacts/${{ github.sha }}/images', //TODO: make bucket configurable + destination: '${{ env.BUILD_ARTIFACTS_BUCKET }}/${{ github.sha }}/images', //TODO: make bucket configurable process_gcloudignore: false, }), ]), @@ -169,7 +169,7 @@ local releaseLibStep = common.releaseLibStep; + step.withIf('${{ fromJSON(needs.version.outputs.pr_created) }}') + step.with({ path: 'release/dist', - destination: 'loki-build-artifacts/${{ github.sha }}', //TODO: make bucket configurable + destination: '${{ env.BUILD_ARTIFACTS_BUCKET }}/${{ github.sha }}', //TODO: make bucket configurable process_gcloudignore: false, }), ]), diff --git a/workflows/main.jsonnet b/workflows/main.jsonnet index a53d541a..fb401d31 100644 --- a/workflows/main.jsonnet +++ b/workflows/main.jsonnet @@ -8,10 +8,12 @@ validateGel: import 'validate-gel.libsonnet', releasePRWorkflow: function( branches=['release-[0-9]+.[0-9]+.x', 'k[0-9]+'], + buildArtifactsBucket='loki-build-artifacts', buildImage='grafana/loki-build-image:0.33.0', changelogPath='CHANGELOG.md', checkTemplate='./.github/workflows/check.yml', distMakeTargets=['dist', 'packages'], + dryRun=false, dockerUsername='grafana', golangCiLintVersion='v1.55.1', imageBuildTimeoutMin=25, @@ -40,9 +42,11 @@ group: 'create-release-pr-${{ github.sha }}', }, env: { + BUILD_ARTIFACTS_BUCKET: buildArtifactsBucket, BUILD_TIMEOUT: imageBuildTimeoutMin, CHANGELOG_PATH: changelogPath, DOCKER_USERNAME: dockerUsername, + DRY_RUN: dryRun, IMAGE_PREFIX: imagePrefix, RELEASE_LIB_REF: releaseLibRef, RELEASE_REPO: releaseRepo, @@ -72,6 +76,7 @@ }, releaseWorkflow: function( branches=['release-[0-9].[0-9].x', 'k[0-9]*'], + buildArtifactsBucket='loki-build-artifacts', dockerUsername='grafanabot', getDockerCredsFromVault=false, imagePrefix='grafana', @@ -96,6 +101,7 @@ group: 'create-release-${{ github.sha }}', }, env: { + BUILD_ARTIFACTS_BUCKET: buildArtifactsBucket, IMAGE_PREFIX: imagePrefix, RELEASE_LIB_REF: releaseLibRef, RELEASE_REPO: releaseRepo, diff --git a/workflows/release.libsonnet b/workflows/release.libsonnet index 96edd7f4..dc9978b2 100644 --- a/workflows/release.libsonnet +++ b/workflows/release.libsonnet @@ -9,7 +9,7 @@ local releaseLibStep = common.releaseLibStep; // 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}'; +local pullRequestFooter = 'Merging this PR will release the [artifacts](https://console.cloud.google.com/storage/browser/${BUILD_ARTIFACTS_BUCKET}/${SHA}) of ${SHA}'; { createReleasePR: @@ -45,7 +45,8 @@ local pullRequestFooter = 'Merging this PR will release the [artifacts](https:// --separate-pull-requests false \ --target-branch "${{ steps.extract_branch.outputs.branch }}" \ --token "${{ steps.github_app_token.outputs.token }}" \ - --versioning-strategy "${{ env.VERSIONING_STRATEGY }}" + --versioning-strategy "${{ env.VERSIONING_STRATEGY }}" \ + --dry-run ${{ fromJSON(env.DRY_RUN) }} ||| % pullRequestFooter), ]), @@ -89,7 +90,7 @@ local pullRequestFooter = 'Merging this PR will release the [artifacts](https:// releaseStep('download binaries') + step.withRun(||| echo "downloading binaries to $(pwd)/dist" - gsutil cp -r gs://loki-build-artifacts/${{ needs.shouldRelease.outputs.sha }}/dist . + gsutil cp -r gs://${BUILD_ARTIFACTS_BUCKET}/${{ needs.shouldRelease.outputs.sha }}/dist . |||), releaseStep('check if release exists') diff --git a/workflows/workflows.jsonnet b/workflows/workflows.jsonnet index 917c8a75..1992d23f 100644 --- a/workflows/workflows.jsonnet +++ b/workflows/workflows.jsonnet @@ -6,23 +6,52 @@ local build = lokiRelease.build; imageJobs={ loki: build.image('fake-loki', 'cmd/loki'), }, + buildArtifactsBucket='loki-build-artifacts', branches=['release-[0-9]+.[0-9]+.x'], imagePrefix='trevorwhitney075', releaseLibRef='release-1.12.x', releaseRepo='grafana/loki-release', skipValidation=false, versioningStrategy='always-bump-patch', - ), false, false + ) + { + name: 'Create Release PR', + }, false, false + ), + '.github/workflows/test-release-pr.yml': std.manifestYamlDoc( + lokiRelease.releasePRWorkflow( + imageJobs={ + loki: build.image('fake-loki', 'cmd/loki'), + }, + buildArtifactsBucket='loki-build-artifacts', + branches=['release-[0-9]+.[0-9]+.x'], + dryRun=true, + imagePrefix='trevorwhitney075', + releaseLibRef='release-1.12.x', + releaseRepo='grafana/loki-release', + skipValidation=false, + versioningStrategy='always-bump-patch', + ) + { + name: 'Test Create Release PR Action', + on+: { + pull_request: {}, + }, + }, false, false ), '.github/workflows/release.yml': std.manifestYamlDoc( lokiRelease.releaseWorkflow( branches=['release-[0-9]+.[0-9]+.x'], + buildArtifactsBucket='loki-build-artifacts', getDockerCredsFromVault=true, imagePrefix='trevorwhitney075', releaseLibRef='release-1.12.x', releaseRepo='grafana/loki-release', useGitHubAppToken=false, - ), false, false + ) + { + name: 'Create Release', + on+: { + pull_request: {}, + }, + }, false, false ), '.github/workflows/check.yml': std.manifestYamlDoc( lokiRelease.check