From d63158786f639ef45fcc05cbf6391a388317cc50 Mon Sep 17 00:00:00 2001 From: Luiz Aoqui Date: Wed, 27 Apr 2022 20:14:23 -0400 Subject: [PATCH] ci: setup release process with CRT (#12781) --- .github/workflows/build-trigger.yml | 13 ++ .github/workflows/build.yml | 37 ++++-- .github/workflows/generate-static-assets.yml | 68 ---------- .github/workflows/release.yml | 126 +++++++++++++++++++ .release/ci.hcl | 12 +- 5 files changed, 178 insertions(+), 78 deletions(-) create mode 100644 .github/workflows/build-trigger.yml delete mode 100644 .github/workflows/generate-static-assets.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/build-trigger.yml b/.github/workflows/build-trigger.yml new file mode 100644 index 000000000..47dddfc98 --- /dev/null +++ b/.github/workflows/build-trigger.yml @@ -0,0 +1,13 @@ +name: Build trigger + +on: + push: + branches: + - "main" + workflow_dispatch: + +jobs: + build: + uses: ./.github/workflows/build.yml + with: + make-prerelease: true diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ae7077fa4..750dfdbe9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,10 +1,18 @@ name: build on: - push: - branches: - - "main" workflow_dispatch: + inputs: + build-ref: + description: 'The git ref to build from' + type: string + default: '' + required: false + make-prerelease: + description: "Run prerelease to generate files" + type: "boolean" + required: false + default: true env: PKG_NAME: "nomad" @@ -17,6 +25,8 @@ jobs: go-version: ${{ steps.get-go-version.outputs.go-version }} steps: - uses: actions/checkout@v2 + with: + ref: ${{ github.event.inputs.build-ref }} - name: Determine Go version id: get-go-version # We use .go-version as our source of truth for current Go @@ -30,6 +40,8 @@ jobs: product-version: ${{ steps.get-product-version.outputs.product-version }} steps: - uses: actions/checkout@v2 + with: + ref: ${{ github.event.inputs.build-ref }} - name: get product version id: get-product-version run: | @@ -43,13 +55,16 @@ jobs: steps: - name: "Checkout directory" uses: actions/checkout@v2 + with: + ref: ${{ github.event.inputs.build-ref }} - name: Generate metadata file id: generate-metadata-file - uses: hashicorp/actions-generate-metadata@v1 + uses: hashicorp/actions-generate-metadata@add-optional-sha-param with: version: ${{ needs.get-product-version.outputs.product-version }} product: ${{ env.PKG_NAME }} repositoryOwner: "hashicorp" + sha: ${{ github.event.inputs.build-ref }} - uses: actions/upload-artifact@v2 with: name: metadata.json @@ -61,6 +76,8 @@ jobs: ldflags: ${{ steps.generate-ld-flags.outputs.ldflags }} steps: - uses: actions/checkout@v2 + with: + ref: ${{ github.event.inputs.build-ref }} - name: "Generate ld flags" id: generate-ld-flags run: | @@ -82,6 +99,8 @@ jobs: steps: - uses: actions/checkout@v2 + with: + ref: ${{ github.event.inputs.build-ref }} - name: Setup go uses: actions/setup-go@v2 with: @@ -102,7 +121,7 @@ jobs: - name: Build prerelease run: make prerelease - if: ${{ github.event_name != 'workflow_dispatch' }} + if: ${{ github.event.inputs.make-prerelease == 'true' }} - name: Build env: @@ -132,6 +151,8 @@ jobs: steps: - uses: actions/checkout@v2 + with: + ref: ${{ github.event.inputs.build-ref }} - name: Setup go uses: actions/setup-go@v2 with: @@ -152,7 +173,7 @@ jobs: - name: Build prerelease run: make prerelease - if: ${{ github.event_name != 'workflow_dispatch' }} + if: ${{ github.event.inputs.make-prerelease == 'true' }} - name: Install Linux build utilties run: | @@ -239,6 +260,8 @@ jobs: steps: - uses: actions/checkout@v2 + with: + ref: ${{ github.event.inputs.build-ref }} - name: Setup go uses: actions/setup-go@v2 @@ -260,7 +283,7 @@ jobs: - name: Build prerelease run: make prerelease - if: ${{ github.event_name != 'workflow_dispatch' }} + if: ${{ github.event.inputs.make-prerelease == 'true' }} - name: Build env: diff --git a/.github/workflows/generate-static-assets.yml b/.github/workflows/generate-static-assets.yml deleted file mode 100644 index 4bedd7b7b..000000000 --- a/.github/workflows/generate-static-assets.yml +++ /dev/null @@ -1,68 +0,0 @@ -name: Generate Static Assets - -on: - push: - branches: - - "release/**" -env: - GO_TAGS: "release" - -jobs: - get-go-version: - runs-on: ubuntu-latest - outputs: - go-version: ${{ steps.get-go-version.outputs.go-version }} - steps: - - uses: actions/checkout@v2 - - name: Determine Go version - id: get-go-version - # We use .go-version as our source of truth for current Go - # version, because "goenv" can react to it automatically. - run: | - echo "Building with Go $(cat .go-version)" - echo "::set-output name=go-version::$(cat .go-version)" - generate-metadata: - runs-on: ubuntu-latest - needs: get-go-version - name: generate-metadata - steps: - - uses: actions/checkout@v2 - - name: Setup go - uses: actions/setup-go@v2 - with: - go-version: ${{ needs.get-go-version.outputs.go-version }} - - - name: Setup node and yarn - uses: actions/setup-node@v2 - with: - node-version: "14" - cache-dependency-path: "ui/yarn.lock" - - name: Install Yarn - run: | - npm install -g yarn - - uses: actions/checkout@v2 - - name: Generate static assets - id: generate-static-assets - run: | - make deps - make prerelease - - name: Commit and push changes - id: commit-change-push - run: | - git add -A . - find . -name '*.generated.go' -not -path './vendor/*' -exec git add -f '{}' \; - if ! git diff-index --quiet HEAD --; - then - git config --global user.email "github-team-nomad-core@hashicorp.com" - git config --global user.name "hc-github-team-nomad-core" - git commit --message "Generate files for release" - git push origin "$(git rev-parse --abbrev-ref HEAD)" - echo "committing generated files" - else - echo "no files were updated" - fi - - name: Invoke build workflow - uses: benc-uk/workflow-dispatch@4c044c1613fabbe5250deadc65452d54c4ad4fc7 - with: - workflow: build - token: ${{ secrets.ELEVATED_GITHUB_TOKEN}} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..b65bb5b1f --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,126 @@ +name: Release + +on: + workflow_dispatch: + inputs: + version: + description: 'The version being released' + required: true + type: string + update-changelog: + description: 'Update CHANGELOG' + required: true + type: boolean + default: true + notification-channel: + description: 'Slack channel to use for notifications' + required: false + type: string + default: 'CUYKT2A73' + +env: + GO_TAGS: "release" + +jobs: + get-go-version: + runs-on: ubuntu-latest + outputs: + go-version: ${{ steps.get-go-version.outputs.go-version }} + steps: + - uses: actions/checkout@v2 + - name: Determine Go version + id: get-go-version + # We use .go-version as our source of truth for current Go + # version, because "goenv" can react to it automatically. + run: | + echo "Building with Go $(cat .go-version)" + echo "::set-output name=go-version::$(cat .go-version)" + + prepare-release: + needs: get-go-version + runs-on: ubuntu-latest + outputs: + build-ref: ${{ steps.commit-change-push.outputs.build-ref }} + steps: + - uses: actions/checkout@v2 + + - name: Setup go + uses: actions/setup-go@v2 + with: + go-version: ${{ needs.get-go-version.outputs.go-version }} + + - name: Setup node and yarn + uses: actions/setup-node@v2 + with: + node-version: "14" + cache-dependency-path: "ui/yarn.lock" + + - name: Install Yarn + run: | + npm install -g yarn + + - name: Install dependencies + run: | + make deps + + - name: Update notification channel + if: ${{ github.event.inputs.notification-channel != '' }} + run: | + sed -i.bak -e 's|\(notification_channel * = *"\)[^"]*|\1${{ github.event.inputs.notification-channel }}|g' .release/ci.hcl + rm -rf .release/ci.hcl.bak + git diff --color=always .release/ci.hcl + + - name: Update version file + run: | + NOMAD_VERSION="${{ github.event.inputs.version }}" + NOMAD_MAIN_VERSION=$(echo "$NOMAD_VERSION" | cut -d- -f1) + NOMAD_PRERELEASE_VERSION=$(echo "$NOMAD_VERSION" | sed 's|^[^-]*-\{0,1\}||g') + + echo "updating version to ${NOMAD_MAIN_VERSION}-${NOMAD_PRERELEASE_VERSION}" + + sed -i.bak -e "s|\(Version * = *\"\)[^\"]*|\1${NOMAD_MAIN_VERSION}|g" version/version.go + sed -i.bak -e "s|\(VersionPrerelease * = *\"\)[^\"]*|\1${NOMAD_PRERELEASE_VERSION}|g" version/version.go + rm -rf version/version.go.bak + git diff --color=always version/version.go + + - name: Update changelog + if: ${{ github.event.inputs.update-changelog == 'true' }} + run: | + echo "::group::Fetch all git repo" + git fetch --unshallow + echo "::endgroup::" + + echo -e "## ${{ github.event.inputs.version }} ($(date '+%B %d, %Y'))\n$(make changelog)\n\n$(cat CHANGELOG.md)" > CHANGELOG.md + git diff --color=always CHANGELOG.md + + - name: Generate static assets + id: generate-static-assets + run: | + make prerelease + + - name: Commit and push changes + id: commit-change-push + run: | + git add -A . + find . -name '*.generated.go' -not -path './vendor/*' -exec git add -f '{}' \; + if ! git diff-index --quiet HEAD --; + then + git config --global user.email "github-team-nomad-core@hashicorp.com" + git config --global user.name "hc-github-team-nomad-core" + git commit --message "Generate files for ${{ github.event.inputs.version }} release" + git push origin "$(git rev-parse --abbrev-ref HEAD)" + echo "committing generated files" + else + echo "no files were updated" + fi + echo "::set-output name=build-ref::$(git rev-parse HEAD)" + + - run: sleep 120 + + - name: Invoke build workflow + uses: benc-uk/workflow-dispatch@v1.1 + with: + workflow: build + token: ${{ secrets.ELEVATED_GITHUB_TOKEN}} + inputs: '{"build-ref": "${{ steps.commit-change-push.outputs.build-ref }}", "make-prerelease": "false"}' + ref: ${{ needs.prepare-release.outputs.build-ref }} diff --git a/.release/ci.hcl b/.release/ci.hcl index e5d7294ea..c9a62492a 100644 --- a/.release/ci.hcl +++ b/.release/ci.hcl @@ -9,9 +9,15 @@ project "nomad" { // notification_channel = "CUYKT2A73" } github { - organization = "hashicorp" - repository = "nomad" - release_branches = ["main"] + organization = "hashicorp" + repository = "nomad" + release_branches = [ + "main", + "release/1.0.x", + "release/1.1.x", + "release/1.2.x", + "release/1.3.x", + ] } }