ci: setup release process with CRT (#12781)

This commit is contained in:
Luiz Aoqui
2022-04-27 20:14:23 -04:00
committed by GitHub
parent de59d73009
commit d63158786f
5 changed files with 178 additions and 78 deletions

13
.github/workflows/build-trigger.yml vendored Normal file
View File

@@ -0,0 +1,13 @@
name: Build trigger
on:
push:
branches:
- "main"
workflow_dispatch:
jobs:
build:
uses: ./.github/workflows/build.yml
with:
make-prerelease: true

View File

@@ -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:

View File

@@ -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}}

126
.github/workflows/release.yml vendored Normal file
View File

@@ -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 }}

View File

@@ -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",
]
}
}