Skip to content

Commit 240764d

Browse files
authored
gha: rerun workflow after AWS creds injected (#61)
in the circleCI pipeline it does not run until makefile sets up webhooks but in GHA it runs as soon as zero create pushes the repo, during that time it has no AWS credentials, so it will always fail
1 parent d1a4acb commit 240764d

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

scripts/gha-setup.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,12 @@ curl -XPUT "https://api.github.com/repos/$GITHUB_ORG/$GITHUB_REPO/branches/$DEFA
3939
"restrictions": null
4040
}'
4141

42+
## Rerun github actions workflow, since the first time github action is ran there are no AWS credentials
43+
## so it will always fail, begining of this script we inject the AWS credentials, therefore now we can rerun the workflow
44+
MOST_RECENT_RUN_ID=$(curl -XGET --url "https://api.github.com/repos/${GITHUB_ORG}/${GITHUB_REPO}/actions/runs" \
45+
--header "Authorization: token $GITHUB_ACCESS_TOKEN" --header 'Content-Type: application/json' | jq -r ".workflow_runs[0].id")
46+
## Triggering the rerun
47+
curl -XPOST --url "https://api.github.com/repos/${GITHUB_ORG}/${GITHUB_REPO}/actions/runs/${MOST_RECENT_RUN_ID}/rerun" \
48+
--header "Authorization: token $GITHUB_ACCESS_TOKEN" --header 'Content-Type: application/json'
49+
4250
echo "Github actions environment variables setup successfully."

templates/.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,18 @@ jobs:
3434
build:
3535
needs: unit-test
3636
runs-on: ubuntu-latest
37+
env:
38+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
3739
steps:
3840
- uses: actions/checkout@v2
3941
- name: Set IMAGE_TAG as env
4042
run: |
4143
IMAGE_TAG=$(git rev-parse --short=7 ${{ github.sha }})
4244
echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_ENV
45+
- if: env.AWS_ACCESS_KEY_ID == null
46+
run: |
47+
echo "AWS Credentials not found, This is expected for the first run as the repo is provisioned then secrets are injected at a later step."
48+
exit 1
4349
- name: Configure AWS credentials
4450
uses: aws-actions/configure-aws-credentials@v1
4551
with:

0 commit comments

Comments
 (0)