Skip to content

Cpp update

Cpp update #465

Workflow file for this run

---
#
# https://docs.docker.com/build/ci/github-actions/
# https://github.com/docker/build-push-action
# https://docs.github.com/en/actions/creating-actions/creating-a-docker-container-action
#
name: Docker Build Workflow
on: # yamllint disable-line rule:truthy
schedule:
# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of the month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12 or JAN-DEC)
# │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT)
# │ │ │ │ │
# │ │ │ │ │
# │ │ │ │ │
# * * * * *
- cron: '15 8 1 * *'
workflow_dispatch:
pull_request:
env:
IMAGE_NAME: ci-generic-debian
defaults:
run:
shell: bash
jobs:
stage1:
name: Change Check
runs-on: 'ubuntu-latest'
outputs:
docs_changed: ${{ steps.check_file_changed.outputs.docs_changed }}
matrix_exercise: ${{ steps.check_file_changed.outputs.matrix_exercise }}
env:
re_change: '^(Dockerfile.*|.github/docker/.*|.github/workflows/docker-build.yml)$'
steps:
- name: Check GitHub Vars
id: github-vars
run: set | grep -e ^CI -e ^GITHUB_ -e ^RUNNER_
- name: Checkout Repo
id: checkout-repo
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.ref }}
submodules: recursive
- name: Get Change List
id: check_file_changed
run: |-
{
printf "Workflow: %s\n\n" "${GITHUB_WORKFLOW}"
printf "Runner: name[%s] arch[%s]\n" "${RUNNER_NAME}" "${RUNNER_ARCH}"
printf "Repo: %s\n" "${GITHUB_REPOSITORY}"
printf "User: %s\n" "${GITHUB_TRIGGERING_ACTOR}"
printf "\n"
} | tee -a "${GITHUB_STEP_SUMMARY}"
# Diff HEAD with the previous commit then output to stdout.
declare -a GIT_DIFF
mapfile -t GIT_DIFF < <(git diff --name-only HEAD^ HEAD | tee /tmp/changed_files.txt)
{
printf "=== Which files changed? ===\n"
printf "\n"
printf "\`\`\`text\n"
printf "%s\n" "${GIT_DIFF[@]}"
printf "\`\`\`\n"
printf "\n"
} | tee -a "${GITHUB_STEP_SUMMARY}"
# Get changed exercise list.
if [[ ${GITHUB_EVENT_NAME} != pull_request ]]; then
printf "Manual run, pretending we have a diff.\n"
HAS_DIFF=true
fi
printf "\n"
# Check if the files are present in the changed file list (added, modified, deleted) then output to stdout.
HAS_DIFF="${HAS_DIFF:-false}"
printf "=== Which Docker files changed? ===\n"
if printf "%s\n" "${GIT_DIFF[@]}" | grep -E "${{ env.re_change }}"; then
HAS_DIFF=true
fi
printf "\n"
# Did Docker files change?
{
printf "=== Did Docker files change? ===\n"
printf "Changes Detected: %s\n" "${HAS_DIFF}"
printf "\n"
printf "\`\`\`text\n"
printf "%s\n" "${GIT_DIFF[@]}" | grep -E "${{ env.re_change }}" || true
printf "\`\`\`\n"
printf "\n"
} | tee -a "${GITHUB_STEP_SUMMARY}"
# Set the output named "docs_changed"
printf "%s=%s\n" "docs_changed" "${HAS_DIFF}" >> "${GITHUB_OUTPUT}"
stage2:
name: Docker Build
strategy:
matrix:
os: ["ubuntu-latest"]
runs-on: "${{ matrix.os }}"
needs: [stage1]
if: needs.stage1.outputs.docs_changed == 'True'
outputs:
tag_date: ${{ steps.setup_image_info.outputs.tag_date }}
steps:
- name: Setup Env [${{ matrix.os }}]
id: setup_image_info
run: |-
tag_date="$(date +%Y%m%d)"
printf "%s=%s\n" "tag_date" "${tag_date}" >> "${GITHUB_OUTPUT}"
- name: Docker Build Checkout [${{ matrix.os }}]
uses: actions/checkout@v3
- name: Login to Docker Hub [${{ matrix.os }}]
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up Docker Buildx [${{ matrix.os }}]
uses: docker/setup-buildx-action@v2
- name: Build and push [${{ matrix.os }}]
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:latest,${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:${{ steps.setup_image_info.outputs.tag_date }}
stage3:
name: Docker Build Check
env:
ORG: ${{ secrets.DOCKERHUB_USERNAME }}
IMAGE_NAME: ci-generic-debian
strategy:
matrix:
os:
- vpayno/ci-generic-debian:latest
- vpayno/ci-generic-debian:${{ needs.stage2.outputs.tag_date }}
runs-on: ubuntu-latest
container: ${{ matrix.os }}
needs: [stage2]
steps:
- name: Test New Container [${{ matrix.os }}]
run: |-
printf "%s\n" "Hello World!"
- name: Docker Build Summary [${{ matrix.os }}]
run: |-
ORG_IMAGE="${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}"
TOKEN="$(curl "https://auth.docker.io/token?service=registry.docker.io&scope=repository:${ORG_IMAGE}:pull" | jq -r .access_token)"
{
printf "Docker Hub Image Info\n"
curl -sS --header "Authorization: Bearer ${TOKEN}" "https://index.docker.io/v2/${ORG_IMAGE}/tags/list" | jq .
} | tee -a "${GITHUB_STEP_SUMMARY}"