Skip to content

Add PR Preview actions #381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: development
Choose a base branch
from
29 changes: 29 additions & 0 deletions .github/workflows/preview-close.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: 'Amplify PR Closed'
on:
pull_request_target:
types: [closed]

jobs:
delete:
permissions:
id-token: write
if: contains(github.event.pull_request.labels.*.name, 'Preview Environment')
runs-on: ubuntu-latest
steps:
- name: configure AWS credentials
id: creds
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: us-east-2
role-to-assume: ${{ secrets.AWS_GITHUB_ACTIONS_ROLE }}
output-credentials: true
- name: cleanup PR preview branch
uses: mikehosmar/amplify-preview-actions@sed-replace-all
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you elaborate on what this dependency is?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is an action which contains the amplify commands to create and close branches.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I just meant to highlight the "uses: mikehosmar/amplify-preview-actions@sed-replace-all" line. I wasn't sure if that was a link to something in your personal account somewhere and, if so, should we move it to a more accessible location.

Copy link
Member Author

Choose a reason for hiding this comment

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

I did Fork the action to my account to make sure we have a copy which we control. We could fork it to clearpathrobotics if you would like.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, it would be preferable to fork to clearpathrobotics.

with:
branch_name: ${{ github.head_ref }}
amplify_command: delete
env:
AWS_ACCESS_KEY_ID: ${{ steps.creds.outputs.aws-access-key-id }}
AWS_SECRET_ACCESS_KEY: ${{ steps.creds.outputs.aws-secret-access-key }}
AmplifyAppId: ${{ secrets.AMPLIFY_APP_ID }}
AWS_REGION: 'us-east-2'
63 changes: 63 additions & 0 deletions .github/workflows/preview-rc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Amplify Preview Enable

on:
create:
delete:

jobs:
deploy-on-create:
if: github.event_name == 'create' && startsWith(github.event.ref, 'rc/')
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- name: configure AWS credentials
id: creds
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: us-east-2
role-to-assume: ${{ secrets.AWS_GITHUB_ACTIONS_ROLE }}
output-credentials: true
- name: Enable Amplify Preview
uses: mikehosmar/amplify-preview-actions@sed-replace-all
with:
branch_name: ${{ github.event.ref }}
amplify_command: deploy
env:
AWS_ACCESS_KEY_ID: ${{ steps.creds.outputs.aws-access-key-id }}
AWS_SECRET_ACCESS_KEY: ${{ steps.creds.outputs.aws-secret-access-key }}
AmplifyAppId: ${{ secrets.AMPLIFY_APP_ID }}
EnablePreview: true
AWS_REGION: 'us-east-2'

cleanup-on-delete:
if: github.event_name == 'delete' && (startsWith(github.event.ref, 'rc/') || startsWith(github.head_ref, 'rc/'))
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- name: Get ref for pull_request
run: |
echo "BRANCH_NAME=${{ github.head_ref }}" >> $GITHUB_ENV
if: github.event_name == 'pull_request_target'
- name: Get ref for delete
run: |
echo "BRANCH_NAME=${{ github.event.ref }}" >> $GITHUB_ENV
if: github.event_name == 'delete'
- name: configure AWS credentials
id: creds
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: us-east-2
role-to-assume: ${{ secrets.AWS_GITHUB_ACTIONS_ROLE }}
output-credentials: true
- name: cleanup PR preview branch
uses: mikehosmar/amplify-preview-actions@sed-replace-all
with:
branch_name: ${{ env.BRANCH_NAME }}
amplify_command: delete
env:
AWS_ACCESS_KEY_ID: ${{ steps.creds.outputs.aws-access-key-id }}
AWS_SECRET_ACCESS_KEY: ${{ steps.creds.outputs.aws-secret-access-key }}
AmplifyAppId: ${{ secrets.AMPLIFY_APP_ID }}
AWS_REGION: 'us-east-2'
33 changes: 33 additions & 0 deletions .github/workflows/preview.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Amplify Preview

on:
pull_request:
types: [labeled]

jobs:
deploy:
if: contains(github.event.label.name, 'Preview Environment')
runs-on: ubuntu-latest
continue-on-error: true
permissions:
id-token: write
pull-requests: write
steps:
- name: configure AWS credentials
id: creds
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: us-east-2
role-to-assume: ${{ secrets.AWS_GITHUB_ACTIONS_ROLE }}
output-credentials: true
- name: deploy PR preview
uses: mikehosmar/amplify-preview-actions@sed-replace-all
with:
branch_name: ${{ github.head_ref }}
amplify_command: deploy
env:
AWS_ACCESS_KEY_ID: ${{ steps.creds.outputs.aws-access-key-id }}
AWS_SECRET_ACCESS_KEY: ${{ steps.creds.outputs.aws-secret-access-key }}
AmplifyAppId: ${{ secrets.AMPLIFY_APP_ID }}
AWS_REGION: 'us-east-2'
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}