From cd613d2576bf94fd9e9441d9c0fb463da4bfdc87 Mon Sep 17 00:00:00 2001 From: Paul Gilber Date: Sat, 4 Nov 2023 04:59:52 +0000 Subject: [PATCH] replace VERSION and PROJECT with github-env-vars-action provided variables --- .github/workflows/code-scan-sonarcloud.yml | 16 ++++----------- .github/workflows/merge-cleanup.yml | 23 ++++++++-------------- .github/workflows/release.yml | 4 ---- 3 files changed, 12 insertions(+), 31 deletions(-) diff --git a/.github/workflows/code-scan-sonarcloud.yml b/.github/workflows/code-scan-sonarcloud.yml index 88e7379..638ecf7 100644 --- a/.github/workflows/code-scan-sonarcloud.yml +++ b/.github/workflows/code-scan-sonarcloud.yml @@ -33,16 +33,8 @@ jobs: pull-requests: read # Allow SonarCloud to get pull request details environment: sonarcloud # Use `sonarcloud` repository environment steps: - # Workaround for the absence of github.branch_name - # Setting an environment variable: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable - - name: Set VERSION - if: github.head_ref != '' - run: | - echo "VERSION=${{ github.head_ref }}" >> $GITHUB_ENV - - name: Set VERSION - if: github.head_ref == '' - run: | - echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV + # Workaround for the absence of github.branch_name, use github-env-vars-action to define useful environment variables not available by default + - uses: FranzDiebold/github-env-vars-action@v2 # https://github.com/marketplace/actions/github-environment-variables-action - name: Checkout repository uses: actions/checkout@v4 # https://github.com/marketplace/actions/checkout @@ -91,7 +83,7 @@ jobs: # run: | # mvn -B verify \ # org.sonarsource.scanner.npm:sonar-npm-plugin:sonar \ - # -Drevision=${{ env.VERSION }} \ + # -Drevision=${{ env.CI_ACTION_REF_NAME }} \ # -Dsonar.organization=${{ vars.SONAR_ORGANIZATION }} \ # -Dsonar.projectKey=${{ vars.SONAR_PROJECT_KEY }} \ # -Dmaven.test.skip=true \ @@ -111,7 +103,7 @@ jobs: # run: | # mvn -B verify \ # org.sonarsource.scanner.npm:sonar-npm-plugin:sonar \ - # -Drevision=${{ env.VERSION }} \ + # -Drevision=${{ env.CI_ACTION_REF_NAME }} \ # -Dsonar.organization=${{ vars.SONAR_ORGANIZATION }} \ # -Dsonar.projectKey=${{ vars.SONAR_PROJECT_KEY }} \ # -Dsonar.pullrequest.provider=GitHub \ diff --git a/.github/workflows/merge-cleanup.yml b/.github/workflows/merge-cleanup.yml index 9fc22d4..e1a2be7 100644 --- a/.github/workflows/merge-cleanup.yml +++ b/.github/workflows/merge-cleanup.yml @@ -20,10 +20,6 @@ on: # Set Workflow-level permissions: https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs permissions: {} # This Workflow does not require any permission -# Set Workflow-level environment variables -env: - PROJECT: demoapp-frontend - jobs: output-information: runs-on: ubuntu-latest @@ -45,23 +41,20 @@ jobs: # - name: Skopeo Delete Image # id: skopeo-delete # run: | - # skopeo delete docker://${{ vars.DOCKER_REGISTRY_URL }}/${{ vars.DOCKER_REPOSITORY }}/${{ env.PROJECT }}:${{ env.VERSION }} + # skopeo delete docker://${{ vars.DOCKER_REGISTRY_URL }}/${{ vars.DOCKER_REPOSITORY }}/${{ env.CI_REPOSITORY_NAME }}:${{ env.CI_ACTION_REF_NAME }} # Regctl allows image tag deletion which is allowed by Docker Hub docker-hub-regctl: runs-on: ubuntu-latest environment: docker-hub steps: - # Workaround for the absence of github.branch_name - # Setting an environment variable: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable - - name: Set VERSION - if: github.head_ref != '' - run: | - echo "VERSION=${{ github.head_ref }}" >> $GITHUB_ENV - - name: Set VERSION - if: github.head_ref == '' + # Workaround for the absence of github.branch_name, use github-env-vars-action to define useful environment variables not available by default + - uses: FranzDiebold/github-env-vars-action@v2 # https://github.com/marketplace/actions/github-environment-variables-action + + # Set Complete Container Image URL + - name: Set CONTAINER_IMAGE_URL run: | - echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV + echo "CONTAINER_IMAGE_URL=${{ vars.DOCKER_REGISTRY_URL }}/${{ vars.DOCKER_REPOSITORY }}/${{ env.CI_REPOSITORY_NAME }}:${{ env.CI_ACTION_REF_NAME }}" >> $GITHUB_ENV # Install regctl: https://github.com/regclient/regclient - name: Install regctl @@ -75,4 +68,4 @@ jobs: --pass ${{ secrets.DOCKER_REGISTRY_PASSWORD }} \ - name: regctl Delete Image Tag run: | - ./regctl tag delete ${{ vars.DOCKER_REGISTRY_URL }}/${{ vars.DOCKER_REPOSITORY }}/${{ env.PROJECT }}:${{ env.VERSION }} + ./regctl tag delete ${{ vars.DOCKER_REGISTRY_URL }}/${{ vars.DOCKER_REPOSITORY }}/${{ env.CI_REPOSITORY_NAME }}:${{ env.CI_ACTION_REF_NAME }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2a75251..21faef2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,10 +12,6 @@ on: tags: - 'v*' # When a tag starting with `v` is created e.g. v1.0.0 -# Set Workflow-level environment variables -env: - PROJECT: demoapp-frontend - jobs: push_to_registries: name: Push Container image to multiple registries