chore(deps): bump actions/checkout from 2.4.0 to 4.0.0 #338
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: CI | |
on: | |
# always execute docker build when something is pushed to master or release-* branches | |
push: | |
branches: | |
- 'master' | |
- 'main' | |
- 'release-*' | |
# in addition, execute for pull requests to those branches | |
pull_request: | |
branches: | |
- 'master' | |
- 'main' | |
- 'release-*' | |
defaults: | |
run: | |
shell: bash | |
jobs: | |
prepare_ci_run: | |
name: Prepare CI Run | |
# Prepare CI Run looks at what has been changed in this commit/PR/... and determines which artifacts should be | |
# built afterwards (in other jobs that depend on this one). | |
runs-on: ubuntu-20.04 | |
outputs: # declare what this job outputs (so it can be re-used for other jobs) | |
# build config | |
# metadata | |
GIT_SHA: ${{ steps.extract_branch.outputs.GIT_SHA }} | |
BRANCH: ${{ steps.extract_branch.outputs.BRANCH }} | |
BRANCH_SLUG: ${{ steps.extract_branch.outputs.BRANCH_SLUG }} | |
VERSION: ${{ steps.get_version.outputs.VERSION }} | |
DATE: ${{ steps.get_datetime.outputs.DATE }} | |
TIME: ${{ steps.get_datetime.outputs.TIME }} | |
DATETIME: ${{ steps.get_datetime.outputs.DATETIME }} | |
steps: | |
- name: Check out code | |
uses: actions/[email protected] | |
with: | |
fetch-depth: 0 # need to checkout "all commits" for certain features to work (e.g., get all changed files) | |
- name: Load CI Environment from .ci_env | |
id: load_ci_env | |
uses: c-py/action-dotenv-to-setenv@v3 | |
with: | |
env-file: .ci_env | |
- name: Extract branch name | |
id: extract_branch | |
# see https://github.com/keptn/gh-action-extract-branch-name for details | |
uses: keptn/gh-action-extract-branch-name@main | |
- name: 'Get Previous tag' | |
id: get_previous_tag | |
uses: "WyriHaximus/[email protected]" | |
with: | |
fallback: "0.0.1" | |
- name: 'Get next patch version' | |
id: get_next_semver_tag | |
uses: "WyriHaximus/[email protected]" | |
with: | |
version: ${{ steps.get_previous_tag.outputs.tag }} | |
- name: Get the version | |
id: get_version | |
env: | |
BRANCH: ${{ steps.extract_branch.outputs.BRANCH }} | |
BRANCH_SLUG: ${{ steps.extract_branch.outputs.BRANCH_SLUG }} | |
shell: bash | |
run: | | |
# determine version | |
GIT_LAST_TAG=${{ steps.get_previous_tag.outputs.tag }} | |
GIT_NEXT_TAG=${{ steps.get_next_semver_tag.outputs.patch }} | |
echo "GIT_LAST_TAG=${GIT_LAST_TAG}, GIT_NEXT_TAG=${GIT_NEXT_TAG}" | |
if [[ "$BRANCH" == "release-"* ]]; then | |
# Release Branch: extract version from branch name | |
VERSION=${BRANCH#"release-"} | |
else | |
if [[ "$BRANCH" == "master" ]]; then | |
# master branch = latest | |
VERSION="${GIT_NEXT_TAG}-dev" | |
else | |
# Feature/Development Branch - use last tag with branch slug | |
VERSION="${GIT_NEXT_TAG}-dev-${BRANCH_SLUG}" | |
fi | |
fi | |
echo "VERSION=${VERSION}" | |
echo "##[set-output name=VERSION;]$(echo ${VERSION})" | |
- name: Get current date and time | |
id: get_datetime | |
run: | | |
echo "::set-output name=DATE::$(date +'%Y%m%d')" | |
echo "::set-output name=TIME::$(date +'%H%M')" | |
echo "::set-output name=DATETIME::$(date +'%Y%m%d')$(date +'%H%M')" | |
############################################################################ | |
# Unit tests # | |
############################################################################ | |
unit-tests: | |
name: Unit Tests | |
needs: prepare_ci_run | |
runs-on: ubuntu-20.04 | |
steps: | |
- name: Set up Go 1.x | |
uses: actions/setup-go@v2 | |
with: | |
go-version: ^1.16 | |
- name: Checkout Code | |
uses: actions/[email protected] | |
- name: Load CI Environment from .ci_env | |
id: load_ci_env | |
uses: c-py/action-dotenv-to-setenv@v3 | |
with: | |
env-file: .ci_env | |
- name: Test | |
run: go test -coverprofile=coverage.txt -covermode=atomic -v ./... | |
working-directory: . | |
############################################################################ | |
# Build Docker Image # | |
############################################################################ | |
docker_build: | |
needs: [prepare_ci_run] | |
name: Docker Build | |
runs-on: ubuntu-20.04 | |
env: | |
VERSION: ${{ needs.prepare_ci_run.outputs.VERSION }} | |
DATETIME: ${{ needs.prepare_ci_run.outputs.DATETIME }} | |
steps: | |
- name: Checkout Code | |
uses: actions/[email protected] | |
- name: Load CI Environment from .ci_env | |
id: load_ci_env | |
uses: c-py/action-dotenv-to-setenv@v3 | |
with: | |
env-file: .ci_env | |
- name: Docker Build | |
id: docker_build | |
uses: keptn/gh-automation/.github/actions/[email protected] | |
with: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
TAGS: | | |
ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE }}:${{ env.VERSION }} | |
BUILD_ARGS: | | |
version=${{ env.VERSION }} | |
PUSH: ${{(github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event.pull_request.head.repo.full_name == github.repository)}} | |
- id: report_docker_build_to_pr | |
name: Report Docker Build to PR | |
if: (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) | |
uses: marocchino/sticky-pull-request-comment@v2 | |
with: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
recreate: true | |
header: test | |
message: | | |
The following Docker Images have been built: | |
${{ fromJSON(steps.docker_build.outputs.BUILD_METADATA)['image.name'] }} |