-
Notifications
You must be signed in to change notification settings - Fork 0
92 lines (78 loc) · 4.36 KB
/
cd-compute.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
86
87
88
89
90
91
92
name: CD Compute
on:
push:
branches:
- "preprod"
- "prod"
workflow_dispatch:
jobs:
initiate-deployment:
runs-on: ubuntu-latest
timeout-minutes: 10
env:
AWS_REGION: eu-west-3
steps:
- uses: actions/[email protected]
- name: Update github workflow state
run: |
commit_message=$(git log -1 --pretty=%B)
commit_author=$(git log -1 --pretty=%an)
app_env_deployment_id_value=${{ env.app_env_deployment_id }}
if [ -z "$app_env_deployment_id_value" ]; then
app_env_deployment_id_value=null
else
app_env_deployment_id_value="\"$app_env_deployment_id_value\""
fi
response=$(curl --fail -X POST "https://api.prod.jcloudify.com/gh-repos/${{ github.repository }}/github-workflow-state" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
-d "{\"app_env_deployment_id\":$app_env_deployment_id_value, \"commit_sha\":\"${{ github.sha }}\", \"commit_message\":$(echo \"$commit_message\"), \"commit_author_name\":$(echo \"$commit_author\"), \"status\":\"WORKFLOW_RUNNING\", \"environment_type\":$(echo \"${{ github.ref_name }}\" | tr \"[:lower:]\" \'[:upper:]\")}")
echo "app_env_deployment_id=$(echo $response | jq -r '.app_env_deployment_id')" >> $GITHUB_ENV
echo $response
- uses: actions/[email protected]
with:
java-version: '21'
distribution: 'corretto'
- name: Prepare build
run: |
chmod +x ./gradlew
chmod +x .shell/publish_gen_to_maven_local.sh
response=$(curl -X GET "https://api.prod.jcloudify.com/gh-repos/${{ github.repository }}/upload-build-uri?environment_type=$(echo "${{ github.ref_name }}" | tr '[:lower:]' '[:upper:]')" -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/json")
echo "upload_build_file_uri=$(echo $response | jq -r '.uri')" >> $GITHUB_ENV
echo "to_upload_filename=$(echo $response | jq -r '.filename')" >> $GITHUB_ENV
curl -X GET -o template.yml "$(echo $response | jq -r '.build_template_file_uri')"
- name: Build project
run: sam build
- name: Prepare JCloudify deployment
run: |
shopt -s globstar
zip -r9 ${{ env.to_upload_filename }} .aws-sam
shopt -u globstar
curl -X PUT -H "Content-Type: application/zip" -T ${{ env.to_upload_filename }} "${{ env.upload_build_file_uri }}"
- name: Get current time
uses: gerred/actions/current-time@master
id: current-time
- name: Create UUID
id: generate-uuid
uses: filipstefansson/uuid-action@v1
with:
name: ${{ steps.current-time.outputs.time }}
- name: Trigger JCloudify deployment
run: |
curl --fail -X PUT "https://api.prod.jcloudify.com/gh-repos/${{ github.repository }}/env-deploys?environment_type=$(echo "${{ github.ref_name }}" | tr '[:lower:]' '[:upper:]')" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
-d "{\"formatted_bucket_key\":\"${{ env.to_upload_filename }}\",\"id\":\"${{ steps.generate-uuid.outputs.uuid }}\", \"commit_sha\":\"${{ github.sha }}\", \"app_env_deployment_id\":\"${{ env.app_env_deployment_id }}\", \"environment_type\":$(echo \"${{ github.ref_name }}\" | tr \"[:lower:]\" \'[:upper:]\")}"
- name: Update github state if step fails
if: failure()
run: |
app_env_deployment_id_value=${{ env.app_env_deployment_id }}
if [ -z "$app_env_deployment_id_value" ]; then
app_env_deployment_id_value=null
else
app_env_deployment_id_value="\"$app_env_deployment_id_value\""
fi
curl -X POST "https://api.prod.jcloudify.com/gh-repos/${{ github.repository }}/github-workflow-state" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
-d "{\"app_env_deployment_id\":$app_env_deployment_id_value, \"commit_sha\":\"${{ github.sha }}\", \"commit_message\":$(echo \"$commit_message\"), \"commit_author_name\":$(echo \"$commit_author\"), \"status\":\"WORKFLOW_FAILED\", \"environment_type\":$(echo \"${{ github.ref_name }}\" | tr \"[:lower:]\" \'[:upper:]\")}"