-
Notifications
You must be signed in to change notification settings - Fork 0
175 lines (152 loc) · 5.79 KB
/
shared-build-and-deploy-on-push-Release.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
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# This workflow will build a MuleSoft project and deploy to CloudHub
# Based on https://github.com/arch-jn/github-actions-mule-cicd-demo/blob/main/.github/workflows/build-and-deploy-on-push.yml
name: shared - Build and Deploy Release
on:
workflow_call:
inputs:
ENVIRONMENT_CLOUDHUB:
required: true
type: string
description: Cloudhub Environment Value QA, STG, PROD
ENVIRONMENT_FOR_MULE_CONFIG:
required: true
type: string
description: Config Properties Environment Value qa, stg, prd
APPLICATION_NAME:
required: true
type: string
description: Application name in Cloudhub runtime, will be used for url. Name should be similar to prod-ukef-bbg-pa-v1
secrets:
MULE_NEXUS_USERNAME:
required: true
MULE_NEXUS_PASSWORD:
required: true
GH_PAT_FOR_READ_PACKAGES:
required: true
GH_USER_FOR_READ_PACKAGES:
# User is not used at the moment, but please send it
required: false
ANYPOINT_PLATFORM_USERNAME:
required: false
ANYPOINT_PLATFORM_PASSWORD:
required: false
DECRYPTION_KEY:
required: true
ANYPOINT_PLATFORM_CLIENT_ID:
required: true
ANYPOINT_PLATFORM_CLIENT_PASSWORD:
required: true
CONNECTED_APP_DEPLOY_CLIENT_ID:
required: true
CONNECTED_APP_DEPLOY_CLIENT_SECRET:
required: true
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Set up JDK 1.8
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: adopt
- name: Add repo credentials
uses: s4u/maven-settings-action@v2.4.0
with:
servers: |
[{
"id": "mule-enterprise",
"username": "${{ secrets.MULE_NEXUS_USERNAME }}",
"password": "${{ secrets.MULE_NEXUS_PASSWORD }}"
},{
"id": "anypoint-exchange-v3",
"username": "~~~Client~~~",
"password": "${{ secrets.CONNECTED_APP_DEPLOY_CLIENT_ID }}~?~${{ secrets.CONNECTED_APP_DEPLOY_CLIENT_SECRET }}"
},{
"id": "github-mulesoft-ukef-mule-common",
"username": "avaitonis",
"password": "${{ secrets.GH_PAT_FOR_READ_PACKAGES }}"
}]
#- name: Print effective-settings (optional)
# run: mvn help:effective-settings
- name: Change package version, remove -SNAPSHOT
run: sed -i 's/-SNAPSHOT//g' pom.xml
- name: Build with Maven
env:
DECRYPTION_KEY: ${{ secrets.DECRYPTION_KEY }}
#run: mvn -B package --file pom.xml
run: mvn -B package -DdecryptionKey=$DECRYPTION_KEY -DskipMunitTests --file pom.xml
- name: Stamp artifact file name with commit hash
run: |
artifactName1=$(ls target/*.jar | head -1)
commitHash=$(git rev-parse --short "$GITHUB_SHA")
artifactName2=$(ls target/*.jar | head -1 | sed "s/.jar/-$commitHash.jar/g")
mv $artifactName1 $artifactName2
- name: Upload artifact
uses: actions/upload-artifact@master
with:
name: artifacts
path: target/*.jar
retention-days: 10
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- uses: actions/download-artifact@master
with:
name: artifacts
- name: Add repo credentials
uses: s4u/maven-settings-action@v2.4.0
with:
servers: |
[{
"id": "mule-enterprise",
"username": "${{ secrets.MULE_NEXUS_USERNAME }}",
"password": "${{ secrets.MULE_NEXUS_PASSWORD }}"
},{
"id": "anypoint-exchange-v3",
"username": "~~~Client~~~",
"password": "${{ secrets.CONNECTED_APP_DEPLOY_CLIENT_ID }}~?~${{ secrets.CONNECTED_APP_DEPLOY_CLIENT_SECRET }}"
},{
"id": "github-mulesoft-ukef-mule-common",
"username": "avaitonis",
"password": "${{ secrets.GH_PAT_FOR_READ_PACKAGES }}"
}]
- name: Deploy to QA, STG or PROD
env:
CONNECTED_APP_DEPLOY_CLIENT_ID: ${{ secrets.CONNECTED_APP_DEPLOY_CLIENT_ID }}
CONNECTED_APP_DEPLOY_CLIENT_SECRET: ${{ secrets.CONNECTED_APP_DEPLOY_CLIENT_SECRET }}
DECRYPTION_KEY: ${{ secrets.DECRYPTION_KEY }}
ANYPOINT_PLATFORM_CLIENT_ID: ${{ secrets.ANYPOINT_PLATFORM_CLIENT_ID }}
ANYPOINT_PLATFORM_CLIENT_PASSWORD: ${{ secrets.ANYPOINT_PLATFORM_CLIENT_PASSWORD }}
ENVIRONMENT_FOR_MULE_CONFIG: ${{ inputs.ENVIRONMENT_FOR_MULE_CONFIG }}
ENVIRONMENT_CLOUDHUB: ${{ inputs.ENVIRONMENT_CLOUDHUB }}
APPLICATION_NAME: ${{ inputs.APPLICATION_NAME }}
run: |
artifactName=$(ls *.jar | head -1)
mvn deploy -DmuleDeploy \
-Dmule.artifact=$artifactName \
-DconnectedAppClientId="$CONNECTED_APP_DEPLOY_CLIENT_ID" \
-DconnectedAppClientSecret="$CONNECTED_APP_DEPLOY_CLIENT_SECRET" \
-Danypointplatformclientid="$ANYPOINT_PLATFORM_CLIENT_ID" \
-Danypointplatformclientsecret="$ANYPOINT_PLATFORM_CLIENT_PASSWORD" \
-Denv=$ENVIRONMENT \
-Ddeploymentenvironment=$ENVIRONMENT_CLOUDHUB \
-Denvironment=$ENVIRONMENT_FOR_MULE_CONFIG \
-DdecryptionKey="$DECRYPTION_KEY" \
-Dapplicationname="$APPLICATION_NAME" \
-DskipTests \
-DskipMunitTests