Skip to content

Commit bbb3abf

Browse files
authored
gha: rerun workflow after AWS creds injected (#22)
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 fe3ed71 commit bbb3abf

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
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
@@ -33,12 +33,18 @@ jobs:
3333
build:
3434
needs: unit-test
3535
runs-on: ubuntu-latest
36+
env:
37+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
3638
steps:
3739
- uses: actions/checkout@v2
3840
- name: Set IMAGE_TAG as env
3941
run: |
4042
IMAGE_TAG=$(git rev-parse --short=7 ${{ github.sha }})
4143
echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_ENV
44+
- if: env.AWS_ACCESS_KEY_ID == null
45+
run: |
46+
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."
47+
exit 1
4248
- name: Configure AWS credentials
4349
uses: aws-actions/configure-aws-credentials@v1
4450
with:

templates/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
},
88
"main": <%if eq (index .Params `apiType`) "rest" %>"src/app.js", <% else %>"src/graphql.js",<% end %>
99
"scripts": {
10-
"test": "echo \"Error: no test specified\" && exit 1",
10+
"test": "echo \"Error: no test specified\" && exit 0",
1111
"lint": "eslint src",
1212
"lint:fix": "eslint src --fix",
1313
"format": "prettier --write '**/*.js'"

0 commit comments

Comments
 (0)