Skip to content

Commit 93aa3f3

Browse files
VIA-180 AS Add create release step in publish workflow
VIA-180 AS Add logic to copy artefact from artefacts/ to tags/ and rename in Dev env VIA-180 AS Configure aws creds in publish workflow VIA-180 AS/AJ Update name for build, upload metadata along with builds, update publish workflow VIA-180 AS Fix typo in build stage VIA-180 AS Add env vars to publish workflow VIA-180 AS Add permissions to get id token for aws connection VIA-180 AS Give write permissions to Github to create release VIA-180 AS Update iam policy json, upload workflow url alongside artefacts
1 parent 037aa74 commit 93aa3f3

File tree

3 files changed

+60
-30
lines changed

3 files changed

+60
-30
lines changed

.github/workflows/cicd-2-publish.yaml

Lines changed: 54 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ on:
55
tags:
66
- 'v*'
77

8+
env:
9+
AWS_REGION: eu-west-2
10+
AWS_S3_PACKAGE_BUCKET: vaccinations-app-github-dev
11+
812
jobs:
913
metadata:
1014
name: "Set CI/CD metadata"
@@ -48,36 +52,59 @@ jobs:
4852
runs-on: ubuntu-latest
4953
needs: [metadata]
5054
timeout-minutes: 3
55+
permissions:
56+
id-token: write
57+
contents: write
5158
steps:
5259
- name: "Log Tag"
5360
env:
5461
TAG: ${{ github.ref_name }}
5562
run: |
5663
echo "TAG=${TAG}"
57-
# - name: "Checkout code"
58-
# uses: actions/checkout@v4
59-
# - name: "Get the artefacts"
60-
# run: |
61-
# echo "Getting the artefacts created by the build stage ..."
62-
# # TODO: Use either action/cache or action/upload-artifact
63-
# - name: "Create release"
64-
# id: create_release
65-
# uses: actions/create-release@v1
66-
# env:
67-
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
68-
# with:
69-
# tag_name: ${{ needs.metadata.outputs.version }}
70-
# release_name: Release ${{ needs.metadata.outputs.version }}
71-
# body: |
72-
# Release of ${{ needs.metadata.outputs.version }}
73-
# draft: false
74-
# prerelease: false
75-
# - name: "Upload release asset"
76-
# uses: actions/upload-release-asset@v1
77-
# env:
78-
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
79-
# with:
80-
# upload_url: "${{ steps.create_release.outputs.upload_url }}"
81-
# asset_path: ./*
82-
# asset_name: repository-template-${{ needs.metadata.outputs.version }}.tar.gz
83-
# asset_content_type: "application/gzip"
64+
- name: "Checkout code"
65+
uses: actions/checkout@v4
66+
- name: "Get commit history"
67+
id: commits
68+
run: |
69+
TAG="${{ github.ref_name }}"
70+
PREVIOUS_TAG=$(git describe --tags --abbrev=0 "${TAG}^" 2>/dev/null || echo "")
71+
if [[ -z "$PREVIOUS_TAG" ]]; then
72+
echo "No previous tag found. Listing all commits."
73+
COMMIT_RANGE=$(git log --pretty=format:"- %s (%h)")
74+
else
75+
echo "Listing commits between $PREVIOUS_TAG and $TAG."
76+
COMMIT_RANGE=$(git log --pretty=format:"- %s (%h)" "${PREVIOUS_TAG}..${TAG}")
77+
fi
78+
echo "commits=$COMMIT_RANGE" >> "$GITHUB_OUTPUT"
79+
- name: "Create release"
80+
uses: actions/create-release@v1
81+
env:
82+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
83+
with:
84+
tag_name: ${{ github.ref_name }}
85+
release_name: Release ${{ github.ref_name }}
86+
body: ${{ steps.commits.outputs.commits }}
87+
draft: false
88+
prerelease: false
89+
- name: "Get short SHA"
90+
id: sha
91+
run: echo "short_sha=$(echo ${GITHUB_SHA} | cut -c1-7)" >> $GITHUB_OUTPUT
92+
- name: "Configure AWS credentials"
93+
uses: aws-actions/configure-aws-credentials@v4
94+
with:
95+
role-session-name: GitHubActionsSession
96+
role-to-assume: ${{ secrets.IAM_ROLE }}
97+
aws-region: ${{ env.AWS_REGION }}
98+
- name: "Copy artefact"
99+
id: copy-artefact
100+
run: |
101+
TAG=${{ github.ref_name }}
102+
SHORT_SHA=${{ steps.sha.outputs.short_sha }}
103+
104+
if aws s3 ls "s3://vaccinations-app-github-dev/artefacts/$SHORT_SHA/" | grep .; then
105+
aws s3 cp "s3://vaccinations-app-github-dev/artefacts/$SHORT_SHA" "s3://vaccinations-app-github-dev/tags/$TAG/" --recursive
106+
else
107+
echo "Error: No matching folder found for SHA: $SHORT_SHA"
108+
exit 1
109+
fi
110+

.github/workflows/stage-3-build.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ jobs:
5656
- name: "Get the release version"
5757
id: strip-branch-name
5858
run: |
59-
release_version=$(echo "${{ steps.date.outputs.today_date }}\
60-
-${{ github.run_id }}_${{ github.run_number }}\
61-
_${{ github.run_attempt }}-${{ steps.sha.outputs.short_sha }}")
59+
release_version=${{ steps.sha.outputs.short_sha }}
6260
echo "Building release version $release_version"
6361
echo "RELEASE_VERSION=$release_version" >> $GITHUB_ENV
6462
- name: "Build OpenNext Package"
@@ -72,6 +70,9 @@ jobs:
7270
run: zip -r open-next.zip .open-next/
7371
- name: "Zip Lambda Package"
7472
run: zip -j -r lambda.zip dist/
73+
- name: "Create workflow URL"
74+
run: |
75+
echo "Workflow URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" >> workflow.log
7576
- name: "Configure AWS credentials"
7677
uses: aws-actions/configure-aws-credentials@v4
7778
with:
@@ -82,3 +83,4 @@ jobs:
8283
run: |
8384
aws s3 cp open-next.zip "s3://${AWS_S3_PACKAGE_BUCKET}/artefacts/${RELEASE_VERSION}/open-next.zip"
8485
aws s3 cp lambda.zip "s3://${AWS_S3_PACKAGE_BUCKET}/artefacts/${RELEASE_VERSION}/lambda.zip"
86+
aws s3 cp workflow.log "s3://${AWS_S3_PACKAGE_BUCKET}/artefacts/${RELEASE_VERSION}/workflow.log"

infrastructure/github-iam-role-policy.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
"s3:GetEncryptionConfiguration",
106106
"s3:GetLifecycleConfiguration",
107107
"s3:GetObject",
108+
"s3:GetObjectTagging",
108109
"s3:GetReplicationConfiguration",
109110
"s3:ListBucket",
110111
"s3:PutBucketPolicy",

0 commit comments

Comments
 (0)