Tag and Release #86
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 | |
jobs: | |
build_and_test: | |
name: Build and test | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
ref: ${{ github.event.inputs.commit_ref }} | |
- id: info | |
uses: konveyor/move2kube-get-env-info@v1 | |
- uses: actions/setup-go@v2 | |
with: | |
go-version: ${{ steps.info.outputs.go_version }} | |
- run: IN_CICD=true make ci | |
- run: make test-coverage | |
- name: upload coverage | |
uses: codecov/codecov-action@v1 | |
- 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 on branch ${{ github.event.inputs.commit_ref }}" | |
SLACK_TITLE: Failed | |
SLACK_USERNAME: GitHubActions | |
run_move2kube_tests: | |
needs: [build_and_test] | |
name: Run move2kube tests | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
ref: ${{ github.event.inputs.commit_ref }} | |
- id: info | |
uses: konveyor/move2kube-get-env-info@v1 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
id: buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: pull latest image to reuse layers | |
run: | | |
docker pull quay.io/konveyor/move2kube:latest || true | |
docker pull quay.io/konveyor/move2kube-builder:latest || true | |
- run: echo "${{ secrets.QUAY_BOT_PASSWORD }}" | docker login --username "${{ secrets.QUAY_BOT_USERNAME }}" --password-stdin quay.io | |
- name: build temporary image | |
run: VERSION='${{ github.run_id }}' GO_VERSION='${{ steps.info.outputs.go_version }}' make cmultibuildpush | |
- name: run tests in move2kube-tests | |
uses: felixp8/[email protected] | |
with: | |
owner: konveyor | |
repo: move2kube-tests | |
token: ${{ secrets.MOVE2KUBE_PATOKEN }} | |
event_type: cli_build | |
client_payload: '{"tag": "${{ github.run_id }}", "commit_ref": "${{ github.event.inputs.commit_ref }}"}' | |
wait_time: 5 | |
max_time: 1200 | |
- if: failure() | |
name: delete temporary image from quay | |
run: skopeo delete docker://quay.io/konveyor/move2kube:${{ github.run_id }} | |
- 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: "Tests on move2kube-tests failed for move2kube on tag ${{ github.event.inputs.tag }}" | |
SLACK_TITLE: Failed | |
SLACK_USERNAME: GitHubActions | |
tag: | |
needs: [run_move2kube_tests] | |
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: | | |
core.info('DEBUG 1 start'); | |
const tag = '${{ github.event.inputs.tag }}'; | |
const sha = '${{ steps.get_sha.outputs.sha }}'; | |
core.info(`DEBUG 2 tag ${tag} sha ${sha}`); | |
let tag_exists = false; | |
try { | |
core.info('DEBUG 3 try checking if the tag exists'); | |
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) { | |
core.info('DEBUG 4 an error occurred while checking if the tag exists'); | |
core.info(`DEBUG 5 err.status: ${typeof(err.status)} ${err.status}`); | |
if(err.status !== 404 && err.status !== '404'){ | |
throw err; | |
} | |
core.info('DEBUG 6 the tag does not exist'); | |
} | |
core.info('DEBUG 7 after checking if the tag exists'); | |
if(tag_exists) { | |
core.info('DEBUG 8 the tag exists'); | |
core.info(`deleting the tag ${tag}`); | |
const resp = await github.git.deleteRef({...context.repo, ref: `tags/${tag}`}); | |
core.info('DEBUG 9 after deleting the existing tag'); | |
} | |
core.info('DEBUG 10'); | |
core.info(`creating the tag ${tag} on the commit ${sha}`); | |
github.git.createRef({ | |
...context.repo, | |
ref: `refs/tags/${tag}`, | |
sha | |
}); | |
core.info('DEBUG 11 after creating the tag'); | |
if(!tag.endsWith('-beta.0')) { | |
core.info('DEBUG 12 the tag does not end with -beta.0'); | |
return; | |
} | |
core.info('DEBUG 13 the tag ends with -beta.0 so create a new release branch'); | |
// 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}`); | |
} | |
core.info('DEBUG 14 creating the new release branch'); | |
const branch_name = `release-${major_minor[1]}`; | |
core.info(`New beta.0 release. Creating new branch for ${branch_name}`); | |
github.git.createRef({ | |
...context.repo, | |
ref: `refs/heads/${branch_name}`, | |
sha | |
}); | |
core.info('DEBUG 15 after creating the new release branch'); | |
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/move2kube-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 | |
- id: info | |
uses: konveyor/move2kube-get-env-info@v1 | |
- uses: actions/setup-go@v2 | |
with: | |
go-version: ${{ steps.info.outputs.go_version }} | |
- run: VERSION='${{ github.event.inputs.tag }}' make dist | |
- name: upload release assets | |
uses: konveyor/[email protected] | |
with: | |
repo_token: ${{ secrets.GITHUB_TOKEN }} | |
tag: ${{ github.event.inputs.tag }} | |
file: _dist/output/* | |
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 ${{ github.event.inputs.tag }} created: https://github.com/konveyor/move2kube/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 }} | |
- id: info | |
uses: konveyor/move2kube-get-env-info@v1 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
id: buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: pull latest image to reuse layers | |
run: | | |
docker pull quay.io/konveyor/move2kube:latest || true | |
docker pull quay.io/konveyor/move2kube-builder:latest || true | |
docker pull quay.io/konveyor/move2kube:${{ github.run_id }} | |
- run: echo "${{ secrets.QUAY_BOT_PASSWORD }}" | docker login --username "${{ secrets.QUAY_BOT_USERNAME }}" --password-stdin quay.io | |
- name: build container image | |
run: VERSION='${{ github.event.inputs.tag }}' GO_VERSION='${{ steps.info.outputs.go_version }}' make cmultibuildpush | |
- if: always() | |
name: delete temporary image from quay | |
run: skopeo delete docker://quay.io/konveyor/move2kube:${{ github.run_id }} | |
- 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:${{ 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:${{ github.event.inputs.tag }}" | |
SLACK_TITLE: Failed | |
SLACK_USERNAME: GitHubActions | |
trigger_other_repos: | |
needs: [image_build] | |
name: Trigger release in other repos | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/github-script@v3 | |
with: | |
github-token: ${{ secrets.MOVE2KUBE_PATOKEN }} | |
script: | | |
const create_release_workflow = 'release.yml'; | |
const repos = [ | |
"move2kube-api", | |
"move2kube-tests", | |
"move2kube-demos", | |
"move2kube-transformers", | |
]; | |
const promises = repos.map(repo => github.actions.createWorkflowDispatch({ | |
owner: context.repo.owner, | |
repo, | |
workflow_id: create_release_workflow, | |
ref: context.ref, | |
inputs: context.payload.inputs, | |
})); | |
await Promise.all(promises); | |
update_draft_title: | |
needs: [create_release_draft, trigger_other_repos] | |
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}); |