Last active
February 24, 2025 19:14
-
-
Save chris/c373694bc954c068df140d43f14d8456 to your computer and use it in GitHub Desktop.
GitHub action to add AWS Amplify URL to PR comments and Slack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Amplify Branch URL notifications | |
on: | |
create: | |
pull_request: | |
types: [opened] | |
jobs: | |
add_url_comment: | |
name: Add Amplify deploy URL to PR comments and Slack | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set branch name | |
if: ${{ github.event_name == 'create' }} | |
run: echo "::set-env name=BRANCH_NAME::${GITHUB_REF#refs/heads/}" | |
- name: Set domain name for releases | |
if: ${{ github.event_name == 'create' && contains(github.ref, 'release/') }} | |
run: echo "::set-env name=DOMAIN_NAME::custom-prod-domain.com" | |
- name: Set domain name for non-releases | |
if: ${{ github.event_name == 'create' && !contains(github.ref, 'release/') }} | |
run: echo "::set-env name=DOMAIN_NAME::custom-test-domain.com" | |
- name: Slack notification for new production deploy version | |
if: ${{ github.event_name == 'create' && contains(github.ref, 'tags') }} | |
env: | |
SLACK_WEBHOOK: ${{ secrets.SLACK_DEV_NOTICES_WEBHOOK }} | |
run: 'curl -X POST -H "Content-type: application/json" --data "{\"text\":\"New production deploy, v${BRANCH_NAME#refs/tags/}: https://${DOMAIN_NAME}\"}" ${SLACK_WEBHOOK}' | |
- name: Slack notification for branch creation | |
if: ${{ github.event_name == 'create' && !contains(github.ref, 'tags') }} | |
env: | |
SLACK_WEBHOOK: ${{ secrets.SLACK_DEV_NOTICES_WEBHOOK }} | |
run: 'curl -X POST -H "Content-type: application/json" --data "{\"text\":\"New Amplify branch URL: https://${BRANCH_NAME//[\/\.]/-}.${DOMAIN_NAME}\"}" ${SLACK_WEBHOOK}' | |
- name: Add PR comment | |
if: ${{ github.event_name == 'pull_request' }} | |
env: | |
GH_API_TOKEN: ${{ secrets.GH_ACTIONS_API_TOKEN }} | |
run: 'curl -s -H "Authorization: token ${GH_API_TOKEN}" -X POST -d "{\"body\": \"Amplify URL: https://${GITHUB_HEAD_REF//[\/\.]/-}.custom-test-domain.com\"}" "https://api.github.com/repos/YOUORYOURORG/REPONAME/issues/${GITHUB_REF//[a-z\/]/}/comments"' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment