Skip to content

Commit

Permalink
Checkout only on exact parent commit sha in workflow-triggered workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangabriele committed Feb 28, 2024
1 parent b9180ab commit 37cfb2a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
24 changes: 14 additions & 10 deletions .github/workflows/application_deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,31 @@ concurrency:
jobs:
push_to_registry:
name: Push to registry
if: ${{ !contains(github.ref, 'dependabot') }}
if: ${ github.event.workflow_run.conclusion == 'success' && !contains(github.ref, 'dependabot') }}
runs-on: ubuntu-22.04
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
steps:
- name: Check status of required workflows
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
APLICATION_UNITS_TESTS_WORKFLOW_CONCLUSION=$(gh api repos/MTES-MCT/monitorfish/actions/runs --jq '.workflow_runs[] | select(.name=="Application Unit Tests").conclusion' | head -n 1)
APPLICATION_E2E_TESTS_WORKFLOW_CONCLUSION=$(gh api repos/MTES-MCT/monitorfish/actions/runs --jq '.workflow_runs[] | select(.name=="Application E2E Tests").conclusion' | head -n 1)
if [[ "$APLICATION_UNITS_TESTS_WORKFLOW_CONCLUSION" != "success" || "$APPLICATION_E2E_TESTS_WORKFLOW_CONCLUSION" != "success" ]]; then
exit 1
fi
- name: Check Unit Tests status
id: check_unit_tests_status
uses: LASER-Yi/[email protected]
with:
branch: ${{ github.event.workflow_run.head_branch }}
token: ${{ secrets.GITHUB_TOKEN }}
workflow: application_unit_tests.yml

- name: Checkout
if: ${{ steps.check-check_unit_tests_status.outputs.conclusion == 'success' }}
uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_commit.id }}

- name: Set version and environment profile
if: ${{ steps.check-check_unit_tests_status.outputs.conclusion == 'success' }}
uses: ./.github/actions/set-version-and-environment-profile

- name: Download image
if: ${{ steps.check-check_unit_tests_status.outputs.conclusion == 'success' }}
uses: ishworkh/[email protected]
with:
commit_sha: ${{ github.event.workflow_run.head_commit.id }}
Expand All @@ -46,6 +49,7 @@ jobs:
workflow: "Application Build"

- name: Push docker image to registry
if: ${{ steps.check-check_unit_tests_status.outputs.conclusion == 'success' }}
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${GITHUB_ACTOR} --password-stdin
make docker-tag
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/application_e2e_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_commit.id }}

- name: Set version and environment profile
uses: ./.github/actions/set-version-and-environment-profile
Expand Down Expand Up @@ -108,6 +110,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_commit.id }}

- name: Set version and environment profile
uses: ./.github/actions/set-version-and-environment-profile
Expand Down

0 comments on commit 37cfb2a

Please sign in to comment.