-
Notifications
You must be signed in to change notification settings - Fork 1
148 lines (127 loc) · 5.08 KB
/
build-and-test.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
name: 🧱 Build and Push
run-name: 🧱 Build and Push ${{ github.ref_name }}
env:
bucket-name: cvs-services
on:
workflow_call:
workflow_dispatch:
inputs:
ignore-test-failures:
type: boolean
description: Ignore Test Failures
default: false
concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: true
permissions:
id-token: write
contents: write
jobs:
environment:
name: 🧹 Prepare Environment
runs-on: ubuntu-latest
outputs:
environment-name: ${{ steps.environment.outputs.environment-name }}
environment-type: ${{ steps.environment.outputs.environment-type }}
github-branch: ${{ steps.environment.outputs.github-branch }}
commit: ${{ steps.commit.outputs.commit }}
package-name: ${{ steps.name.outputs.package-name }}
steps:
- name: Generate Package Name
id: name
run: |
repo=${{ github.repository }}
echo "package-name=${repo#dvsa/}" >> $GITHUB_OUTPUT
echo "package-name=${repo#dvsa/}" >> $GITHUB_STEP_SUMMARY
- name: 🪪 Get Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.CVS_MGMT_AWS_ROLE }}
aws-region: ${{ vars.DVSA_AWS_REGION}}
role-session-name: GHA_TagDevelop
- name: 📥 Get Codebase
uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}
- name: ↕️ Get Environment Details
id: environment
uses: dvsa/cvs-github-actions/environment@develop
with:
environment: ${{ github.ref_name }}
- name: Get Commit SHA
id: commit
run: |
# Get the branch Commit ID
commit_id=$(git rev-parse HEAD)
echo "commit=${commit_id}"
echo "commit=${commit_id}" >> $GITHUB_OUTPUT
echo "Commit ID: ${commit_id}" >> $GITHUB_STEP_SUMMARY
build-service:
name: 🧱 Build ${{ needs.environment.outputs.package-name }}
runs-on:
- ${{ needs.environment.outputs.package-name }}
needs: environment
steps:
- name: 🪪 Get Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.CVS_MGMT_AWS_ROLE }}
aws-region: ${{ vars.DVSA_AWS_REGION }}
role-session-name: GHA_BuildServices
- name: 📥 Get Codebase
uses: actions/checkout@v4
- name: Get Commit SHA
id: commit
run: |
# Get the branch Commit ID
commit_id=$(git rev-parse HEAD)
echo "commit=${commit_id}"
echo "commit=${commit_id}" >> $GITHUB_OUTPUT
echo "Commit ID: ${commit_id}" >> $GITHUB_STEP_SUMMARY
- name: 🗒️ Process Manifest Data
id: manifest
run: |
# Generate Manifest Outputs & Identify Build Requirements
hash_files="[]"
if [[ -f "manifest.json" ]]; then
package=$(jq -r '.name' manifest.json)
echo "package=$(jq -r '.name' manifest.json)" >> $GITHUB_OUTPUT
echo "language=$(jq -r '.language' manifest.json)" >> $GITHUB_OUTPUT
echo "liquibase=$(jq -r '.liquibase' manifest.json)" >> $GITHUB_OUTPUT
# Check for existing Hash
hashes=$(aws s3api list-objects-v2 --bucket ${{ env.bucket-name }} --query "Contents[?Key.contains(@,'${{ steps.commit.outputs.commit }}.zip') && Key.contains(@,'$package')].Key" | jq -rc)
if [[ $(awk '{print index($0,"${{ steps.commit.outputs.commit }}")}' <<< $hashes) == 0 ]]; then
echo "Current Hash does not exist"
build_package=true
else
echo "Current Hash exists"
hash_files=$hashes
build_package=false
fi
else
build_package=false
fi
# Add flag to build or skip
echo "build-package=${build_package}" >> $GITHUB_OUTPUT
echo "Build Package: ${build_package}" >> $GITHUB_STEP_SUMMARY
- name: 🏗️ Build Node Function
uses: dvsa/cvs-github-actions/build-node-function@develop
if: ${{ steps.manifest.outputs.build-package == 'true' && steps.manifest.outputs.language == 'node' }}
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
with:
commit-sha: ${{ steps.commit.outputs.commit }}
branch: ${{needs.environment.outputs.github-branch }}
mysql_liquibase: ${{ steps.manifest.outputs.liquibase }}
mysql_user: ${{ secrets.MYSQL_USER }}
mysql_password: ${{ secrets.MYSQL_PASS }}
continue-on-error: ${{ inputs.ignore-test-failures }}
- name: 🏗️ Build Java Function
uses: dvsa/cvs-github-actions/build-java-function@develop
if: ${{ steps.manifest.outputs.build-package == 'true' && steps.manifest.outputs.language == 'java' }}
- name: 📤 Upload Artifact
uses: actions/upload-artifact@v4
with:
name: ${{ needs.environment.outputs.package-name }}
path: |
${{ steps.commit.outputs.commit }}*.zip