-
Notifications
You must be signed in to change notification settings - Fork 1
111 lines (102 loc) · 4.08 KB
/
pull_request.yaml
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
name: Pull Request
on:
pull_request:
types: [opened, reopened, synchronize]
permissions:
contents: read
pull-requests: write
env:
BASE_ENVIRONMENT: 'development'
ENVIRONMENT_TYPE: 'ephemeral'
HUMCTL_VERSION: 0.30.3
ENVIRONMENT_ID: pr-${{ github.event.number }}
ENVIRONMENT_NAME: PR-${{ github.event.number }}
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build and Push to Humanitec
id: build-push
uses: humanitec/build-push-to-humanitec@v1
with:
humanitec-token: ${{ secrets.HUMANITEC_TOKEN }}
organization: ${{ vars.HUMANITEC_ORG }}
- name: Install humctl
run: |
wget https://github.com/humanitec/cli/releases/download/v${{ env.HUMCTL_VERSION }}/cli_${{ env.HUMCTL_VERSION }}_linux_amd64.tar.gz
tar -xvf cli_${{ env.HUMCTL_VERSION }}_linux_amd64.tar.gz
chmod +x humctl
mv humctl /usr/local/bin
- name: Create Humanitec Env
run: |
# Check in case this PR receives additional pushes
if humctl get env "${{ env.ENVIRONMENT_ID }}" \
--token ${{ secrets.HUMANITEC_TOKEN }} \
--org ${{ vars.HUMANITEC_ORG }} \
--app ${{ vars.HUMANITEC_APP }}
then
echo "Environment ${{ env.ENVIRONMENT_ID }} already exists. Skipping creation."
exit
fi
humctl create env "${{ env.ENVIRONMENT_ID }}" \
--name "${{ env.ENVIRONMENT_NAME }}" \
--type "${{ env.ENVIRONMENT_TYPE }}" \
--from "${{ env.BASE_ENVIRONMENT }}" \
--token ${{ secrets.HUMANITEC_TOKEN }} \
--org ${{ vars.HUMANITEC_ORG }} \
--app ${{ vars.HUMANITEC_APP }}
- name: Run Score
run: |
if ! [ -f score.yaml ]
then
echo "no score file found, cannot deploy"
exit 1
fi
humctl score deploy -f score.yaml \
--image "${{ steps.build-push.outputs.image }}" \
--wait \
--token ${{ secrets.HUMANITEC_TOKEN }} \
--org ${{ vars.HUMANITEC_ORG }} \
--app ${{ vars.HUMANITEC_APP }} \
--env ${{ env.ENVIRONMENT_ID }}
- name: Wait for deployment
run: |
sleep 1
IS_DONE=false
while [ "$IS_DONE" = false ]; do
CURRENT_STATUS="$(humctl get env "${{ env.ENVIRONMENT_ID }}" \
--token ${{ secrets.HUMANITEC_TOKEN }} \
--org ${{ vars.HUMANITEC_ORG }} \
--app ${{ vars.HUMANITEC_APP }} \
-o json | jq -r ".status.last_deploy.status.status")"
INPROGRESS="in progress"
if [ "$CURRENT_STATUS" = "$INPROGRESS" ]; then
echo "Deployment still in progress..."
sleep 1
else
echo "Deployment complete!"
IS_DONE=true
fi
done
- name: Build Comment Message
run: |
DOMAINS="$(humctl get active-resources \
--token ${{ secrets.HUMANITEC_TOKEN }} \
--org ${{ vars.HUMANITEC_ORG }} \
--app ${{ vars.HUMANITEC_APP }} \
--env ${{ env.ENVIRONMENT_ID }} \
-o json | jq -r '[.[] | select(.metadata.type == "dns") | (.metadata.res_id | split(".") | .[1]) + ": [" + .status.resource.host + "](https://" + .status.resource.host+ ")"] | join("\n")')"
echo "## Deployment Complete for ${{ env.ENVIRONMENT_NAME }}! :tada:" >> pr_message.txt
echo "" >> pr_message.txt
echo "### [View in Humanitec](https://app.humanitec.io/orgs/${{ vars.HUMANITEC_ORG }}/apps/${{ vars.HUMANITEC_APP }})/envs/${{ env.ENVIRONMENT_ID }}" >> pr_message.txt
echo "" >> pr_message.txt
echo "### Domains:" >> pr_message.txt
echo "" >> pr_message.txt
echo "$DOMAINS" >> pr_message.txt
echo "" >> pr_message.txt
cat pr_message.txt
- name: Comment PR
uses: thollander/actions-comment-pull-request@v2
with:
filePath: pr_message.txt