2022-01-26 10:17:59 -05:00
---
2022-09-27 10:30:54 -04:00
name : Build, test, and eventually deploy super-linter container images
2022-01-26 10:17:59 -05:00
on :
pull_request :
push :
jobs :
build :
2022-09-27 10:30:54 -04:00
name : Build, test, and eventually push the container image
2022-01-26 10:17:59 -05:00
runs-on : ubuntu-latest
strategy :
2022-02-07 11:28:48 -05:00
fail-fast : false
2022-01-26 10:17:59 -05:00
matrix :
images :
- container-build-target : final_slim
container-image-id-prefix : slim-
deployment-environment-identifier : Production-SLIM
image-id : slim
- container-build-target : final_standard
container-image-id-prefix : ""
deployment-environment-identifier : Production
image-id : standard
timeout-minutes : 60
steps :
- name : Checkout Code
2022-03-07 10:34:26 -05:00
uses : actions/checkout@v3
2022-01-26 10:17:59 -05:00
with :
# Full git history is needed to get a proper list
# of changed files within `super-linter`
fetch-depth : 0
2022-09-27 10:30:54 -04:00
- name : Get current date and make it available as an environment variable
2022-01-26 10:17:59 -05:00
run : |
echo "Appending the build date contents to GITHUB_ENV..."
echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> "${GITHUB_ENV}"
2022-09-27 10:30:54 -04:00
- name : Setup Docker BuildX
2022-05-09 10:46:10 -04:00
uses : docker/setup-buildx-action@v2.0.0
2022-01-26 10:17:59 -05:00
- name : Build Docker image - ${{ matrix.images.image-id }}
2022-01-26 13:00:55 -05:00
if : ${{ github.repository == 'github/super-linter' && github.ref != 'refs/heads/main' }}
2022-08-15 12:23:56 -04:00
uses : docker/build-push-action@v3.1.1
2022-01-26 10:17:59 -05:00
with :
context : .
file : ./Dockerfile
build-args : |
BUILD_DATE=${{ env.BUILD_DATE }}
BUILD_REVISION=${{ github.sha }}
BUILD_VERSION=${{ github.sha }}
load : true
push : false
tags : |
ghcr.io/github/super-linter:${{ matrix.images.container-image-id-prefix }}${{ github.sha }}
ghcr.io/github/super-linter:${{ matrix.images.container-image-id-prefix }}test
target : "${{ matrix.images.container-build-target }}"
2022-09-27 10:30:54 -04:00
- name : Run container image label test cases
2022-01-26 13:00:55 -05:00
if : ${{ github.repository == 'github/super-linter' && github.ref != 'refs/heads/main' }}
2022-01-26 10:17:59 -05:00
shell : bash
run : .automation/validate-docker-labels.sh "${{ matrix.images.image-id }}"
- name : Edit an action.yml file for test local build
2022-01-26 13:00:55 -05:00
if : ${{ github.repository == 'github/super-linter' && github.ref != 'refs/heads/main' }}
2022-01-26 10:17:59 -05:00
run : |
sed -i "s/super-linter:.*/super-linter:${{ matrix.images.container-image-id-prefix }}${GITHUB_SHA}'/g" action.yml
- name : Gather information about the runtime environment
2022-01-26 13:00:55 -05:00
if : ${{ github.repository == 'github/super-linter' && github.ref != 'refs/heads/main' }}
2022-01-26 10:17:59 -05:00
shell : bash
run : |
make info
############################################################
# Test the built image in the actions context. #
# Not the container directly, and not using RUN_LOCAL=true #
############################################################
- name : Test the local action
2022-01-26 13:00:55 -05:00
if : ${{ github.repository == 'github/super-linter' && github.ref != 'refs/heads/main' }}
2022-01-26 10:17:59 -05:00
uses : ./
env :
ACTIONS_RUNNER_DEBUG : true
ERROR_ON_MISSING_EXEC_BIT : true
VALIDATE_ALL_CODEBASE : false
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
DEFAULT_BRANCH : main
2022-05-24 14:44:12 -04:00
LOCAL_UPDATES : true
2022-09-27 10:30:54 -04:00
# Workaround for https://github.com/actions/runner/issues/434
2022-01-26 10:17:59 -05:00
- name : Fix file and directory ownership
2022-01-26 13:00:55 -05:00
if : ${{ github.repository == 'github/super-linter' && github.ref != 'refs/heads/main' }}
2022-01-26 10:17:59 -05:00
shell : bash
run : |
sudo chown -R "$(id -u)":"$(id -g)" "$(pwd)"
- name : Run the test suite
2022-01-26 13:00:55 -05:00
if : ${{ github.repository == 'github/super-linter' && github.ref != 'refs/heads/main' }}
2022-01-26 10:17:59 -05:00
shell : bash
run : |
make IMAGE=${{ matrix.images.image-id }} test
- name : Upload the code coverage report
2022-01-26 13:00:55 -05:00
if : ${{ github.repository == 'github/super-linter' && github.ref != 'refs/heads/main' }}
2022-01-26 10:17:59 -05:00
uses : codacy/codacy-coverage-reporter-action@v1.1
2022-02-14 15:47:36 -05:00
# Sometimes this fails when user does not have permissions to secrets
continue-on-error : true
2022-01-26 10:17:59 -05:00
with :
project-token : ${{ secrets.CODACY_PROJECT_TOKEN }}
coverage-reports : test/reports/cobertura/runTests.sh/cobertura.xml
2022-09-27 10:30:54 -04:00
- name : Run test cases - ${{ matrix.images.image-id }}
2022-01-26 13:00:55 -05:00
if : ${{ github.repository == 'github/super-linter' && github.ref != 'refs/heads/main' }}
2022-01-26 10:17:59 -05:00
shell : bash
run : |
docker run \
-e RUN_LOCAL=true \
-e TEST_CASE_RUN=true \
-e ANSIBLE_DIRECTORY=.automation/test/ansible \
-e ACTIONS_RUNNER_DEBUG=true \
-e ERROR_ON_MISSING_EXEC_BIT=true \
-v "${GITHUB_WORKSPACE}:/tmp/lint" \
"ghcr.io/github/super-linter:${{ matrix.images.container-image-id-prefix }}${GITHUB_SHA}"
2022-09-27 10:30:54 -04:00
- name : Clean the working directory for additional testing
2022-01-26 13:00:55 -05:00
if : ${{ github.repository == 'github/super-linter' && github.ref != 'refs/heads/main' }}
2022-01-26 10:17:59 -05:00
shell : bash
run : .automation/clean-code-base-for-tests.sh
- name : Run against all code base - ${{ matrix.images.image-id }}
2022-01-26 13:00:55 -05:00
if : ${{ github.repository == 'github/super-linter' && github.ref != 'refs/heads/main' }}
2022-01-26 10:17:59 -05:00
shell : bash
run : |
docker run \
-e RUN_LOCAL=true \
-e OUTPUT_DETAILS=detailed \
-e ACTIONS_RUNNER_DEBUG=true \
-e ERROR_ON_MISSING_EXEC_BIT=true \
-v "${GITHUB_WORKSPACE}:/tmp/lint" \
"ghcr.io/github/super-linter:${{ matrix.images.container-image-id-prefix }}${GITHUB_SHA}"
2022-09-27 10:30:54 -04:00
- name : Login to Docker Hub
2022-01-26 10:17:59 -05:00
if : ${{ github.repository == 'github/super-linter' && github.ref == 'refs/heads/main' }}
2022-05-09 10:45:50 -04:00
uses : docker/login-action@v2.0.0
2022-01-26 10:17:59 -05:00
with :
username : ${{ secrets.DOCKER_USERNAME }}
password : ${{ secrets.DOCKER_PASSWORD }}
- name : Login to GitHub Container Registry
if : ${{ github.repository == 'github/super-linter' && github.ref == 'refs/heads/main' }}
2022-05-09 10:45:50 -04:00
uses : docker/login-action@v2.0.0
2022-01-26 10:17:59 -05:00
with :
registry : ghcr.io
username : ${{ secrets.GCR_USERNAME }}
password : ${{ secrets.GCR_TOKEN }}
2022-09-27 10:30:54 -04:00
- name : Start the deployment for the ${{ matrix.images.deployment-environment-identifier }} environment
2022-01-26 10:17:59 -05:00
if : ${{ github.repository == 'github/super-linter' && github.ref == 'refs/heads/main' }}
2022-07-11 13:13:52 -04:00
uses : bobheadxi/deployments@v1.3.0
2022-01-26 10:17:59 -05:00
id : deployment
with :
step : start
token : ${{ secrets.GITHUB_TOKEN }}
env : ${{ matrix.images.deployment-environment-identifier }}
2022-09-27 10:30:54 -04:00
- name : Build the container image and push it - ${{ matrix.images.image-id }}
2022-01-26 10:17:59 -05:00
if : ${{ github.repository == 'github/super-linter' && github.ref == 'refs/heads/main' }}
2022-08-15 12:23:56 -04:00
uses : docker/build-push-action@v3.1.1
2022-01-26 10:17:59 -05:00
with :
context : .
file : ./Dockerfile
build-args : |
BUILD_DATE=${{ env.BUILD_DATE }}
BUILD_REVISION=${{ github.sha }}
BUILD_VERSION=${{ github.sha }}
2022-01-26 13:00:55 -05:00
load : false
2022-01-26 10:17:59 -05:00
push : true
tags : |
github/super-linter:${{ matrix.images.container-image-id-prefix }}latest
ghcr.io/github/super-linter:${{ matrix.images.container-image-id-prefix }}latest
target : "${{ matrix.images.container-build-target }}"
2022-09-27 10:30:54 -04:00
- name : Update the deployment status for the ${{ matrix.images.deployment-environment-identifier }} environment
if : ${{ github.repository == 'github/super-linter' && github.ref == 'refs/heads/main' }}
uses : bobheadxi/deployments@v1.3.0
with :
step : finish
token : ${{ secrets.GITHUB_TOKEN }}
status : ${{ job.status }}
deployment_id : ${{ steps.deployment.outputs.deployment_id }}
env : ${{ steps.deployment.outputs.env }}
env_url : https://github.com/github/super-linter
- name : Create a GitHub issue on failure
2022-01-26 10:17:59 -05:00
if : ${{ github.repository == 'github/super-linter' && github.ref == 'refs/heads/main' && failure() }}
2022-02-14 16:20:29 -05:00
uses : actions/github-script@v6
2022-01-26 10:17:59 -05:00
id : create-issue
with :
# https://octokit.github.io/rest.js/v18#issues-create
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 to production" ,
body : "Automation has failed us!\nMore information can be found at:\n - ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
})
console.log('create', create)
return create.data.number
2022-09-27 10:30:54 -04:00
- name : Assign admins to the issue created on failure
2022-02-14 16:20:29 -05:00
uses : actions/github-script@v6
2022-01-26 10:17:59 -05:00
if : ${{ github.repository == 'github/super-linter' && github.ref == 'refs/heads/main' && failure() }}
with :
github-token : ${{secrets.GITHUB_TOKEN}}
script : |
github.rest.issues.addAssignees({
owner : context.repo.owner,
repo : context.repo.repo,
issue_number : "${{ steps.create-issue.outputs.result }}" ,
assignees : [
'admiralawkbar' ,
'jwiebalk' ,
'IAmHughes' ,
'nemchik' ,
'Hanse00' ,
'GaboFDC' ,
'ferrarimarco'
]
})