Skip to content

Commit 114960f

Browse files
authored
link PR (#40)
1 parent 30a69a8 commit 114960f

File tree

5 files changed

+75
-6
lines changed

5 files changed

+75
-6
lines changed

.github/actions/build/action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ outputs:
1616
tags:
1717
description: "The Docker tags for the image"
1818
value: ${{ steps.meta.outputs.tags }}
19+
version:
20+
description: "The version for the image"
21+
value: ${{ steps.meta.outputs.version }}
1922

2023
runs:
2124
using: "composite"

.github/actions/deploy/action.yml

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,18 @@ inputs:
77
image:
88
required: true
99
description: "Which image to deploy"
10-
token:
10+
version:
11+
required: true
12+
description: "Which version to deploy"
13+
fly_token:
1114
required: true
1215
description: "Access token for flyctl"
1316
slack_webhook_url:
1417
required: true
1518
description: "Webhook URL for slack"
19+
gh_token:
20+
description: 'The GitHub token to use for the API requests'
21+
required: true
1622

1723
runs:
1824
using: 'composite'
@@ -42,11 +48,63 @@ runs:
4248
--workdir /workspace \
4349
ghcr.io/superfly/flyctl:latest \
4450
deploy \
45-
-t ${{ inputs.token }} \
51+
-t ${{ inputs.fly_token }} \
4652
-c /workspace/fly.toml \
4753
-i ${{ inputs.image }} \
4854
--yes \
4955
--verbose
56+
57+
- name: Get input commit or latest commit
58+
id: commit
59+
shell: bash
60+
env:
61+
GH_TOKEN: ${{ inputs.gh_token }}
62+
run: |
63+
echo "url=${{ github.server_url }}/${{ github.repository }}/commits/${{ github.sha }}" >> $GITHUB_OUTPUT
64+
65+
- name: Get The PRs associated with the commit
66+
id: prs
67+
shell: bash
68+
env:
69+
GH_TOKEN: ${{ inputs.gh_token }}
70+
run: |
71+
prs=$(gh api \
72+
-H "Accept: application/vnd.github+json" \
73+
-H "X-GitHub-Api-Version: 2022-11-28" \
74+
/repos/${{ github.repository }}/commits/${{ github.sha }}/pulls)
75+
76+
echo "prs=$prs" >> $GITHUB_OUTPUT
77+
echo "prs $prs"
78+
79+
- name: Get ther run URL
80+
id: run
81+
shell: bash
82+
run: |
83+
echo "url=${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" >> $GITHUB_OUTPUT
84+
85+
- name: Comment PR
86+
shell: bash
87+
env:
88+
GH_TOKEN: ${{ inputs.gh_token }}
89+
run: |
90+
cat <<EOF >> comment.txt
91+
This PR was shipped to (${{ inputs.environment }})
92+
- [commit](${{ steps.commit.outputs.url }})
93+
- version: ${{ inputs.version }}
94+
- image: ${{ inputs.image }}
95+
96+
[View the run](${{ steps.run.outputs.url }})
97+
EOF
98+
99+
for pr in $(echo '${{ steps.prs.outputs.prs }}' | jq -r '.[].number'); do
100+
gh api \
101+
--method POST \
102+
-H "Accept: application/vnd.github.v3+json" \
103+
/repos/${{ github.repository }}/pulls/$pr/reviews \
104+
-f body="$(cat comment.txt)" \
105+
-F event=COMMENT
106+
done
107+
50108
- name: Notify (scuccessful deployment)
51109
if: success()
52110
uses: ./.github/actions/slack

.github/workflows/deploy.development.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Deploy (staging)
1+
name: Deploy (development)
22

33
on:
44
pull_request:
@@ -28,6 +28,8 @@ jobs:
2828
uses: ./.github/actions/deploy
2929
with:
3030
environment: development
31-
token: ${{ secrets.FLY_TOKEN }}
3231
image: ${{ steps.build.outputs.tags }}
32+
version: ${{ steps.build.outputs.version }}
33+
fly_token: ${{ secrets.FLY_TOKEN }}
3334
slack_webhook_url: ${{ secrets.SLACK_WEBHOOK_URL }}
35+
gh_token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/deploy.production.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ jobs:
2828
uses: ./.github/actions/deploy
2929
with:
3030
environment: production
31-
token: ${{ secrets.FLY_TOKEN }}
3231
image: ${{ steps.build.outputs.tags }}
32+
version: ${{ steps.build.outputs.version }}
33+
fly_token: ${{ secrets.FLY_TOKEN }}
3334
slack_webhook_url: ${{ secrets.SLACK_WEBHOOK_URL }}
35+
gh_token: ${{ secrets.GITHUB_TOKEN }}
36+
37+
- uses: ./.github/actions/link

.github/workflows/deploy.staging.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ jobs:
2626
uses: ./.github/actions/deploy
2727
with:
2828
environment: staging
29-
token: ${{ secrets.FLY_TOKEN }}
3029
image: ${{ steps.build.outputs.tags }}
30+
version: ${{ steps.build.outputs.version }}
31+
fly_token: ${{ secrets.FLY_TOKEN }}
3132
slack_webhook_url: ${{ secrets.SLACK_WEBHOOK_URL }}
33+
gh_token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)