-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
85 lines (79 loc) · 2.72 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
name: "Fly GitHub Deploy"
description: "Deploy to Fly from GitHub Actions"
branding:
icon: "umbrella"
color: "blue"
inputs:
app:
description: "The app name"
default: ""
required: false
build-args:
description: "Build time variables in the form of NAME=VALUE pairs"
default: ""
required: false
fly-token:
description: "Fly API token"
required: true
github-token:
description: "The repo scoped token generated by GitHub Actions"
required: false
runs:
using: "composite"
steps:
- uses: actions/checkout@v4
- uses: superfly/flyctl-actions/setup-flyctl@master
- name: Lookup app hostname
shell: bash
run: |
echo "FLY_HOSTNAME=$(flyctl status --json | jq -r '.Hostname')" >> $GITHUB_ENV
env:
FLY_API_TOKEN: "${{ inputs.fly-token }}"
- name: Lookup app release version
shell: bash
run: |
echo "FLY_RELEASE_VERSION=$(flyctl releases --json | jq 'max_by(.Version).Version')" >> $GITHUB_ENV
env:
FLY_API_TOKEN: "${{ inputs.fly-token }}"
- name: Create deployment in GitHub
if: ${{ inputs.github-token }}
shell: bash
env:
GITHUB_TOKEN: ${{ inputs.github-token }}
run: |
deploymentId=$(jq -n "{
\"ref\": \"${{ github.event.repository.default_branch }}\",\
\"environment\": \"$FLY_HOSTNAME\",\
\"description\": \"Fly deploy from GitHub Actions\",\
\"required_contexts\": []\
}" \
| gh api repos/${{ github.repository }}/deployments \
--method POST \
--header "Accept: application/vnd.github.v3+json" \
--input - \
--jq '.id')
echo 'DEPLOYMENT_ID='$deploymentId >> $GITHUB_ENV
- name: Deploy to Fly
shell: bash
run: |
flyctl deploy --remote-only \
--ha=false \
--app "${{ inputs.app }}" \
--build-arg "${{ inputs.build-args }}" \
--env RELEASE_COMMIT=$(git rev-parse --verify HEAD) \
--env RELEASE_CREATED_AT=$(date --iso-8601=seconds) \
--env RELEASE_VERSION="v$(( $FLY_RELEASE_VERSION + 1 ))"
env:
FLY_API_TOKEN: "${{ inputs.fly-token }}"
- name: Create deployment status in GitHub
if: ${{ inputs.github-token }}
shell: bash
env:
GITHUB_TOKEN: ${{ inputs.github-token }}
run: |
gh api repos/${{ github.repository }}/deployments/$DEPLOYMENT_ID/statuses \
--method POST \
--header "Accept: application/vnd.github.v3+json" \
--field state=success \
--field log_url=https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} \
--field environment_url=https://$FLY_HOSTNAME