-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathaction.yml
More file actions
240 lines (197 loc) · 7.52 KB
/
action.yml
File metadata and controls
240 lines (197 loc) · 7.52 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
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
name: 'Brightspot Build'
description: 'Build Brightspot'
inputs:
project-aws-account-id:
description: 'AWS Account ID of project'
required: true
cloud-aws-account-id:
description: 'AWS Account ID of Cloud project'
required: true
region:
description: 'Region project is deployed to'
required: true
project:
description: 'Shortname for project'
required: true
repository:
description: 'Repository name. This overrides the default which is ${project}/${project}'
required: false
aws-access-key-id:
description: 'AWS Access Key ID'
required: true
aws-secret-access-key:
description: 'AWS Secret Access Key'
required: true
aws-session-token:
description: 'AWS Session Token'
required: true
deploy-s3:
description: 'Deploy to S3 in addition to the container build'
required: false
default: false
deploy-bucket:
description: 'S3 bucket to deploy to'
required: false
deploy-bucket-prefix:
description: 'Directory prefix within the S3 bucket'
required: false
deploy-container:
description: 'Deploy to container build'
required: false
default: true
build-maven:
description: 'Build with Maven'
default: false
build-gradle:
description: 'Build with Gradle'
default: true
java-distribution:
description: 'Java distribution'
required: false
default: 'temurin'
java-version:
description: 'Java version'
required: false
default: '11'
cache-npm:
description: 'Cache NPM'
default: true
checkout-repo:
description: "Checkout repo, defaults to true. Can be set to false to re-use the build created from another step"
default: true
war-build-dir:
description: 'Directory containing the compiled WAR file. This overrides the default which is web/build/libs'
required: false
default: 'web/build/libs'
outputs:
container-build-tag:
description: "Container build tag. This tag is stable and won't change."
value: ${{ steps.build-container.outputs.container-build-tag }}
container-version-tag:
description: "Container version tag. This tag is unstable and may move with each build."
value: ${{ steps.build-container.outputs.container-build-tag }}
runs:
using: "composite"
steps:
- uses: actions/checkout@v3
if: ${{ inputs.checkout-repo == 'true' }}
- name: Set up JDK
uses: actions/setup-java@v2
with:
java-version: ${{ inputs.java-version }}
distribution: ${{ inputs.java-distribution }}
- name: Get Tag Version
shell: bash
run: |
echo "GITHUB_ACTIONS_TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
echo "GITHUB_ACTIONS_PULL_REQUEST=${{ github.event.pull_request.number }}" >> $GITHUB_ENV
- uses: actions/checkout@v3
if: ${{ inputs.checkout-repo == 'true' }}
with:
repository: perfectsense/github-actions-s3-deploy
ref: v1
path: ./github-actions-s3-deploy
- name: Maven Cache
if: ${{ inputs.build-maven == 'true' }}
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Gradle Cache
if: ${{ inputs.build-gradle == 'true' }}
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: NPM Cache
if: ${{ inputs.cache-npm == 'true' }}
uses: actions/cache@v3
with:
path: |
~/.npm
~/.yarn/cache
~/.config/yarn/global
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-npm-
- name: Build with Maven
if: ${{ inputs.build-maven == 'true' }}
shell: bash
run: ./github-actions-s3-deploy/build-maven.sh
- name: Build with Gradle
if: ${{ inputs.build-gradle == 'true' }}
shell: bash
run: ./github-actions-s3-deploy/build-gradle.sh
- name: Deploy to S3
if: ${{ inputs.deploy-s3 == 'true' && github.actor!= 'dependabot[bot]' }}
env:
AWS_ACCESS_KEY_ID: ${{ inputs.aws-access-key-id }}
AWS_SECRET_ACCESS_KEY: ${{ inputs.aws-secret-access-key }}
AWS_SESSION_TOKEN: ${{ inputs.aws-session-token }}
AWS_DEFAULT_REGION: ${{ inputs.region }}
DEPLOY_BUCKET: ${{ inputs.deploy-bucket }}
DEPLOY_BUCKET_PREFIX: ${{ inputs.deploy-bucket-prefix }}
DEPLOY_SOURCE_DIR: ${{ inputs.war-build-dir }}
shell: bash
run: ./github-actions-s3-deploy/deploy.sh
- name: Configure AWS Credentials
if: github.actor!= 'dependabot[bot]'
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ inputs.aws-access-key-id }}
aws-secret-access-key: ${{ inputs.aws-secret-access-key }}
aws-session-token: ${{ inputs.aws-session-token }}
aws-region: ${{ inputs.region }}
mask-aws-account-id: false
- name: Login to project ECR
uses: docker/login-action@v1
if: ${{ inputs.deploy-container == 'true' && github.actor!= 'dependabot[bot]' }}
with:
registry: ${{ inputs.project-aws-account-id }}.dkr.ecr.${{ inputs.region }}.amazonaws.com
- name: Login to Brightspot Cloud ECR
uses: docker/login-action@v1
if: ${{ inputs.deploy-container == 'true' && github.actor!= 'dependabot[bot]' }}
with:
registry: ${{ inputs.cloud-aws-account-id }}.dkr.ecr.${{ inputs.region }}.amazonaws.com
- name: Build Container
id: build-container
if: ${{ inputs.deploy-container == 'true' && github.actor!= 'dependabot[bot]' }}
shell: bash
run: |
version=""
build=""
echo "GITHUB_ACTIONS_TAG ${GITHUB_ACTIONS_TAG}"
echo "GITHUB_ACTIONS_PULL_REQUEST ${GITHUB_ACTIONS_PULL_REQUEST}"
if [[ ! -z "$GITHUB_ACTIONS_PULL_REQUEST" && "$GITHUB_ACTIONS_PULL_REQUEST" != "" ]]; then
version="pullrequest-$GITHUB_ACTIONS_PULL_REQUEST"
build=pullrequest-$GITHUB_ACTIONS_PULL_REQUEST-build$GITHUB_RUN_NUMBER
elif [[ "$GITHUB_ACTIONS_TAG" =~ ^v[0-9]+\. ]]; then
echo "GITHUB_ACTIONS_TAG ${GITHUB_ACTIONS_TAG}"
version=release-${GITHUB_ACTIONS_TAG/v/}
build=release-${GITHUB_ACTIONS_TAG/v/}
else
COMMIT_COUNT=$(git rev-list --count HEAD)
COMMIT_SHA=$(git rev-parse --short=6 HEAD)
build=development-$(git describe --all | sed 's/heads\///' | sed 's/\//-/g')
build+=-build$GITHUB_RUN_NUMBER
version=development-$(git describe --all | sed 's/heads\///' | sed 's/\//-/g')
fi
cp ${{ inputs.war-build-dir }}/*.war etc/container/web.war
cd etc/container
PROJECT="${{ inputs.project }}"
REPOSITORY="${{ inputs.repository }}"
if [ -z ${REPOSITORY} ]; then
REPOSITORY="$PROJECT/$PROJECT"
fi
REGISTRY="${{ inputs.project-aws-account-id }}.dkr.ecr.${{ inputs.region }}.amazonaws.com"
BUILD_TAG="$REGISTRY/$REPOSITORY:$build"
VERSION_TAG="$REGISTRY/$REPOSITORY:$version"
docker buildx build --push --build-arg WAR_ARTIFACT=web.war -t $VERSION_TAG -t $BUILD_TAG -f Dockerfile .
echo "::set-output name=container-build-tag::$(echo $BUILD_TAG)"
echo "::set-output name=container-version-tag::$(echo $VERSION_TAG)"