-
Notifications
You must be signed in to change notification settings - Fork 4
158 lines (158 loc) · 4.8 KB
/
ci.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
name: CI
on:
push:
branches:
- main
paths:
- src/**
- pom.xml
- .github/workflows/ci.yml
pull_request:
branches:
- main
paths:
- src/**
- pom.xml
- .github/workflows/ci.yml
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: graalvm/setup-graalvm@v1
with:
java-version: '21'
distribution: 'graalvm'
cache: 'maven'
- name: mvn test
env:
_JAVA_OPTIONS: -Djava.net.preferIPv4Stack=true
run: ./mvnw -V --no-transfer-progress test
- name: Upload build artifacts
uses: actions/upload-artifact@v2
with:
name: build-artifacts
path: target
build-jvm-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
needs: test
steps:
- uses: actions/checkout@v2
- uses: graalvm/setup-graalvm@v1
with:
java-version: '21'
distribution: 'graalvm'
cache: 'maven'
- name: Download build artifacts
uses: actions/download-artifact@v2
with:
name: build-artifacts
path: target
- name: build image
run: ./mvnw -V --no-transfer-progress spring-boot:build-image -DskipTests -Dspring-boot.build-image.imageName=ghcr.io/${{ github.repository }}:jvm
- name: Login to GitHub Container Registry
if: github.ref == 'refs/heads/main'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: docker push
if: github.ref == 'refs/heads/main'
run: docker push ghcr.io/${{ github.repository }}:jvm
- name: Generate digest
if: github.ref == 'refs/heads/main'
run: |
cat <<EOF > image.yaml
image: $(docker inspect --format='{{index .RepoDigests 0}}' ghcr.io/${{ github.repository }}:jvm)
git_revision: ${GITHUB_SHA}
EOF
- name: Upload artifact
if: github.ref == 'refs/heads/main'
uses: actions/upload-artifact@v2
with:
name: image
path: image.yaml
build-native-image:
if: github.ref == 'refs/heads/skip'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
needs: test
steps:
- uses: actions/checkout@v2
- uses: graalvm/setup-graalvm@v1
with:
java-version: '21'
distribution: 'graalvm'
cache: 'maven'
- name: Download build artifacts
uses: actions/download-artifact@v2
with:
name: build-artifacts
path: target
- name: build image
run: ./mvnw -V --no-transfer-progress -Pnative clean spring-boot:build-image -DskipTests -Dspring-boot.build-image.imageName=ghcr.io/${{ github.repository }}:native
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: docker push
run: |
docker push ghcr.io/${{ github.repository }}:native
docker inspect --format='{{index .RepoDigests 0}}' ghcr.io/${{ github.repository }}:native
- name: Generate digest
if: github.ref == 'refs/heads/main'
run: |
cat <<EOF > image_native.yaml
image: $(docker inspect --format='{{index .RepoDigests 0}}' ghcr.io/${{ github.repository }}:native)
git_revision: ${GITHUB_SHA}
EOF
- name: Upload artifact
if: github.ref == 'refs/heads/main'
uses: actions/upload-artifact@v2
with:
name: image
path: image_native.yaml
save-image:
if: github.ref == 'refs/heads/main'
needs: [ build-jvm-image ]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: git config
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git remote set-url origin https://github-actions:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
- name: Ensure images branch exists
run: |
if ! git ls-remote --exit-code --heads origin images; then
git checkout --orphan images
git reset --hard
git commit --allow-empty -m ":robot: Initial commit on images branch"
git push origin images
fi
- name: Checkout images branch
run: git checkout images
- name: Download artifact
uses: actions/download-artifact@v2
with:
name: image
path: .
- name: Commit and push changes
run: |
git add -A
git commit -m ":robot: Add Docker image digest for ${GITHUB_SHA}"
git push origin images
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}