-
Notifications
You must be signed in to change notification settings - Fork 307
129 lines (111 loc) · 4.41 KB
/
precommit.yml
File metadata and controls
129 lines (111 loc) · 4.41 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
name: precommit
#on:
# pull_request:
# # we want to run the CI on every PR targetting those branches
# branches: [dev]
concurrency:
group: precommit-deploy
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-24.04
outputs:
unit_tests_report: ${{ env.UNIT_TEST_REPORT_FILE }}
build_artifact: ${{ env.BUILD_ARTIFACT }}
total_additions: ${{ steps.check_additions.outputs.total_additions }}
env:
BUILD_DIR: apps/server/dist/s3/
BUILD_ARTIFACT: ebs.zip
COMMIT_URL: ${{github.event.head_commit.url}}
COMMITTER: ${{github.event.head_commit.committer.name}}
CHANGELOG_FILE: './changelog.md'
UNIT_TEST_REPORT_FILE: './unit-tests.log'
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- name: Setup Node.js
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f
with:
node-version-file: '.nvmrc'
cache: 'yarn'
- name: Install JS dependencies
run: yarn --immutable
- name: Update configuration
run: yarn nx run webapp:configure
- name: Build and package
run: yarn nx run server:package
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
with:
name: 'build-artifact'
path: '${{env.BUILD_DIR}}${{env.BUILD_ARTIFACT}}'
- name: Check total PR additions
id: check_additions
run: |
total_additions=$(gh api -H "Accept: application/vnd.github.v3+json" \
"repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}" \
| jq -r '.additions')
if [ -z "$total_additions" ] || [ "$total_additions" = "null" ]; then
echo "Error: Could not extract additions"
exit 1
fi
echo "Found total additions: $total_additions"
echo "total_additions=$total_additions" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
deploy_to_aws:
name: 'Deploy to live environments'
runs-on: ubuntu-24.04
env:
AWS_REGION: eu-central-1
needs: [build]
steps:
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c
with:
name: 'build-artifact'
- name: Check if deploy is necessary
id: check_deploy
if: ${{ always() }}
run: |
if [[ ${{ needs.build.outputs.total_additions }} -le 100 || "${{ github.actor }}" == "renovate[bot]" ]]; then
echo "Skipping deployment"
exit 0
fi
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@ec61189d14ec14c8efccab744f656cffd0e33f37
with:
aws-access-key-id: ${{ secrets.WEBTEAM_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.WEBTEAM_AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
- name: Deploy to precommit environment
id: deploy
uses: aws-actions/aws-elasticbeanstalk-deploy@1f56e4e813ae4eb167e69ca324234c336c1df573
with:
aws-region: ${{ env.AWS_REGION }}
application-name: Webapp
environment-name: wire-webapp-precommit
version-label: ${{ github.run_id }}
deployment-package-path: ${{ needs.build.outputs.build_artifact }}
wait-for-deployment: true
wait-for-environment-recovery: true
deployment-timeout: 150
use-existing-application-version-if-available: true
- name: Deployment Status
if: ${{ always() }}
run: |
if [[ "${{ steps.deploy.outcome }}" == "success" ]]; then
echo "✅ Deployment completed successfully"
elif [[ "${{ steps.deploy.outcome }}" == "skipped" ]]; then
if [[ "${{ needs.build.outputs.total_additions }}" -le 100 ]]; then
echo "⏭️ Deployment was skipped: PR has ${{ needs.build.outputs.total_additions }} additions (threshold: 100)"
elif [[ "${{ github.actor }}" == "renovate[bot]" ]]; then
echo "⏭️ Deployment was skipped: PR is from renovate"
else
echo "⏭️ Deployment was skipped"
fi
else
echo "❌ Deployment failed"
exit 1
fi