-
Notifications
You must be signed in to change notification settings - Fork 292
115 lines (98 loc) · 3.84 KB
/
precommit.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
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:
precommit-deploy:
runs-on: buildjet-8vcpu-ubuntu-2204
outputs:
unit_tests_report: ${{ env.UNIT_TEST_REPORT_FILE }}
build_artifact: ${{ env.BUILD_ARTIFACT }}
env:
DEPLOYMENT_RECOVERY_TIMEOUT_SECONDS: 150
AWS_APPLICATION_NAME: Webapp
BUILD_DIR: 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@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18.16.x
cache: 'yarn'
- name: Install JS dependencies
run: yarn --immutable
- name: Update configuration
run: yarn configure
# - name: Test
# run: |
# set -o pipefail
# yarn test --detectOpenHandles=false 2>&1 | tee ${{ env.UNIT_TEST_REPORT_FILE }}
# echo -e "COMMIT SHA = ${{ github.sha }}" >> ${{env.UNIT_TEST_REPORT_FILE}}
# echo -e "TEST RUN DATE = $(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> ${{env.UNIT_TEST_REPORT_FILE}}
# - uses: actions/upload-artifact@v4
# with:
# name: 'unit-tests-report'
# path: ${{env.UNIT_TEST_REPORT_FILE}}
- name: Build
run: yarn build:prod
- uses: actions/upload-artifact@v4
with:
name: 'build-artifact'
path: '${{env.BUILD_DIR}}${{env.BUILD_ARTIFACT}}'
- name: Fetch PR details
id: pr_details
uses: octokit/[email protected]
with:
route: GET /repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Check total PR additions
id: check_additions
run: |
# Parse the JSON response directly without storing in file
total_additions=$(echo '${{ fromJSON(steps.pr_details.outputs.data).additions }}')
echo "Total additions: $total_additions"
echo "total_additions=$total_additions" >> $GITHUB_ENV
- name: Deploy to precommit environment
id: deploy
if: ${{ env.total_additions > 100 && github.actor != 'dependabot[bot]' }}
uses: einaregilsson/beanstalk-deploy@v22
with:
application_name: Webapp
aws_access_key: ${{ secrets.WEBTEAM_AWS_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.WEBTEAM_AWS_SECRET_ACCESS_KEY }}
deployment_package: ${{needs.build.outputs.build_artifact}}
environment_name: wire-webapp-precommit
region: eu-central-1
use_existing_version_if_available: true
version_description: ${{ github.sha }}
version_label: ${{ github.run_id }}
wait_for_deployment: false
wait_for_environment_recovery: 150
- name: Deployment Status
if: ${{ always() }}
run: |
if [[ "${{ steps.deploy.outcome }}" == "success" ]]; then
echo "✅ Deployment completed successfully"
elif [[ "${{ steps.deploy.outcome }}" == "skipped" ]]; then
if [[ "${{ env.total_additions }}" -le 100 ]]; then
echo "⏭️ Deployment was skipped: PR has ${{ env.total_additions }} additions (threshold: 100)"
elif [[ "${{ github.actor }}" == "dependabot[bot]" ]]; then
echo "⏭️ Deployment was skipped: PR is from dependabot"
else
echo "⏭️ Deployment was skipped"
fi
else
echo "❌ Deployment failed"
exit 1
fi