From c0f47d0effb2fe5a4df3808a85baeaeea672469a Mon Sep 17 00:00:00 2001 From: Marco Ferrari Date: Wed, 26 Jan 2022 16:17:59 +0100 Subject: [PATCH] De-duplicate workflows (#2220) * De-duplicate deploy-DEV workflows * Add $ * Fix build target * Fix standard target * Consolidate workflows in a single one * more clean * add changes * fix spaces * fix release Co-authored-by: Admiral Awkbar --- .../HOLDING/automerge-dependabot.yml.hold | 63 ---- .github/workflows/deploy-DEV-slim.yml | 207 ------------ .github/workflows/deploy-DEV-standard.yml | 206 ------------ .github/workflows/deploy-PROD-slim.yml | 185 ----------- .github/workflows/deploy-PROD-standard.yml | 184 ----------- .github/workflows/deploy-Production.yml | 307 ++++++++++++++++++ .github/workflows/deploy-RELEASE-standard.yml | 206 ------------ ...oy-RELEASE-slim.yml => deploy-Release.yml} | 135 ++++---- Makefile | 2 - 9 files changed, 366 insertions(+), 1129 deletions(-) delete mode 100644 .github/workflows/HOLDING/automerge-dependabot.yml.hold delete mode 100644 .github/workflows/deploy-DEV-slim.yml delete mode 100644 .github/workflows/deploy-DEV-standard.yml delete mode 100644 .github/workflows/deploy-PROD-slim.yml delete mode 100644 .github/workflows/deploy-PROD-standard.yml create mode 100644 .github/workflows/deploy-Production.yml delete mode 100644 .github/workflows/deploy-RELEASE-standard.yml rename .github/workflows/{deploy-RELEASE-slim.yml => deploy-Release.yml} (64%) diff --git a/.github/workflows/HOLDING/automerge-dependabot.yml.hold b/.github/workflows/HOLDING/automerge-dependabot.yml.hold deleted file mode 100644 index f9d01bac..00000000 --- a/.github/workflows/HOLDING/automerge-dependabot.yml.hold +++ /dev/null @@ -1,63 +0,0 @@ ---- -####################################### -####################################### -## Dependabot automerge dependencies ## -####################################### -####################################### - -# -# Documentation: -# https://medium.com/@toufik.airane/automerge-github-dependabot-alerts-with-github-actions-7cd6f5763750 -# - -###################### -# name of the action # -###################### -name: automerge on pull request - -############### -# When to run # -############### -on: [pull_request] - -################# -# Start the job # -################# -jobs: - automerge: - name: automerge dependabot - runs-on: ubuntu-latest - if: github.actor == 'dependabot[bot]' - steps: - - name: Wait for CI/CT/CD to succeed - uses: fountainhead/action-wait-for-check@v1.0.0 - id: wait-for-build - with: - token: ${{ secrets.GITHUB_TOKEN }} - checkName: Deploy Docker Image - DEV - ref: ${{ github.event.pull_request.head.sha || github.sha }} - - - name: Wait for CI/CT/CD to succeed pt2 - uses: fountainhead/action-wait-for-check@v1.0.0 - id: wait-for-ci - with: - token: ${{ secrets.GITHUB_TOKEN }} - checkName: Stack linter - ref: ${{ github.event.pull_request.head.sha || github.sha }} - - - name: merge - if: steps.wait-for-build.outputs.conclusion == 'success' || steps.wait-for-build.outputs.conclusion == 'skipped' && steps.wait-for-ci.outputs.conclusion == 'success' - uses: actions/github-script@v3 - with: - script: | - github.pulls.createReview({ - owner: context.payload.repository.owner.login, - repo: context.payload.repository.name, - pull_number: context.payload.pull_request.number, - event: 'APPROVE' - }) - github.pulls.merge({ - owner: context.payload.repository.owner.login, - repo: context.payload.repository.name, - pull_number: context.payload.pull_request.number - }) diff --git a/.github/workflows/deploy-DEV-slim.yml b/.github/workflows/deploy-DEV-slim.yml deleted file mode 100644 index 99c140be..00000000 --- a/.github/workflows/deploy-DEV-slim.yml +++ /dev/null @@ -1,207 +0,0 @@ ---- -######################### -######################### -## Deploy Docker Image ## -######################### -######################### - -# -# Documentation: -# https://help.github.com/en/articles/workflow-syntax-for-github-actions -# - -##################################### -# Start the job on all push to main # -##################################### -############################# -# Start the job on all push # -############################# -on: - push: - branches-ignore: [main] - -############### -# Set the Job # -############### -jobs: - build: - # Name the Job - name: Deploy Docker Image - DEV - SLIM - # Set the agent to run on - runs-on: ubuntu-latest - # Prevent duplicate run from happening when a forked push is committed - if: ${{ github.event_name == 'push' || - github.event.pull_request.head.repo.full_name != github.repository }} - timeout-minutes: 60 - ################## - # Load all steps # - ################## - steps: - ########################## - # Checkout the code base # - ########################## - - name: Checkout Code - uses: actions/checkout@v2.4.0 - with: - # Full git history is needed to get a proper list - # of changed files within `super-linter` - fetch-depth: 0 - - ######################## - # Get the current date # - ######################## - - name: Get current date - run: | - echo "Appending the build date contents to GITHUB_ENV..." - echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> "${GITHUB_ENV}" - - ######################## - # Setup Docker build X # - ######################## - - name: Setup BuildX - uses: docker/setup-buildx-action@v1.6.0 - - ################ - # Docker cache # - ################ - - name: Cache Docker layers - uses: actions/cache@v2 - with: - path: /tmp/.buildx-cache - key: ${{ runner.os }}-single-buildx-slim - restore-keys: | - ${{ runner.os }}-single-buildx - - ########################################### - # Build and Push containers to registries # - ########################################### - - name: Build Docker image - SLIM - uses: docker/build-push-action@v2.8.0 - 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:slim-${{ github.sha }} - ghcr.io/github/super-linter:slim-test - target: final_slim - cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,dest=/tmp/.buildx-cache-new - - # Temp fix - # https://github.com/docker/build-push-action/issues/252 - # https://github.com/moby/buildkit/issues/1896 - ############# - # Fix Cache # - ############# - - name: Move cache - run: | - rm -rf /tmp/.buildx-cache - mv /tmp/.buildx-cache-new /tmp/.buildx-cache - - ######################################## - # Validates the metadata docker labels # - ######################################## - - name: Run Docker label test cases - shell: bash - run: .automation/validate-docker-labels.sh "slim" - - ######################################## - # Edit action.yml for test local build # - ######################################## - - name: Edit an action.yml file for test local build - run: | - sed -i "s/super-linter:.*/super-linter:slim-${GITHUB_SHA}'/g" action.yml - - ###################### - # Gather information # - ###################### - - name: Gather information about the runtime environment - shell: bash - run: | - make info - - ########################## - # Test in action context # - ########################## - # Test the built image in the actions context. - # Not the container directly, and not using RUN_LOCAL=true - - name: Test the local action - uses: ./ - env: - ACTIONS_RUNNER_DEBUG: true - ERROR_ON_MISSING_EXEC_BIT: true - VALIDATE_ALL_CODEBASE: false - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - DEFAULT_BRANCH: main - - ############################################################### - # Fix file and dir ownership. # - # Workaround for https://github.com/actions/runner/issues/434 # - ############################################################### - - name: Fix file and directory ownership - shell: bash - run: | - sudo chown -R "$(id -u)":"$(id -g)" "$(pwd)" - - ################## - # Run test cases # - ################## - - name: Run the test suite - shell: bash - run: | - make IMAGE=slim test - - ########################## - # Codacy Coverage Report # - ########################## - - name: Upload the code coverage report - uses: codacy/codacy-coverage-reporter-action@v1.3 - # Dependabot does not have priv to see the secret, so will - # fail opn bump jobs... - continue-on-error: true - with: - project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} - coverage-reports: test/reports/cobertura/runTests.sh/cobertura.xml - - ##################################### - # Run Linter against Test code base # - ##################################### - - name: Run Test Cases - SLIM - 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:slim-${GITHUB_SHA}" - - ######################################### - # Clean code base to run against it all # - ######################################### - - name: Clean Test code base for additional testing - shell: bash - run: .automation/clean-code-base-for-tests.sh - - ############################################ - # Run Linter against ALL cleaned code base # - ############################################ - - name: Run against all code base - SLIM - 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 \ - -e YAML_LINTER_RULES=.github/linters/.yaml-linter.yml \ - -v "${GITHUB_WORKSPACE}:/tmp/lint" \ - "ghcr.io/github/super-linter:slim-${GITHUB_SHA}" diff --git a/.github/workflows/deploy-DEV-standard.yml b/.github/workflows/deploy-DEV-standard.yml deleted file mode 100644 index 3f428e9f..00000000 --- a/.github/workflows/deploy-DEV-standard.yml +++ /dev/null @@ -1,206 +0,0 @@ ---- -######################### -######################### -## Deploy Docker Image ## -######################### -######################### - -# -# Documentation: -# https://help.github.com/en/articles/workflow-syntax-for-github-actions -# - -##################################### -# Start the job on all push to main # -##################################### -############################# -# Start the job on all push # -############################# -on: - push: - branches-ignore: [main] - -############### -# Set the Job # -############### -jobs: - build: - # Name the Job - name: Deploy Docker Image - DEV - # Set the agent to run on - runs-on: ubuntu-latest - # Prevent duplicate run from happening when a forked push is committed - if: ${{ github.event_name == 'push' || - github.event.pull_request.head.repo.full_name != github.repository }} - timeout-minutes: 60 - ################## - # Load all steps # - ################## - steps: - ########################## - # Checkout the code base # - ########################## - - name: Checkout Code - uses: actions/checkout@v2.4.0 - with: - # Full git history is needed to get a proper list - # of changed files within `super-linter` - fetch-depth: 0 - - ######################## - # Get the current date # - ######################## - - name: Get current date - run: | - echo "Appending the build date contents to GITHUB_ENV..." - echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> "${GITHUB_ENV}" - - ######################## - # Setup Docker build X # - ######################## - - name: Setup BuildX - uses: docker/setup-buildx-action@v1.6.0 - - ################ - # Docker cache # - ################ - - name: Cache Docker layers - uses: actions/cache@v2 - with: - path: /tmp/.buildx-cache - key: ${{ runner.os }}-single-buildx-standard - restore-keys: | - ${{ runner.os }}-single-buildx - - ########################################### - # Build and Push containers to registries # - ########################################### - - name: Build Docker image - Standard - uses: docker/build-push-action@v2.8.0 - 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:${{ github.sha }}" - ghcr.io/github/super-linter:test - cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,dest=/tmp/.buildx-cache-new - - # Temp fix - # https://github.com/docker/build-push-action/issues/252 - # https://github.com/moby/buildkit/issues/1896 - ############# - # Fix Cache # - ############# - - name: Move cache - run: | - rm -rf /tmp/.buildx-cache - mv /tmp/.buildx-cache-new /tmp/.buildx-cache - - ######################################## - # Validates the metadata docker labels # - ######################################## - - name: Run Docker label test cases - shell: bash - run: .automation/validate-docker-labels.sh - - ######################################## - # Edit action.yml for test local build # - ######################################## - - name: Edit an action.yml file for test local build - run: | - sed -i "s/super-linter:.*/super-linter:${GITHUB_SHA}'/g" action.yml - - ###################### - # Gather information # - ###################### - - name: Gather information about the runtime environment - shell: bash - run: | - make info - - ########################## - # Test in action context # - ########################## - # Test the built image in the actions context. - # Not the container directly, and not using RUN_LOCAL=true - - name: Test the local action - uses: ./ - env: - ACTIONS_RUNNER_DEBUG: true - ERROR_ON_MISSING_EXEC_BIT: true - VALIDATE_ALL_CODEBASE: false - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - DEFAULT_BRANCH: main - - ############################################################### - # Fix file and dir ownership. # - # Workaround for https://github.com/actions/runner/issues/434 # - ############################################################### - - name: Fix file and directory ownership - shell: bash - run: | - sudo chown -R "$(id -u)":"$(id -g)" "$(pwd)" - - ################## - # Run test cases # - ################## - - name: Run the test suite - shell: bash - run: | - make test - - ########################## - # Codacy Coverage Report # - ########################## - - name: Upload the code coverage report - uses: codacy/codacy-coverage-reporter-action@v1.3 - # Dependabot does not have priv to see the secret, so will - # fail opn bump jobs... - continue-on-error: true - with: - project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} - coverage-reports: test/reports/cobertura/runTests.sh/cobertura.xml - - ##################################### - # Run Linter against Test code base # - ##################################### - - name: Run Test Cases - standard - 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:${GITHUB_SHA}" - - ######################################### - # Clean code base to run against it all # - ######################################### - - name: Clean Test code base for additional testing - shell: bash - run: .automation/clean-code-base-for-tests.sh - - ############################################ - # Run Linter against ALL cleaned code base # - ############################################ - - name: Run against all code base - 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 \ - -e YAML_LINTER_RULES=.github/linters/.yaml-linter.yml \ - -v "${GITHUB_WORKSPACE}:/tmp/lint" \ - "ghcr.io/github/super-linter:${GITHUB_SHA}" diff --git a/.github/workflows/deploy-PROD-slim.yml b/.github/workflows/deploy-PROD-slim.yml deleted file mode 100644 index 29bcbb34..00000000 --- a/.github/workflows/deploy-PROD-slim.yml +++ /dev/null @@ -1,185 +0,0 @@ ---- -######################### -######################### -## Deploy Docker Image ## -######################### -######################### - -# -# Documentation: -# https://help.github.com/en/articles/workflow-syntax-for-github-actions -# - -##################################### -# Start the job on all push to main # -##################################### -on: - push: - branches: - - 'main' - -############### -# Set the Job # -############### -jobs: - build: - # Name the Job - name: Deploy Docker Image - PROD - slim - # Set the agent to run on - runs-on: ubuntu-latest - # Only run this on the main repo - if: ${{ github.repository == 'github/super-linter' }} - timeout-minutes: 60 - ################## - # Load all steps # - ################## - steps: - ########################## - # Checkout the code base # - ########################## - - name: Checkout Code - uses: actions/checkout@v2.4.0 - - ######################## - # Get the current date # - ######################## - - name: Get current date - run: | - echo "Appending the build date contents to GITHUB_ENV..." - echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> "${GITHUB_ENV}" - - ######################## - # Setup Docker build X # - ######################## - - name: Setup BuildX - uses: docker/setup-buildx-action@v1.6.0 - - ############################### - # Login to DockerHub registry # - ############################### - - name: Login to DockerHub - uses: docker/login-action@v1.12.0 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - ###################################### - # Login to GitHub Container registry # - ###################################### - - name: Login to GitHub Container Registry - uses: docker/login-action@v1.12.0 - with: - registry: ghcr.io - username: ${{ secrets.GCR_USERNAME }} - password: ${{ secrets.GCR_TOKEN }} - - ######################### - # Update deployment API # - ######################### - - name: Start deployment - uses: bobheadxi/deployments@v0.6.2 - id: deployment - with: - step: start - token: ${{ secrets.GITHUB_TOKEN }} - env: Production-SLIM - - ################ - # Docker cache # - ################ - - name: Cache Docker layers - uses: actions/cache@v2 - with: - path: /tmp/.buildx-cache - key: ${{ runner.os }}-single-buildx-slim - restore-keys: | - ${{ runner.os }}-single-buildx - - ########################################### - # Build and Push containers to registries # - ########################################### - - name: Build and push - SLIM - uses: docker/build-push-action@v2.8.0 - with: - context: . - file: ./Dockerfile - build-args: | - BUILD_DATE=${{ env.BUILD_DATE }} - BUILD_REVISION=${{ github.sha }} - BUILD_VERSION=${{ github.sha }} - push: true - tags: | - github/super-linter:slim-latest - ghcr.io/github/super-linter:slim-latest - target: final_slim - cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,dest=/tmp/.buildx-cache-new - - # Temp fix - # https://github.com/docker/build-push-action/issues/252 - # https://github.com/moby/buildkit/issues/1896 - ############# - # Fix Cache # - ############# - - name: Move cache - run: | - rm -rf /tmp/.buildx-cache - mv /tmp/.buildx-cache-new /tmp/.buildx-cache - - ####################################################### - # Create a GitHub Issue with the info from this build # - ####################################################### - - name: Create GitHub Issue for failure - if: failure() - uses: actions/github-script@v5 - 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 - - ############################ - # Assign admins on failure # - ############################ - - name: Assign Admins on failure - uses: actions/github-script@v5 - if: failure() - with: - # https://octokit.github.io/rest.js/v18#issues-create - 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', - 'lindluni', - 'IAmHughes', - 'nemchik', - 'Hanse00', - 'GaboFDC', - 'ferrarimarco' - ] - }) - - ######################### - # Update Deployment API # - ######################### - - name: Update deployment status - uses: bobheadxi/deployments@v0.6.2 - if: always() - with: - step: finish - token: ${{ secrets.GITHUB_TOKEN }} - status: ${{ job.status }} - deployment_id: ${{ steps.deployment.outputs.deployment_id }} - env_url: https://github.com/github/super-linter diff --git a/.github/workflows/deploy-PROD-standard.yml b/.github/workflows/deploy-PROD-standard.yml deleted file mode 100644 index 0a3feaf4..00000000 --- a/.github/workflows/deploy-PROD-standard.yml +++ /dev/null @@ -1,184 +0,0 @@ ---- -######################### -######################### -## Deploy Docker Image ## -######################### -######################### - -# -# Documentation: -# https://help.github.com/en/articles/workflow-syntax-for-github-actions -# - -##################################### -# Start the job on all push to main # -##################################### -on: - push: - branches: - - 'main' - -############### -# Set the Job # -############### -jobs: - build: - # Name the Job - name: Deploy Docker Image - PROD - standard - # Set the agent to run on - runs-on: ubuntu-latest - # Only run this on the main repo - if: ${{ github.repository == 'github/super-linter' }} - timeout-minutes: 60 - ################## - # Load all steps # - ################## - steps: - ########################## - # Checkout the code base # - ########################## - - name: Checkout Code - uses: actions/checkout@v2.4.0 - - ######################## - # Get the current date # - ######################## - - name: Get current date - run: | - echo "Appending the build date contents to GITHUB_ENV..." - echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> "${GITHUB_ENV}" - - ######################## - # Setup Docker build X # - ######################## - - name: Setup BuildX - uses: docker/setup-buildx-action@v1.6.0 - - ############################### - # Login to DockerHub registry # - ############################### - - name: Login to DockerHub - uses: docker/login-action@v1.12.0 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - ###################################### - # Login to GitHub Container registry # - ###################################### - - name: Login to GitHub Container Registry - uses: docker/login-action@v1.12.0 - with: - registry: ghcr.io - username: ${{ secrets.GCR_USERNAME }} - password: ${{ secrets.GCR_TOKEN }} - - ######################### - # Update deployment API # - ######################### - - name: Start deployment - uses: bobheadxi/deployments@v0.6.2 - id: deployment - with: - step: start - token: ${{ secrets.GITHUB_TOKEN }} - env: Production - - ################ - # Docker cache # - ################ - - name: Cache Docker layers - uses: actions/cache@v2 - with: - path: /tmp/.buildx-cache - key: ${{ runner.os }}-single-buildx-standard - restore-keys: | - ${{ runner.os }}-single-buildx - - ########################################### - # Build and Push containers to registries # - ########################################### - - name: Build and push - Standard - uses: docker/build-push-action@v2.8.0 - with: - context: . - file: ./Dockerfile - build-args: | - BUILD_DATE=${{ env.BUILD_DATE }} - BUILD_REVISION=${{ github.sha }} - BUILD_VERSION=${{ github.sha }} - push: true - tags: | - github/super-linter:latest - ghcr.io/github/super-linter:latest - cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,dest=/tmp/.buildx-cache-new - - # Temp fix - # https://github.com/docker/build-push-action/issues/252 - # https://github.com/moby/buildkit/issues/1896 - ############# - # Fix Cache # - ############# - - name: Move cache - run: | - rm -rf /tmp/.buildx-cache - mv /tmp/.buildx-cache-new /tmp/.buildx-cache - - ####################################################### - # Create a GitHub Issue with the info from this build # - ####################################################### - - name: Create GitHub Issue for failure - if: failure() - uses: actions/github-script@v5 - 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 - - ############################ - # Assign admins on failure # - ############################ - - name: Assign Admins on failure - uses: actions/github-script@v5 - if: failure() - with: - # https://octokit.github.io/rest.js/v18#issues-create - 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', - 'lindluni', - 'IAmHughes', - 'nemchik', - 'Hanse00', - 'GaboFDC', - 'ferrarimarco' - ] - }) - - ######################### - # Update Deployment API # - ######################### - - name: Update deployment status - uses: bobheadxi/deployments@v0.6.2 - if: always() - with: - step: finish - token: ${{ secrets.GITHUB_TOKEN }} - status: ${{ job.status }} - deployment_id: ${{ steps.deployment.outputs.deployment_id }} - env_url: https://github.com/github/super-linter diff --git a/.github/workflows/deploy-Production.yml b/.github/workflows/deploy-Production.yml new file mode 100644 index 00000000..4bfc5914 --- /dev/null +++ b/.github/workflows/deploy-Production.yml @@ -0,0 +1,307 @@ +--- +############################################# +############################################# +## Deploy Docker Image test and Production ## +############################################# +############################################# + +# +# Documentation: +# https://help.github.com/en/articles/workflow-syntax-for-github-actions +# + +########################################### +# Start the job on all push or PR to main # +########################################### +on: + pull_request: + push: + +############### +# Set the Job # +############### +jobs: + build: + # Name the Job + name: Deploy Docker Image - DEV + # Set the agent to run on + runs-on: ubuntu-latest + strategy: + 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 below # + ############### + steps: + ############################ + # Checkout the source code # + ############################ + - name: Checkout Code + uses: actions/checkout@v2.4.0 + with: + # Full git history is needed to get a proper list + # of changed files within `super-linter` + fetch-depth: 0 + + ########################### + # Set current date to ENV # + ########################### + - name: Get current date + run: | + echo "Appending the build date contents to GITHUB_ENV..." + echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> "${GITHUB_ENV}" + + ####################### + # Setup Docker BuildX # + ####################### + - name: Setup BuildX + uses: docker/setup-buildx-action@v1.6.0 + + ####################################### + # Build local docker images for tests # + ####################################### + - name: Build Docker image - ${{ matrix.images.image-id }} + uses: docker/build-push-action@v2.7.0 + with: + cache-from: type=gha + cache-to: type=gha,mode=max + 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 }}" + + ################################ + # Run local docker labels test # + ################################ + - name: Run Docker label test cases + shell: bash + run: .automation/validate-docker-labels.sh "${{ matrix.images.image-id }}" + + ####################################### + # Edit the action.yml for local tests # + ####################################### + - name: Edit an action.yml file for test local build + run: | + sed -i "s/super-linter:.*/super-linter:${{ matrix.images.container-image-id-prefix }}${GITHUB_SHA}'/g" action.yml + + ###################### + # Gather information # + ###################### + - name: Gather information about the runtime environment + 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 + uses: ./ + env: + ACTIONS_RUNNER_DEBUG: true + ERROR_ON_MISSING_EXEC_BIT: true + VALIDATE_ALL_CODEBASE: false + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + DEFAULT_BRANCH: main + + ############################################################### + # Fix file and dir ownership. # + # Workaround for https://github.com/actions/runner/issues/434 # + ############################################################### + - name: Fix file and directory ownership + shell: bash + run: | + sudo chown -R "$(id -u)":"$(id -g)" "$(pwd)" + + ######################## + # Run local make tests # + ######################## + - name: Run the test suite + shell: bash + run: | + make IMAGE=${{ matrix.images.image-id }} test + + ########################## + # Codacy Coverage Report # + ########################## + - name: Upload the code coverage report + if: ${{ github.repository == 'github/super-linter' }} + uses: codacy/codacy-coverage-reporter-action@v1.1 + with: + project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} + coverage-reports: test/reports/cobertura/runTests.sh/cobertura.xml + + ##################################### + # Run Linter against Test code base # + ##################################### + - name: Run Test Cases - ${{ matrix.images.image-id }} + 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}" + + ######################################### + # Clean code base to run against it all # + ######################################### + - name: Clean Test code base for additional testing + shell: bash + run: .automation/clean-code-base-for-tests.sh + + ############################################ + # Run Linter against ALL cleaned code base # + ############################################ + - name: Run against all code base - ${{ matrix.images.image-id }} + 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}" + + ############################################################# + ############################################################# + ## The following steps are only run if the PR is merges ## + ## into the 'main' branch and push the image to registries ## + ############################################################# + ############################################################# + + ###################### + # Login to DockerHub # + ###################### + - name: Login to DockerHub + if: ${{ github.repository == 'github/super-linter' && github.ref == 'refs/heads/main' }} + uses: docker/login-action@v1.10.0 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + #################### + # Login to GHCR.io # + #################### + - name: Login to GitHub Container Registry + if: ${{ github.repository == 'github/super-linter' && github.ref == 'refs/heads/main' }} + uses: docker/login-action@v1.10.0 + with: + registry: ghcr.io + username: ${{ secrets.GCR_USERNAME }} + password: ${{ secrets.GCR_TOKEN }} + + ######################### + # Update deployment API # + ######################### + - name: Start deployment + if: ${{ github.repository == 'github/super-linter' && github.ref == 'refs/heads/main' }} + uses: bobheadxi/deployments@v0.6.1 + id: deployment + with: + step: start + token: ${{ secrets.GITHUB_TOKEN }} + env: ${{ matrix.images.deployment-environment-identifier }} + + ###################################### + # Build the docker image and push it # + ###################################### + - name: Build Docker image - ${{ matrix.images.image-id }} + if: ${{ github.repository == 'github/super-linter' && github.ref == 'refs/heads/main' }} + uses: docker/build-push-action@v2.7.0 + with: + cache-from: type=gha + cache-to: type=gha,mode=max + context: . + file: ./Dockerfile + build-args: | + BUILD_DATE=${{ env.BUILD_DATE }} + BUILD_REVISION=${{ github.sha }} + BUILD_VERSION=${{ github.sha }} + load: true + 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 }}" + + ####################################################### + # Create a GitHub Issue with the info from this build # + ####################################################### + - name: Create GitHub Issue for failure + if: ${{ github.repository == 'github/super-linter' && github.ref == 'refs/heads/main' && failure() }} + uses: actions/github-script@v5 + 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 + + #################################### + # Deploy was failure, alert admins # + #################################### + - name: Assign Admins on failure + uses: actions/github-script@v5 + if: ${{ github.repository == 'github/super-linter' && github.ref == 'refs/heads/main' && failure() }} + with: + # https://octokit.github.io/rest.js/v18#issues-create + 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' + ] + }) + + ######################### + # Update Deployment API # + ######################### + - name: Update deployment status + if: ${{ github.repository == 'github/super-linter' && github.ref == 'refs/heads/main' }} + uses: bobheadxi/deployments@v0.6.1 + with: + step: finish + token: ${{ secrets.GITHUB_TOKEN }} + status: ${{ job.status }} + deployment_id: ${{ steps.deployment.outputs.deployment_id }} + env_url: https://github.com/github/super-linter diff --git a/.github/workflows/deploy-RELEASE-standard.yml b/.github/workflows/deploy-RELEASE-standard.yml deleted file mode 100644 index 5838fa05..00000000 --- a/.github/workflows/deploy-RELEASE-standard.yml +++ /dev/null @@ -1,206 +0,0 @@ ---- -################################# -################################# -## Deploy Release Docker Image ## -################################# -################################# - -# -# Documentation: -# https://help.github.com/en/articles/workflow-syntax-for-github-actions -# - -########################################## -# Start the job upon a published release # -########################################## -on: - # Start when a release is published - release: - types: ['published'] - -############### -# Set the Job # -############### -jobs: - deploy: - # Name the Job - name: Deploy Docker Image - Release - standard - # Set the agent to run on - runs-on: ubuntu-latest - - ##################################################################### - # Only run if Admin start job and it was the Release Issue template # - ##################################################################### - if: ${{ github.actor == 'admiralawkbar' || github.actor == 'lindluni' || - github.actor == 'IAmHughes' || github.actor == 'nemchik' || - github.actor == 'Hanse00' || github.actor == 'github-actions' || - github.actor == 'GaboFDC' || github.actor == 'ferrarimarco' }} - - timeout-minutes: 60 - - ################## - # Load all steps # - ################## - steps: - ########################## - # Checkout the code base # - ########################## - - name: Checkout Code - uses: actions/checkout@v2.4.0 - - ######################### - # Update deployment API # - ######################### - - name: Start deployment - uses: bobheadxi/deployments@v0.6.2 - id: deployment - with: - step: start - token: ${{ secrets.GITHUB_TOKEN }} - env: Release - - ######################## - # Get the current date # - ######################## - - name: Get current date - run: | - echo "Appending the build date contents to GITHUB_ENV..." - echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> "${GITHUB_ENV}" - - ######################## - # Setup Docker build X # - ######################## - - name: Setup BuildX - uses: docker/setup-buildx-action@v1.6.0 - - ############################### - # Login to DockerHub registry # - ############################### - - name: Login to DockerHub - uses: docker/login-action@v1.12.0 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - ###################################### - # Login to GitHub Container registry # - ###################################### - - name: Login to GitHub Container Registry - uses: docker/login-action@v1.12.0 - with: - username: ${{ secrets.GCR_USERNAME }} - password: ${{ secrets.GCR_TOKEN }} - registry: ghcr.io - - ########################### - # Get the current release # - ########################### - - name: Get current Release number - # shellcheck disable=SC2062 - run: | - echo "RELEASE_VERSION=$(echo ${{ github.event.release.name }} \ - | grep -E -o "v[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+")" \ - >> "${GITHUB_ENV}" - - ################ - # Docker cache # - ################ - - name: Cache Docker layers - uses: actions/cache@v2 - with: - path: /tmp/.buildx-cache - key: ${{ runner.os }}-single-buildx-standard - restore-keys: | - ${{ runner.os }}-single-buildx - - ########################################### - # Build and Push containers to registries # - ########################################### - - name: Build and push - Standard - uses: docker/build-push-action@v2.8.0 - with: - context: . - file: ./Dockerfile - build-args: | - BUILD_DATE=${{ env.BUILD_DATE }} - BUILD_REVISION=${{ github.sha }} - BUILD_VERSION=${{ github.sha }} - push: true - tags: | - github/super-linter:latest - github/super-linter:v4 - "github/super-linter:${{ env.RELEASE_VERSION }}" - ghcr.io/github/super-linter:latest - ghcr.io/github/super-linter:v4 - "ghcr.io/github/super-linter:${{ env.RELEASE_VERSION }}" - cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,dest=/tmp/.buildx-cache-new - - # Temp fix - # https://github.com/docker/build-push-action/issues/252 - # https://github.com/moby/buildkit/issues/1896 - ############# - # Fix Cache # - ############# - - name: Move cache - run: | - rm -rf /tmp/.buildx-cache - mv /tmp/.buildx-cache-new /tmp/.buildx-cache - - ######################### - # Update Deployment API # - ######################### - - name: Update deployment status - uses: bobheadxi/deployments@v0.6.2 - if: always() - with: - step: finish - token: ${{ secrets.GITHUB_TOKEN }} - status: ${{ job.status }} - deployment_id: ${{ steps.deployment.outputs.deployment_id }} - env_url: https://github.com/github/super-linter/releases/tag/${{ env.RELEASE_VERSION }} - - ####################################################### - # Create a GitHub Issue with the info from this build # - ####################################################### - - name: Create GitHub Issue for failure - if: failure() - uses: actions/github-script@v5 - 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 release to production", - 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 }}" - }) - console.log('create', create) - return create.data.number - - ############################ - # Assign admins on failure # - ############################ - - name: Assign Admins on failure - uses: actions/github-script@v5 - if: failure() - with: - # https://octokit.github.io/rest.js/v18#issues-create - 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', - 'lindluni', - 'IAmHughes', - 'nemchik', - 'Hanse00', - 'GaboFDC', - 'ferrarimarco' - ] - }) diff --git a/.github/workflows/deploy-RELEASE-slim.yml b/.github/workflows/deploy-Release.yml similarity index 64% rename from .github/workflows/deploy-RELEASE-slim.yml rename to .github/workflows/deploy-Release.yml index 74e17bf0..b20eb924 100644 --- a/.github/workflows/deploy-RELEASE-slim.yml +++ b/.github/workflows/deploy-Release.yml @@ -1,7 +1,7 @@ --- ################################# ################################# -## Deploy Release Docker Image ## +## Deploy Docker Image Release ## ################################# ################################# @@ -22,75 +22,70 @@ on: # Set the Job # ############### jobs: - deploy: + build: # Name the Job - name: Deploy Docker Image - Release - SLIM + name: Deploy Docker Image - Release # Set the agent to run on runs-on: ubuntu-latest - - ##################################################################### - # Only run if Admin start job and it was the Release Issue template # - ##################################################################### - if: ${{ github.actor == 'admiralawkbar' || github.actor == 'lindluni' || - github.actor == 'IAmHughes' || github.actor == 'nemchik' || - github.actor == 'Hanse00' || github.actor == 'github-actions' || - github.actor == 'GaboFDC' || github.actor == 'ferrarimarco' }} - + strategy: + matrix: + images: + - container-build-target: final_slim + container-image-id-prefix: slim- + deployment-environment-identifier: Release-SLIM + image-id: slim + - container-build-target: final_standard + container-image-id-prefix: "" + deployment-environment-identifier: Release + image-id: standard timeout-minutes: 60 - ################## - # Load all steps # - ################## + ############### + # Steps below # + ############### steps: - ########################## - # Checkout the code base # - ########################## + ############################ + # Checkout the source code # + ############################ - name: Checkout Code uses: actions/checkout@v2.4.0 - - ######################### - # Update deployment API # - ######################### - - name: Start deployment - uses: bobheadxi/deployments@v0.6.2 - id: deployment with: - step: start - token: ${{ secrets.GITHUB_TOKEN }} - env: Release-SLIM + # Full git history is needed to get a proper list + # of changed files within `super-linter` + fetch-depth: 0 - ######################## - # Get the current date # - ######################## + ########################### + # Set current date to ENV # + ########################### - name: Get current date run: | echo "Appending the build date contents to GITHUB_ENV..." echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> "${GITHUB_ENV}" - ######################## - # Setup Docker build X # - ######################## + ####################### + # Setup Docker BuildX # + ####################### - name: Setup BuildX uses: docker/setup-buildx-action@v1.6.0 - ############################### - # Login to DockerHub registry # - ############################### + ###################### + # Login to DockerHub # + ###################### - name: Login to DockerHub - uses: docker/login-action@v1.12.0 + uses: docker/login-action@v1.10.0 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - ###################################### - # Login to GitHub Container registry # - ###################################### + #################### + # Login to GHCR.io # + #################### - name: Login to GitHub Container Registry - uses: docker/login-action@v1.12.0 + uses: docker/login-action@v1.10.0 with: + registry: ghcr.io username: ${{ secrets.GCR_USERNAME }} password: ${{ secrets.GCR_TOKEN }} - registry: ghcr.io ########################### # Get the current release # @@ -102,21 +97,21 @@ jobs: | grep -E -o "v[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+")" \ >> "${GITHUB_ENV}" - ################ - # Docker cache # - ################ - - name: Cache Docker layers - uses: actions/cache@v2 + ######################### + # Update deployment API # + ######################### + - name: Start deployment + uses: bobheadxi/deployments@v0.6.1 + id: deployment with: - path: /tmp/.buildx-cache - key: ${{ runner.os }}-single-buildx-slim - restore-keys: | - ${{ runner.os }}-single-buildx + step: start + token: ${{ secrets.GITHUB_TOKEN }} + env: ${{ matrix.images.deployment-environment-identifier }} - ########################################### - # Build and Push containers to registries # - ########################################### - - name: Build and push - SLIM + ###################################### + # Build the docker image and push it # + ###################################### + - name: Build Docker image - ${{ matrix.images.image-id }} uses: docker/build-push-action@v2.8.0 with: context: . @@ -125,28 +120,16 @@ jobs: BUILD_DATE=${{ env.BUILD_DATE }} BUILD_REVISION=${{ github.sha }} BUILD_VERSION=${{ github.sha }} + load: true push: true tags: | - github/super-linter:slim-latest - github/super-linter:slim-v4 - "github/super-linter:slim-${{ env.RELEASE_VERSION }}" - ghcr.io/github/super-linter:slim-latest - ghcr.io/github/super-linter:slim-v4 - "ghcr.io/github/super-linter:slim-${{ env.RELEASE_VERSION }}" - target: final_slim - cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,dest=/tmp/.buildx-cache-new - - # Temp fix - # https://github.com/docker/build-push-action/issues/252 - # https://github.com/moby/buildkit/issues/1896 - ############# - # Fix Cache # - ############# - - name: Move cache - run: | - rm -rf /tmp/.buildx-cache - mv /tmp/.buildx-cache-new /tmp/.buildx-cache + github/super-linter:${{ matrix.images.container-image-id-prefix }}latest + github/super-linter:${{ matrix.images.container-image-id-prefix }}v4 + github/super-linter:${{ matrix.images.container-image-id-prefix }}${{ env.RELEASE_VERSION }} + ghcr.io/github/super-linter:${{ matrix.images.container-image-id-prefix }}latest + ghcr.io/github/super-linter:${{ matrix.images.container-image-id-prefix }}v4 + ghcr.io/github/super-linter:${{ matrix.images.container-image-id-prefix }}${{ env.RELEASE_VERSION }} + target: "${{ matrix.images.container-build-target }}" ######################### # Update Deployment API # diff --git a/Makefile b/Makefile index 1a6f3c8f..3ef2bbcd 100644 --- a/Makefile +++ b/Makefile @@ -76,11 +76,9 @@ DOCKERFILE := '' IMAGE := '' ifeq ($(IMAGE),slim) SUPER_LINTER_TEST_CONTINER_URL := "ghcr.io/github/super-linter:slim-test" - DOCKERFILE := "Dockerfile-slim" IMAGE := "slim" else SUPER_LINTER_TEST_CONTINER_URL := "ghcr.io/github/super-linter:test" - DOCKERFILE := "Dockerfile" IMAGE := "standard" endif