Skip to content

Bump actions/checkout from 3 to 4 #131

Bump actions/checkout from 3 to 4

Bump actions/checkout from 3 to 4 #131

name: "CI"
on:
push:
branches:
- master
- devel
pull_request:
env:
REGISTRY: ghcr.io
IMAGE_REPO: ghcr.io/masterofmalt/atom.devops.githubactions/
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
################################
# Run Linter against code base #
################################
- name: Lint Code Base
if: env.ACT != 'true'
uses: github/super-linter@v4
env:
VALIDATE_MARKDOWN: true
VALIDATE_YAML: true
VALIDATE_JAVASCRIPT_ES: true
VALIDATE_DOCKERFILE: true
VALIDATE_BASH: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
test_js:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: |
cd docker-build-from-cache
npm ci
npm run all
- name: Ensure the current dist is the same as the built one
if: env.ACT != 'true'
run: |
if ! git diff; then
echo "ERROR: Did you forget to commit something?"
exit 1
fi
test:
name: "Test"
runs-on: ubuntu-latest
needs: [lint, test_js]
steps:
- uses: actions/checkout@v4
id: checkout
- uses: ./Docker_Image_GetTag
id: get_tag
- name: Check Return Tag
run: |
if [ "${{ steps.get_tag.outputs.tag_name }}" == "" ]; then
exit 1
fi
- name: Login to registry
id: login
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: ./docker-build-from-cache
id: build_from_cache
with:
dockerfile: ./.github/Dockerfile
image_prefix: test_image_name
tag_name: ${{ steps.get_tag.outputs.tag_name }}
registry: ${{ env.IMAGE_REPO }}
additional_args: '--build-arg GREETING="Greetings" --build-arg ADDRESSEE="Github Actions"'
image_targets: "base, runner"
separator: "_"
- name: Check Cache Outputs
run: |
EXPECTED="${{ env.IMAGE_REPO }}test_image_name_base:${{ steps.get_tag.outputs.tag_name }} ${{ env.IMAGE_REPO }}test_image_name_runner:${{ steps.get_tag.outputs.tag_name }}"
if ! diff <(echo "${{ steps.build_from_cache.outputs.image_name_tags }}") <(echo $EXPECTED); then
exit 1
fi
- name: Verify arguments worked
run: |
# Verify that our docker image does what we meant it to
set -x
RESULT=$(docker run --rm "${IMAGE_REPO}test_image_name_runner:${{ steps.get_tag.outputs.tag_name }}")
if [ "${RESULT}" != "Greetings, Github Actions." ]; then
exit 1
fi
- name: verify we got the last image tag.
run: |
docker image inspect "${IMAGE_REPO}test_image_name:${{ steps.get_tag.outputs.tag_name }}"
- name: push_tagged_targets
run: |
# For this tests purpose we need to add the latest tag too. In the real world this
# is done during a devel merge by GetTag retrieving 'latest'
for target in base runner; do
docker tag \
"${IMAGE_REPO}test_image_name_${target}:${{ steps.get_tag.outputs.tag_name }}" \
"${IMAGE_REPO}test_image_name_${target}:latest"
docker push "${IMAGE_REPO}test_image_name_${target}:latest"
docker push "${IMAGE_REPO}test_image_name_${target}:${{ steps.get_tag.outputs.tag_name }}"
done
- name: verify a build from cache with no targets.
uses: ./docker-build-from-cache
id: build_from_cache_no_targets
with:
dockerfile: ./.github/Dockerfile
image_prefix: test_no_targets
tag_name: ${{ steps.get_tag.outputs.tag_name }}
registry: ${{ env.IMAGE_REPO }}
additional_args: '--build-arg GREETING="Greetings" --build-arg ADDRESSEE="Github Actions"'
image_targets: ""
- name: Check No target Cache Outputs
run: |
EXPECTED="${{ env.IMAGE_REPO }}test_no_targets:${{ steps.get_tag.outputs.tag_name }}"
if ! diff <(echo "${{ steps.build_from_cache_no_targets.outputs.image_name_tags }}") <(echo $EXPECTED); then
exit 1
fi
- uses: ./Docker_Image_Cache
id: nocache
with:
image_name: test_image_name
tag_name: NotATag
registry: ${{ env.IMAGE_REPO }}
- name: Check Cache Outputs
run: |
if [ "${{ steps.nocache.outputs.setting }}" != "--no-cache" ]; then
exit 1
fi
- uses: ./Docker_Image_Cache
id: cache
with:
image_name: ubuntu
tag_name: latest
registry: ""
- name: Check Cache Outputs
run: |
if [ "${{ steps.cache.outputs.setting }}" != "--no-cache" ]; then
exit 1
fi
- uses: ./Docker_Image_Build
id: build
with:
dockerfile: ./.github/Dockerfile
image_name: test_image_name
tag_name: ${{ steps.get_tag.outputs.tag_name }}
registry: ${{ env.IMAGE_REPO }}
github_token: ${{ secrets.GITHUB_TOKEN }}
cache_setting: ${{ steps.cache.outputs.setting }}
- name: Check Image Build
env:
check_value: ${{ env.IMAGE_REPO }}test_image_name:${{ steps.get_tag.outputs.tag_name }}
run: |
if [ "${{ steps.build.outputs.image_name_tag }}" != "${{ env.check_value }}" ]; then
exit 1
fi
- name: push
run: |
# For this tests purpose we need to add the latest tag too. In the real world this
# is done during a devel merge by GetTag retrieving 'latest'
docker tag \
"${IMAGE_REPO}test_image_name:${{ steps.get_tag.outputs.tag_name }}" \
"${IMAGE_REPO}test_image_name:latest"
docker push "${IMAGE_REPO}test_image_name:latest"
docker push "${IMAGE_REPO}test_image_name:${{ steps.get_tag.outputs.tag_name }}"
- uses: ./Docker_Image_SetTag
id: tag_image
with:
image_name: test_image_name
new_tag_name: ${{ steps.get_tag.outputs.tag_name }}
registry: ${{ env.IMAGE_REPO }}
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Check Image Tag
run: |
if ! docker images | \
grep "${IMAGE_REPO}test_image_name" | \
grep "${{ steps.get_tag.outputs.tag_name }}"; then
exit 1
fi
- name: Normalise tag to semantic-release
if: env.ACT != 'true'
uses: ./Git_Normalise_Tag
id: normalise_tag
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Check Git Tag
run: |
if [ "${{ steps.normalise_tag.outputs.new_git_tag }}" != "" ] &&
! git tag | grep "${{ steps.normalise_tag.outputs.new_git_tag }}"; then
exit 1
fi
promote:
if: github.ref == 'refs/heads/devel'
name: "Promote"
runs-on: ubuntu-latest
needs: [test]
steps:
- uses: actions/checkout@v4
- name: Merge to master
id: merge
if: env.ACT != 'true'
uses: devmasx/[email protected]
with:
type: now
from_branch: devel
target_branch: main
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Normalise tag to semantic-release
if: env.ACT != 'true'
uses: ./Git_Normalise_Tag
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Bump version and push tag
if: env.ACT != 'true'
id: version_bump
uses: mathieudutour/[email protected]
with:
release_branches: master,main,devel
tag_prefix: ''
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Create a GitHub release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.version_bump.outputs.new_tag }}
release_name: Release ${{ steps.version_bump.outputs.new_tag }}
body: ${{ steps.version_bump.outputs.changelog }}