-
Notifications
You must be signed in to change notification settings - Fork 0
183 lines (153 loc) · 4.86 KB
/
main-workflow.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
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
name: Build and Publish Aws-Exporter
on:
pull_request:
branches:
- main
push:
branches:
- main
tags:
- 'v*'
env:
REGISTRY: asserts
jobs:
lint:
name: Lint Helm Chart
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Helm
uses: azure/setup-helm@v3
with:
version: v3.10.0
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: '3.9'
check-latest: true
- name: Set up chart-testing
uses: helm/[email protected]
- name: Run chart-testing (lint)
run: ct lint --config ct.yaml
build:
name: Build Aws-Exporter
runs-on: ubuntu-20.04
needs: lint
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Check with Gradle
run: ./gradlew check
- name: Get repository name
run: |
REPO_NAME=${GITHUB_REPOSITORY#*/}
echo "REPO_NAME=${REPO_NAME}" >> $GITHUB_ENV
- name: Docker metadata
id: meta-pr
uses: docker/metadata-action@v4
if: github.event_name == 'pull_request'
with:
images: ${{ env.REGISTRY}}/${{ env.REPO_NAME }}
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
- name: Docker metadata
id: meta-merge
uses: docker/metadata-action@v4
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
with:
images: ${{ env.REGISTRY}}/${{ env.REPO_NAME }}
tags: |
type=schedule
type=sha
- name: Docker metadata
id: meta-tag
uses: docker/metadata-action@v4
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
with:
images: ${{ env.REGISTRY}}/${{ env.REPO_NAME }}
tags: |
type=schedule
type=ref,event=tag
type=raw,value=latest-release
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
- name: Build and push pr
uses: docker/build-push-action@v4
if: github.event_name == 'pull_request'
with:
context: '.'
push: true
tags: ${{ steps.meta-pr.outputs.tags }}
- name: Build and push merge
uses: docker/build-push-action@v4
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
with:
context: '.'
push: true
tags: ${{ steps.meta-merge.outputs.tags }}
- name: Build and push tag
uses: docker/build-push-action@v4
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
with:
context: '.'
push: true
tags: ${{ steps.meta-tag.outputs.tags }}
publish-artifact:
name: Publish Aws-Exporter
runs-on: ubuntu-20.04
needs: build
if: github.ref == 'refs/heads/main' || contains(github.ref, 'refs/tags/')
env:
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
AWS_DEFAULT_REGION: us-west-2
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-west-2
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
role-external-id: ${{ secrets.AWS_ROLE_EXTERNAL_ID }}
role-duration-seconds: 1200
role-session-name: BuildSession
- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Gradle Build
run: ./gradlew build
- name: Publish Config with Gradle
run: ./gradlew publish
- name: Clear session
run: |
echo "AWS_ACCOUNT_ID=" >> $GITHUB_ENV
echo "AWS_ACCESS_KEY_ID=" >> $GITHUB_ENV
echo "AWS_SECRET_ACCESS_KEY=" >> $GITHUB_ENV
echo "AWS_SESSION_TOKEN=" >> $GITHUB_ENV