Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,20 @@ jobs:
tests:
name: Tests
uses: ./.github/workflows/test.yml
permissions:
contents: read

generate-build-id:
name: "Generate Build Id"
needs: [ tests ]
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
build-id: ${{ steps.generate.outputs.buildId }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does not actions/checkout@v4 take the latest version? I am just trying to understand why do we need to pull "checkout@11bd71901bbe5b1630ceea73d27597364c9af683" ? looks a bit scary :) ....

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To ensure a specific version is used and prevent the latest version being used in case of malicious updates or security issues with introduced dependencies.

Please see: Pin actions to specific versions


- id: generate
working-directory: ./scripts
Expand All @@ -32,9 +36,9 @@ jobs:
chmod +x ./create_build_id.sh

if [[ "${{ github.event_name }}" == "pull_request" ]]; then
GIT_BRANCH=PR
GIT_BRANCH=PR
elif [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == "refs/heads/main" ]]; then
GIT_BRANCH=main
GIT_BRANCH=main
fi

BUILD_ID=$(./create_build_id.sh $GIT_BRANCH ${{ github.run_number }} ${{ github.sha }})
Expand All @@ -44,12 +48,11 @@ jobs:
publish-docker-image:
name: "Publish docker image to ECR"
needs: [ generate-build-id ]

permissions:
contents: read
id-token: write
uses: ./.github/workflows/publish.yml
with:
directory: .
repository: nhais
build-context: .
build-id: ${{ needs.generate-build-id.outputs.build-id }}
secrets: inherit

Expand All @@ -63,10 +66,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Comment PR
uses: thollander/actions-comment-pull-request@v3
uses: thollander/actions-comment-pull-request@24bffb9b452ba05a4f3f77933840a6a841d1b32b # v3.0.1
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same here as above... doesn't "thollander/actions-comment-pull-request@v3" take the latest version ? or we need specifically v.3.0.1 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To ensure a specific version is used and prevent the latest version being used in case of malicious updates or security issues with introduced dependencies.

Please see: Pin actions to specific versions

with:
message: |
Images built and published to ECR using a Build Id of ${{ needs.generate-build-id.outputs.build-id }}
comment-tag: images-built
mode: upsert

mode: upsert
17 changes: 4 additions & 13 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@ name: Publish Workflow
on:
workflow_call:
inputs:
directory:
required: true
type: string
repository:
required: true
type: string
build-context:
required: true
type: string
build-id:
required: true
type: string
Expand All @@ -25,10 +16,10 @@ jobs:

steps:
- name: Checkout Repository
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
uses: aws-actions/configure-aws-credentials@b47578312673ae6fa5b5096b330d9fbac3d116df #4.2.1
with:
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/${{ secrets.AWS_ROLE_TO_ASSUME }}
role-session-name: gp2gp_github_action_build_workflow
Expand All @@ -37,11 +28,11 @@ jobs:
- name: Build Docker Image
run: |
DOCKER_REGISTRY="${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com"
DOCKER_TAG="$DOCKER_REGISTRY/${{ inputs.repository }}:${{ inputs.build-id }}"
DOCKER_TAG="$DOCKER_REGISTRY/nhais:${{ inputs.build-id }}"
echo "DOCKER_TAG=$DOCKER_TAG" >> $GITHUB_ENV

# Build Image
docker build -f ./${{ inputs.directory }}/Dockerfile -t $DOCKER_TAG ${{ inputs.build-context }}
docker build -f ./Dockerfile -t $DOCKER_TAG .

- name: Login to AWS ECR
run: |
Expand Down
25 changes: 12 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Setup Java 21
uses: actions/setup-java@v4
uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 #4.7.1
with:
java-version: 21
distribution: temurin
Expand All @@ -26,7 +26,7 @@ jobs:
cp -r ./build/reports ./artifacts

- name: Upload Artifacts
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 #v4.6.2
if: always()
with:
name: Unit Test Report
Expand All @@ -35,7 +35,7 @@ jobs:

- name: Test Job Summary
if: always()
uses: test-summary/action@v2
uses: test-summary/action@31493c76ec9e7aa675f1585d3ed6f1da69269a86 #v2.4.0
with:
paths: ./build/test-results/test/TEST-*.xml

Expand All @@ -47,10 +47,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Setup Java 21
uses: actions/setup-java@v4
uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 #4.7.1
with:
java-version: 21
distribution: temurin
Expand All @@ -65,7 +65,7 @@ jobs:
cp -r ./build/reports ./artifacts

- name: Upload Artifacts
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 #v4.6.2
if: always()
with:
name: Component Test Report
Expand All @@ -74,7 +74,7 @@ jobs:

- name: Test Job Summary
if: always()
uses: test-summary/action@v2
uses: test-summary/action@31493c76ec9e7aa675f1585d3ed6f1da69269a86 #v2.4.0
with:
paths: ./build/test-results/componentTest/TEST-*.xml

Expand All @@ -84,15 +84,14 @@ jobs:
integration_tests:
name: Integration Tests
permissions:
id-token: write
contents: read
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Setup Java
uses: actions/setup-java@v4
uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 #4.7.1
with:
java-version: 21
distribution: temurin
Expand Down Expand Up @@ -122,7 +121,7 @@ jobs:
cp -r ./logs ./artifacts

- name: Upload Artifacts
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 #v4.6.2
if: always()
with:
name: Integration Test Report & Docker Logs
Expand All @@ -131,7 +130,7 @@ jobs:

- name: Test Job Summary
if: always()
uses: test-summary/action@v2
uses: test-summary/action@31493c76ec9e7aa675f1585d3ed6f1da69269a86 #v2.4.0
with:
paths: ./build/test-results/integrationTest/TEST-*.xml

Expand Down