2022-12-23 22:22:01 -05:00
---
name : Release
on :
release :
types : [ published]
workflow_dispatch :
inputs :
release_version :
description: 'version to release. Ex : v4.3.2'
required : true
default : 'v'
jobs :
release :
name : Release Images
runs-on : ubuntu-latest
permissions :
2023-07-03 15:01:58 -04:00
contents : write
2022-12-23 22:22:01 -05:00
deployments : write
issues : write
packages : write
strategy :
fail-fast : false
matrix :
images :
- prefix : slim-
environment : Release-SLIM
- prefix : ""
environment : Release
timeout-minutes : 60
steps :
- name : Setup Docker BuildX
2023-09-14 20:13:33 -04:00
uses : docker/setup-buildx-action@v3.0.0
2022-12-23 22:22:01 -05:00
- name : Login to GHCR
2023-09-21 02:56:49 -04:00
uses : docker/login-action@v3.0.0
2022-12-23 22:22:01 -05:00
with :
registry : ghcr.io
username : ${{ github.actor }}
password : ${{ secrets.GITHUB_TOKEN }}
- name : Retrieve Current Release Version
# shellcheck disable=SC2062
run : |
RELEASE_VERSION="${{ github.event.release.name }}"
if [ -z "${RELEASE_VERSION}" ]; then
echo "No release version found in environment, using input..."
RELEASE_VERSION="${{ github.event.inputs.release_version }}"
fi
# Check the RELEASE_VERSION again
if [ -z "${RELEASE_VERSION}" ]; then
echo "Error RELEASE_VERSION is empty. Exiting..."
exit 1
fi
if ! echo "${RELEASE_VERSION}" | grep -E -o "v[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+"; then
echo "Error: RELEASE_VERSION doesn't look like a semantic version: ${RELEASE_VERSION}"
exit 2
fi
2023-07-03 18:57:06 -04:00
SEMVER_VERSION=${RELEASE_VERSION#v}
SEMVER_MAJOR_VERSION=${SEMVER_VERSION%%.*}
SEMVER_MAJOR_VERSION_WITH_PREFIX=v${SEMVER_MAJOR_VERSION}
2023-07-03 19:57:45 -04:00
2022-12-23 22:22:01 -05:00
{
echo "RELEASE_VERSION=${RELEASE_VERSION}"
2023-07-03 18:57:06 -04:00
echo "SEMVER_VERSION=${SEMVER_VERSION}"
echo "SEMVER_MAJOR_VERSION=${SEMVER_MAJOR_VERSION}"
echo "SEMVER_MAJOR_VERSION_WITH_PREFIX=${SEMVER_MAJOR_VERSION_WITH_PREFIX}"
2022-12-23 22:22:01 -05:00
} >> "${GITHUB_ENV}"
- name : Start ${{ matrix.images.environment }} Deployment
2023-01-23 08:00:45 -05:00
uses : bobheadxi/deployments@v1.4.0
2022-12-23 22:22:01 -05:00
id : deployment
with :
step : start
token : ${{ secrets.GITHUB_TOKEN }}
env : ${{ matrix.images.environment }}
# We don't rebuild the image to avoid that the latest tag and the release tags don't point to what the release tag is pointing to.
# Instead, we pull the latest image and tag it.
2022-12-30 18:21:07 -05:00
- name : Retag and Push Images
2022-12-23 22:22:01 -05:00
uses : akhilerm/tag-push-action@v2.1.0
with :
2023-06-30 18:57:06 -04:00
src : ghcr.io/super-linter/super-linter:${{ matrix.images.prefix }}latest
2022-12-23 22:22:01 -05:00
dst : |
2023-07-03 19:57:45 -04:00
ghcr.io/super-linter/super-linter:${{ matrix.images.prefix }}${{ env.SEMVER_MAJOR_VERSION_WITH_PREFIX }}
2023-06-30 18:57:06 -04:00
ghcr.io/super-linter/super-linter:${{ matrix.images.prefix }}${{ env.RELEASE_VERSION }}
2022-12-23 22:22:01 -05:00
- name : Checkout Code
2023-09-11 19:17:22 -04:00
uses : actions/checkout@v4
2022-12-23 22:22:01 -05:00
with :
2023-10-16 14:34:31 -04:00
ref : main
2022-12-23 22:22:01 -05:00
# Full git history is needed to get a proper list of commits and tags
fetch-depth : 0
2023-10-16 12:24:34 -04:00
- name : Update action.yml
run : yq '.runs.image = "docker://ghcr.io/super-linter/super-linter:${{ env.RELEASE_VERSION }}"' -i action.yml
2023-10-15 00:40:57 -04:00
2023-10-16 12:24:34 -04:00
- name : Update slim/action.yml
run : yq '.runs.image = "docker://ghcr.io/super-linter/super-linter:slim-${{ env.RELEASE_VERSION }}"' -i slim/action.yml
2023-10-15 00:40:57 -04:00
2023-10-16 12:24:34 -04:00
- uses : EndBug/add-and-commit@v9 # You can change this to use a specific version.
with :
add : 'action.yml slim/action.yml'
default_author : github_actions
message : 'Automated update of action.yml and slim/action.yml version numbers'
2023-10-16 15:02:31 -04:00
push : origin main --force
2023-10-16 13:15:51 -04:00
2022-12-23 22:22:01 -05:00
# We use ^{} to recursively deference the tag to get the commit the tag is pointing at.
# Then, we use that reference to create new tags, so that the new tags point to the commit
# the original tag was pointing to, and not to the original tag.
# This notation is documented at https://git-scm.com/docs/gitrevisions#Documentation/gitrevisions.txt-emltrevgtemegemv0998em
- name : Update Major Version and Latest Git Tag
run : |
git tag --force "${SEMVER_MAJOR_VERSION_WITH_PREFIX}" "${RELEASE_VERSION}^{}"
git tag --force latest "${RELEASE_VERSION}^{}"
git push --force origin "refs/tags/${SEMVER_MAJOR_VERSION_WITH_PREFIX}" "refs/tags/latest"
- name : Update ${{ matrix.images.environment }} Deployment
2023-01-23 08:00:45 -05:00
uses : bobheadxi/deployments@v1.4.0
2022-12-23 22:22:01 -05:00
if : always()
with :
step : finish
token : ${{ secrets.GITHUB_TOKEN }}
status : ${{ job.status }}
deployment_id : ${{ steps.deployment.outputs.deployment_id }}
env : ${{ steps.deployment.outputs.env }}
2023-06-30 18:57:06 -04:00
env_url : https://github.com/super-linter/super-linter/releases/tag/${{ env.RELEASE_VERSION }}
2022-12-23 22:22:01 -05:00
- name : Create Issue on Failure
if : failure()
uses : actions/github-script@v6
with :
github-token : ${{secrets.GITHUB_TOKEN}}
script : |
const create = await github.rest.issues.create({
owner : context.repo.owner,
repo : context.repo.repo,
title : "Failed to deploy release to production" ,
2023-05-15 15:36:24 -04:00
body : "Automation has failed us! Failed to push release ${{ env.RELEASE_VERSION }}\nMore information can be found at:\n - ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" ,
2022-12-23 22:22:01 -05:00
assignees : [
2023-06-30 18:57:06 -04:00
'zkoppert' ,
'Hanse00'
2022-12-23 22:22:01 -05:00
]
})