-
Notifications
You must be signed in to change notification settings - Fork 0
146 lines (120 loc) · 4.31 KB
/
gradle-build-push-image.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
name: Kotlin CI with Gradle, Build & Push OCI Image
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
env:
REGISTRY: ghcr.io/${{ github.repository_owner }}
IMAGE_NAME: graphql-reactive
jobs:
build-gradle:
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/[email protected]
with:
java-version: '17'
distribution: 'adopt'
cache: gradle
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build
- name: Publish Test Report
uses: mikepenz/action-junit-report@v5
if: always()
with:
report_paths: '**/build/test-results/test/TEST-*.xml'
build-push-image:
name: Build OCI Image and push to GitHub Packages
runs-on: ubuntu-latest
needs: build-gradle
if: contains('refs/heads/main', github.ref)
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
- name: Check out code
uses: actions/checkout@v4
- name: Set Branch name
id: branch-name
run: |
# Short name for current branch. For PRs, use target branch (base ref)
GIT_BRANCH=${GITHUB_BASE_REF:-${GITHUB_REF#refs/heads/}}
echo "GIT_BRANCH=$GIT_BRANCH" >> $GITHUB_ENV
- name: Set Image Tags
id: image-tags
run: |
echo ::set-output name=branch_commit_tag::${GIT_BRANCH}-${COMMIT}
echo ::set-output name=branch_tag::${GIT_BRANCH}-latest
env:
COMMIT: ${{ github.sha }}
- name: Set up JDK 17
uses: actions/[email protected]
with:
java-version: '17'
distribution: 'adopt'
cache: gradle
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build OCI with Gradle
run: ./gradlew bootBuildImage
env:
IMAGE_TAG_BRANCH_COMMIT: ${{ steps.image-tags.outputs.branch_commit_tag }}
IMAGE_TAG_BRANCH: ${{ steps.image-tags.outputs.branch_tag }}
# https://github.com/paketo-buildpacks/ca-certificates#configuration
BP_EMBED_CERTS: true
BP_RUNTIME_CERT_BINDING_DISABLED: true
BP_ENABLE_RUNTIME_CERT_BINDING: false
- name: Push OCI to GitHub Packages
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
docker push $REGISTRY/$IMAGE_NAME --all-tags
build-push-image-dry-run:
name: Build OCI Image (Dry Run)
runs-on: ubuntu-latest
needs: build-gradle
if: github.event_name == 'pull_request'
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set Branch name
id: branch-name
run: |
# Short name for current branch. For PRs, use target branch (base ref)
GIT_BRANCH=${GITHUB_BASE_REF:-${GITHUB_REF#refs/heads/}}
echo "GIT_BRANCH=$GIT_BRANCH" >> $GITHUB_ENV
- name: Set Image Tags
id: image-tags
run: |
echo ::set-output name=branch_commit_tag::${GIT_BRANCH}-${COMMIT}
echo ::set-output name=branch_tag::${GIT_BRANCH}-latest
env:
COMMIT: ${{ github.sha }}
- name: Set up JDK 17
uses: actions/[email protected]
with:
java-version: '17'
distribution: 'adopt'
cache: gradle
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build OCI with Gradle
run: ./gradlew bootBuildImage
env:
IMAGE_TAG_BRANCH_COMMIT: ${{ steps.image-tags.outputs.branch_commit_tag }}
IMAGE_TAG_BRANCH: ${{ steps.image-tags.outputs.branch_tag }}
# https://github.com/paketo-buildpacks/ca-certificates#configuration
BP_EMBED_CERTS: true
BP_RUNTIME_CERT_BINDING_DISABLED: true
BP_ENABLE_RUNTIME_CERT_BINDING: false
- name: Push OCI to GitHub Packages (Dry Run)
run: |
echo docker push $REGISTRY/$IMAGE_NAME --all-tags