2626 with :
2727 role-to-assume : arn:aws:iam::677043464939:role/GitHubAction-AssumeRoleWithAction
2828 role-session-name : GitHub_to_AWS_via_FederatedOIDC
29- aws-region : us-east-1
29+ aws-region : ${{ secrets.AWS_REGION }}
3030 # Hello from AWS: WhoAmI
3131 - name : Sts GetCallerIdentity
3232 run : |
5858
5959 # Add a comment with the S3 preview link
6060 PR_NUMBER=${{ github.event.pull_request.number }}
61- COMMENT="Preview your changes at: http://het-rnd-bucket.s3-website-us-east-1.amazonaws.com/MergeRequest /${PR_NUMBER}/index.html"
61+ COMMENT="Preview your changes at: http://${{ secrets.S3_BUCKET_NAME }}/mergeRequest /${PR_NUMBER}/index.html"
6262 curl -X POST \
6363 -H "Authorization: token $GITHUB_TOKEN" \
6464 -H "Accept: application/vnd.github+json" \
@@ -115,60 +115,66 @@ jobs:
115115 deploy_to_test :
116116 needs : convert_md_to_html
117117 runs-on : ubuntu-latest
118- if : github.ref != 'refs/heads/main' # Run for non-main branches
118+ if : github.event_name == 'pull_request' && github. ref != 'refs/heads/main' # Run for non-main branches
119119 steps :
120120 - name : Checkout code
121121 uses : actions/checkout@v3
122122
123- - name : Get PR number from GitHub API
124- id : pr
125- run : |
126- PR_API_URL="https://api.github.com/repos/${GITHUB_REPOSITORY}/commits/${GITHUB_SHA}/pulls"
127- PR_NUMBER=$(curl -s -H "Accept: application/vnd.github.groot-preview+json" \
128- -H "Authorization: Bearer $GITHUB_TOKEN" \
129- $PR_API_URL | jq '.[0].number')
130- echo "pr_number=$PR_NUMBER"
131- env :
132- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
123+ # - name: Get PR number from GitHub API
124+ # id: pr
125+ # run: |
126+ # PR_API_URL="https://api.github.com/repos/${GITHUB_REPOSITORY}/commits/${GITHUB_SHA}/pulls"
127+ # PR_NUMBER=$(curl -s -H "Accept: application/vnd.github.groot-preview+json" \
128+ # -H "Authorization: Bearer $GITHUB_TOKEN" \
129+ # $PR_API_URL | jq '.[0].number')
130+ # echo "pr_number=$PR_NUMBER"
131+ # env:
132+ # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
133133
134134 - name : Download artifacts
135135 uses : actions/download-artifact@v4
136136 with :
137137 name : site
138138 path : site
139- - name : Configure AWS credentials
140- uses : aws-actions/configure-aws-credentials@v4
139+ # - name: Configure AWS credentials
140+ # uses: aws-actions/configure-aws-credentials@v4
141+ # with:
142+ # aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
143+ # aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
144+ # aws-region: us-east-1 # change if needed
145+ - name : configure aws credentials
146+ uses : aws-actions/configure-aws-credentials@v1.7.0
141147 with :
142- aws-access-key-id : ${{ secrets.AWS_ACCESS_KEY_ID }}
143- aws-secret-access-key : ${{ secrets.AWS_SECRET_ACCESS_KEY }}
144- aws-region : us-east-1 # change if needed
145-
148+ role-to-assume : arn:aws:iam::677043464939:role/GitHubAction-AssumeRoleWithAction
149+ role-session-name : GitHub_to_AWS_via_FederatedOIDC
150+ aws-region : ${{ secrets.AWS_REGION }}
146151 - name : Deploy to Test Environment
147152 env :
148153 S3_BUCKET_NAME : ${{ secrets.S3_BUCKET_NAME }}
149- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
154+ PR_NUMBER : ${{ github.event.pull_request.number }}
155+ # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
150156 run : |
151- PR_API_URL="https://api.github.com/repos/${GITHUB_REPOSITORY}/commits/${GITHUB_SHA}/pulls"
152- PR_NUMBER=$(curl -s -H "Accept: application/vnd.github.groot-preview+json" \
153- -H "Authorization: Bearer $GITHUB_TOKEN" \
154- $PR_API_URL | jq '.[0].number')
157+ # PR_API_URL="https://api.github.com/repos/${GITHUB_REPOSITORY}/commits/${GITHUB_SHA}/pulls"
158+ # PR_NUMBER=$(curl -s -H "Accept: application/vnd.github.groot-preview+json" \
159+ # -H "Authorization: Bearer $GITHUB_TOKEN" \
160+ # $PR_API_URL | jq '.[0].number')
155161 echo "pr_number while deploying =$PR_NUMBER"
156162 pwd
157- # aws s3 ls
158- # aws s3 sync site/ s3://$S3_BUCKET_NAME/test
159- # aws s3 sync site/ s3://$S3_BUCKET_NAME/MergeRequest /$PR_NUMBER
163+ aws s3 ls
164+ aws s3 sync site/ s3://$S3_BUCKET_NAME/test
165+ aws s3 sync site/ s3://$S3_BUCKET_NAME/mergeRequest /$PR_NUMBER
160166
161167 # Deployment to production folder in S3 bucket
162168 deploy_to_production :
163169 runs-on : ubuntu-latest
164170 if : github.ref == 'refs/heads/main' # Run for main branch
165171 steps :
166- - name : Configure AWS credentials
167- uses : aws-actions/configure-aws-credentials@v4
172+ - name : configure aws credentials
173+ uses : aws-actions/configure-aws-credentials@v1.7.0
168174 with :
169- aws-access-key-id : ${{ secrets.AWS_ACCESS_KEY_ID }}
170- aws-secret-access-key : ${{ secrets.AWS_SECRET_ACCESS_KEY }}
171- aws-region : us-east-1 # change if needed
175+ role-to-assume : arn:aws:iam::677043464939:role/GitHubAction-AssumeRoleWithAction
176+ role-session-name : GitHub_to_AWS_via_FederatedOIDC
177+ aws-region : ${{ secrets.AWS_REGION }}
172178 - name : Get PR number from GitHub API
173179 id : pr
174180 run : |
@@ -193,4 +199,4 @@ jobs:
193199 -H "Authorization: Bearer $GITHUB_TOKEN" \
194200 $PR_API_URL | jq '.[0].number')
195201 echo "after pr_number=$PR_NUMBER"
196- aws s3 sync s3://$S3_BUCKET_NAME/MergeRequest /$PR_NUMBER s3://$S3_BUCKET_NAME/production/
202+ aws s3 sync s3://$S3_BUCKET_NAME/mergeRequest /$PR_NUMBER s3://$S3_BUCKET_NAME/production/
0 commit comments