diff --git a/.github/workflows/ci-cd-prod.yml b/.github/workflows/ci-cd-prod.yml index f25bcedf1..c9e68aa0d 100644 --- a/.github/workflows/ci-cd-prod.yml +++ b/.github/workflows/ci-cd-prod.yml @@ -69,15 +69,15 @@ jobs: store-infra-version: name: Store Latest Deployed Infra Version as GitHub Variable - runs-on: ubuntu-latest needs: [deploy-infra, get-current-version] if: ${{ needs.deploy-infra.result == 'success' }} - env: + uses: ./.github/workflows/workflow-store-github-env-variable.yml + with: + variable_name: LATEST_DEPLOYED_INFRA_VERSION + variable_value: ${{ needs.get-current-version.outputs.version }} + environment: prod + secrets: GH_TOKEN: ${{ secrets.RELEASE_VERSION_STORAGE_PAT }} - steps: - - name: Set GitHub variable for latest deployed infra version - run: | - gh variable set LATEST_DEPLOYED_INFRA_VERSION --body "${{ needs.get-current-version.outputs.version }}" --env prod --repo ${{ github.repository }} dry-run-deploy-apps: name: Dry run deploy apps to prod @@ -129,15 +129,15 @@ jobs: store-apps-version: name: Store Latest Deployed Apps Version as GitHub Variable - runs-on: ubuntu-latest needs: [deploy-apps, get-current-version] if: ${{ needs.deploy-apps.result == 'success' }} - env: + uses: ./.github/workflows/workflow-store-github-env-variable.yml + with: + variable_name: LATEST_DEPLOYED_APPS_VERSION + variable_value: ${{ needs.get-current-version.outputs.version }} + environment: prod + secrets: GH_TOKEN: ${{ secrets.RELEASE_VERSION_STORAGE_PAT }} - steps: - - name: Set GitHub variable for latest deployed apps version - run: | - gh variable set LATEST_DEPLOYED_APPS_VERSION --body "${{ needs.get-current-version.outputs.version }}" --env prod --repo ${{ github.repository }} deploy-slack-notifier: name: Deploy slack notifier (prod) diff --git a/.github/workflows/ci-cd-staging.yml b/.github/workflows/ci-cd-staging.yml index adc7d558c..2ff5247e3 100644 --- a/.github/workflows/ci-cd-staging.yml +++ b/.github/workflows/ci-cd-staging.yml @@ -50,15 +50,15 @@ jobs: store-infra-version: name: Store Latest Deployed Infra Version as GitHub Variable - runs-on: ubuntu-latest needs: [deploy-infra, get-current-version] if: ${{ needs.deploy-infra.result == 'success' }} - env: + uses: ./.github/workflows/workflow-store-github-env-variable.yml + with: + variable_name: LATEST_DEPLOYED_INFRA_VERSION + variable_value: ${{ needs.get-current-version.outputs.version }} + environment: staging + secrets: GH_TOKEN: ${{ secrets.RELEASE_VERSION_STORAGE_PAT }} - steps: - - name: Set GitHub variable for latest deployed infra version - run: | - gh variable set LATEST_DEPLOYED_INFRA_VERSION --body "${{ needs.get-current-version.outputs.version }}" --env staging --repo ${{ github.repository }} publish: name: Build and publish docker images @@ -95,15 +95,15 @@ jobs: store-apps-version: name: Store Latest Deployed Apps Version as GitHub Variable - runs-on: ubuntu-latest needs: [deploy-apps, get-current-version] if: ${{ needs.deploy-apps.result == 'success' }} - env: + uses: ./.github/workflows/workflow-store-github-env-variable.yml + with: + variable_name: LATEST_DEPLOYED_APPS_VERSION + variable_value: ${{ needs.get-current-version.outputs.version }} + environment: staging + secrets: GH_TOKEN: ${{ secrets.RELEASE_VERSION_STORAGE_PAT }} - steps: - - name: Set GitHub variable for latest deployed apps version - run: | - gh variable set LATEST_DEPLOYED_APPS_VERSION --body "${{ needs.get-current-version.outputs.version }}" --env staging deploy-slack-notifier: name: Deploy slack notifier (staging) diff --git a/.github/workflows/ci-cd-yt01.yml b/.github/workflows/ci-cd-yt01.yml index d3a994af9..1dee21b98 100644 --- a/.github/workflows/ci-cd-yt01.yml +++ b/.github/workflows/ci-cd-yt01.yml @@ -61,15 +61,15 @@ jobs: store-infra-version: name: Store Latest Deployed Infra Version as GitHub Variable - runs-on: ubuntu-latest needs: [deploy-infra, get-current-version] if: ${{ needs.deploy-infra.result == 'success' }} - env: + uses: ./.github/workflows/workflow-store-github-env-variable.yml + with: + variable_name: LATEST_DEPLOYED_INFRA_VERSION + variable_value: ${{ needs.get-current-version.outputs.version }} + environment: yt01 + secrets: GH_TOKEN: ${{ secrets.RELEASE_VERSION_STORAGE_PAT }} - steps: - - name: Set GitHub variable for latest deployed infra version - run: | - gh variable set LATEST_DEPLOYED_INFRA_VERSION --body "${{ needs.get-current-version.outputs.version }}" --env yt01 --repo ${{ github.repository }} deploy-apps: name: Deploy apps to yt01 @@ -97,15 +97,15 @@ jobs: store-apps-version: name: Store Latest Deployed Apps Version as GitHub Variable - runs-on: ubuntu-latest needs: [deploy-apps, get-current-version] if: ${{ needs.deploy-apps.result == 'success' }} - env: + uses: ./.github/workflows/workflow-store-github-env-variable.yml + with: + variable_name: LATEST_DEPLOYED_APPS_VERSION + variable_value: ${{ needs.get-current-version.outputs.version }} + environment: yt01 + secrets: GH_TOKEN: ${{ secrets.RELEASE_VERSION_STORAGE_PAT }} - steps: - - name: Set GitHub variable for latest deployed apps version - run: | - gh variable set LATEST_DEPLOYED_APPS_VERSION --body "${{ needs.get-current-version.outputs.version }}" --env yt01 --repo ${{ github.repository }} deploy-slack-notifier: name: Deploy slack notifier (yt01) diff --git a/.github/workflows/workflow-store-github-env-variable.yml b/.github/workflows/workflow-store-github-env-variable.yml new file mode 100644 index 000000000..387888e2b --- /dev/null +++ b/.github/workflows/workflow-store-github-env-variable.yml @@ -0,0 +1,39 @@ +name: Store GitHub Environment Variable + +on: + workflow_call: + inputs: + variable_name: + required: true + type: string + description: "Name of the variable to store" + variable_value: + required: true + type: string + description: "Value to store in the variable" + environment: + required: true + type: string + description: "GitHub environment to store the variable in" + secrets: + GH_TOKEN: + required: true + description: "GitHub token with permission to set variables" + +jobs: + store-variable: + name: Store GitHub Environment Variable + runs-on: ubuntu-latest + environment: ${{ inputs.environment }} + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set GitHub variable + env: + GH_TOKEN: ${{ secrets.GH_TOKEN }} + run: | + gh variable set ${{ inputs.variable_name }} \ + --body "${{ inputs.variable_value }}" \ + --env ${{ inputs.environment }} \ + --repo ${{ github.repository }}