Tag and Release #69
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Tag and Release | |
on: | |
workflow_dispatch: | |
inputs: | |
tag: | |
description: "current tag: The tag for this release" | |
required: true | |
default: v0.1.0-rc.2 | |
prev_tag: | |
description: "previous tag: Tag from which to start calculating the changelog" | |
required: true | |
default: v0.1.0-beta.0 | |
commit_ref: | |
description: "commit ref: The branch, tag or SHA of the commit to use for the release." | |
required: false | |
default: main | |
defaults: | |
run: | |
shell: bash | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
ref: ${{ github.event.inputs.commit_ref }} | |
- uses: actions/setup-node@v2-beta | |
with: | |
node-version: "16.16.0" | |
- run: corepack enable | |
- run: make install | |
- run: make build | |
- if: failure() | |
uses: rtCamp/action-slack-notify@v2 | |
env: | |
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} | |
SLACK_COLOR: "#BD3232" | |
SLACK_ICON: https://github.com/actions.png?size=48 | |
SLACK_MESSAGE: "Build and test failed for move2kube-ui on tag ${{ github.event.inputs.tag }}" | |
SLACK_TITLE: Failed | |
SLACK_USERNAME: GitHubActions | |
tag: | |
needs: [build] | |
name: Tag | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
ref: ${{ github.event.inputs.commit_ref }} | |
- id: get_sha | |
run: | | |
echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT | |
- uses: actions/github-script@v3 | |
with: | |
github-token: ${{ secrets.MOVE2KUBE_PATOKEN }} | |
script: | | |
const tag = '${{ github.event.inputs.tag }}'; | |
const sha = '${{ steps.get_sha.outputs.sha }}'; | |
let tag_exists = false; | |
try { | |
const resp = await github.git.getRef({...context.repo, ref: `tags/${tag}`}); | |
tag_exists = true; | |
core.info(`the tag ${tag} already exists on ${resp.data.object.type} ${resp.data.object.sha}`); | |
} catch(err) { | |
if(err.status !== 404){ | |
throw err; | |
} | |
} | |
if(tag_exists) { | |
core.info(`deleting the tag ${tag}`); | |
const resp = await github.git.deleteRef({...context.repo, ref: `tags/${tag}`}); | |
} | |
core.info(`creating the tag ${tag} on the commit ${sha}`); | |
// create the tag | |
github.git.createRef({ | |
...context.repo, | |
ref: `refs/tags/${tag}`, | |
sha | |
}); | |
if(!tag.endsWith('-beta.0')) { | |
return; | |
} | |
// create the release branch | |
const major_minor = /^v(\d+\.\d+)/.exec(tag); | |
if(!major_minor || major_minor.length !== 2){ | |
return core.setFailed(`The tag is not a valid semantic version. tag: ${tag}`); | |
} | |
const branch_name = `release-${major_minor[1]}`; | |
github.git.createRef({ | |
...context.repo, | |
ref: `refs/heads/${branch_name}`, | |
sha | |
}); | |
create_release_draft: | |
needs: [tag] | |
name: Create release draft | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
ref: ${{ github.event.inputs.commit_ref }} | |
fetch-depth: 0 | |
- name: create release draft | |
uses: konveyor/create-release-draft@v1 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
tag: ${{ github.event.inputs.tag }} | |
prev_tag: ${{ github.event.inputs.prev_tag }} | |
config: releasenotes-config.js | |
- uses: azure/setup-helm@v1 | |
- run: IMAGE_TAG='${{ github.event.inputs.tag }}' make prepare-for-release | |
- run: helm package helm-charts/move2kube | |
- run: mkdir temp/ | |
- run: mv *.tgz temp/ | |
- run: curl -L -o oldindex.yaml https://move2kube.konveyor.io/index.yaml | |
- run: helm repo index --merge oldindex.yaml --url https://github.com/konveyor/move2kube-ui/releases/download/${{ github.event.inputs.tag }} temp/ | |
- uses: konveyor/upload-release-action@v3 | |
with: | |
repo_token: ${{ secrets.GITHUB_TOKEN }} | |
tag: ${{ github.event.inputs.tag }} | |
file: temp/* | |
file_glob: true | |
overwrite: true | |
- name: slack notification | |
uses: rtCamp/action-slack-notify@v2 | |
env: | |
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} | |
SLACK_ICON: https://github.com/actions.png?size=48 | |
SLACK_MESSAGE: "Release draft for move2kube-ui ${{ github.event.inputs.tag }} created: https://github.com/konveyor/move2kube-ui/releases" | |
SLACK_TITLE: Success | |
SLACK_USERNAME: GitHubActions | |
image_build: | |
needs: [tag] | |
name: Image build | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
ref: ${{ github.event.inputs.commit_ref }} | |
- name: pull latest image to reuse layers | |
run: | | |
docker pull quay.io/konveyor/move2kube-ui:latest || true | |
docker pull quay.io/konveyor/move2kube-ui-builder:latest || true | |
- run: echo "${{ secrets.QUAY_BOT_PASSWORD }}" | docker login --username "${{ secrets.QUAY_BOT_USERNAME }}" --password-stdin quay.io | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
id: buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: build container image | |
run: VERSION='${{ github.event.inputs.tag }}' make cmultibuildpush | |
# build the operator bundle and container images | |
- name: install-yq | |
run: | | |
echo "installing yq..." | |
curl -L https://github.com/mikefarah/yq/releases/download/v4.13.5/yq_linux_amd64 -o /usr/local/bin/yq && chmod +x /usr/local/bin/yq | |
echo "yq installed" | |
- id: get_channel | |
uses: actions/github-script@v6 | |
with: | |
result-encoding: string | |
script: | | |
const version = '${{ github.event.inputs.tag }}'; | |
return /^v\d+\.\d+\.\d+-\w+/.test(version) ? 'prerelease' : 'stable'; | |
- name: build the operator bundle and container images and push the images to quay | |
run: | | |
cd operator/ || exit 1 | |
VERSION='${{ github.event.inputs.tag }}' make docker-build | |
VERSION='${{ github.event.inputs.tag }}' make docker-push | |
VERSION='${{ github.event.inputs.tag }}' CHANNELS='${{ steps.get_channel.outputs.result }}' DEFAULT_CHANNEL='stable' make bundle | |
VERSION='${{ github.event.inputs.tag }}' make bundle-build | |
VERSION='${{ github.event.inputs.tag }}' make bundle-push | |
# build the operator bundle and container images | |
- name: success slack notification | |
uses: rtCamp/action-slack-notify@v2 | |
env: | |
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} | |
SLACK_ICON: https://github.com/actions.png?size=48 | |
SLACK_MESSAGE: "Built and pushed quay.io/konveyor/move2kube-ui:${{ github.event.inputs.tag }}" | |
SLACK_TITLE: Success | |
SLACK_USERNAME: GitHubActions | |
- if: failure() | |
name: failure slack notification | |
uses: rtCamp/action-slack-notify@v2 | |
env: | |
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} | |
SLACK_COLOR: "#BD3232" | |
SLACK_ICON: https://github.com/actions.png?size=48 | |
SLACK_MESSAGE: "Failed to build and push image quay.io/konveyor/move2kube-ui:${{ github.event.inputs.tag }}" | |
SLACK_TITLE: Failed | |
SLACK_USERNAME: GitHubActions | |
update_draft_title: | |
needs: [create_release_draft, image_build] | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/github-script@v3 | |
with: | |
github-token: ${{ secrets.MOVE2KUBE_PATOKEN }} | |
script: | | |
const tag = '${{ github.event.inputs.tag }}'; | |
const response = await github.repos.listReleases({ ...context.repo }); | |
const drafts = response.data.filter(release => release.draft && release.tag_name === tag); | |
if(drafts.length !== 1) { | |
return core.setFailed(`Expected to find exactly one draft release with the tag ${tag}. Found: ${drafts.length}`); | |
} | |
const draft = drafts[0]; | |
if(!draft.name.startsWith('[WIP] ')) { | |
return core.setFailed(`Expected the draft name to begin with [WIP]. Found: ${draft.name}`); | |
} | |
const new_name = draft.name.replace(/^\[WIP\] /, ''); | |
await github.repos.updateRelease({...context.repo, release_id: draft.id, name: new_name, tag_name: draft.tag_name}); |