Skip to content

Commit 981c77d

Browse files
authored
optimize workflow #2305 (#2306)
1 parent e625180 commit 981c77d

File tree

2 files changed

+99
-89
lines changed

2 files changed

+99
-89
lines changed

.github/workflows/build-and-run-tests.yml

Lines changed: 2 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ on:
1010
- 'main'
1111
- 'unit-test-bot/r**'
1212

13-
env:
14-
REGISTRY: ghcr.io
15-
1613
jobs:
1714
build-and-run-tests:
1815
uses: ./.github/workflows/build-and-run-tests-from-branch.yml
@@ -37,89 +34,5 @@ jobs:
3734
publish-cli-image:
3835
needs: build-and-run-tests
3936
if: ${{ github.event_name == 'push' }}
40-
strategy:
41-
fail-fast: false # force to execute all jobs even though some of them have failed
42-
matrix:
43-
configuration:
44-
- image_name: utbot_java_cli
45-
directory: utbot-cli
46-
extra_options: ""
47-
- image_name: utbot_js_cli
48-
directory: utbot-cli-js
49-
extra_options: "-PbuildType=ALL"
50-
# we can't use utbot_python_cli image name because of the bug while pushing image
51-
# ERROR: unexpected status: 403 Forbidden
52-
- image_name: utbot_py_cli
53-
directory: utbot-cli-python
54-
extra_options: ""
55-
runs-on: ubuntu-20.04
56-
container: unittestbot/java-env:java17-zulu-jdk-gradle7.6.1-kotlinc1.8.0
57-
steps:
58-
- uses: actions/checkout@v3
59-
60-
# "You can make an environment variable available to any subsequent steps in a workflow job by
61-
# defining or updating the environment variable and writing this to the GITHUB_ENV environment file."
62-
- name: Set environment variables
63-
run: |
64-
echo VERSION="$(date +%Y).$(date +%-m)" >> $GITHUB_ENV
65-
echo DOCKER_TAG="$(date +%Y).$(date +%-m).$(date +%-d)-$(echo -n ${GITHUB_SHA} | cut -c 1-7)" >> $GITHUB_ENV
66-
67-
- name: Print environment variables
68-
run: printenv
69-
70-
- name: Build UTBot CLI
71-
run: |
72-
cd ${{ matrix.configuration.directory }}
73-
gradle build --no-daemon --build-cache --no-parallel ${{ matrix.configuration.extra_options }} -Dorg.gradle.jvmargs=-Xmx2g -Dkotlin.daemon.jvm.options=-Xmx4g -x test -PsemVer=${{ env.VERSION }}
74-
75-
- name: Set up Docker Buildx
76-
uses: docker/setup-buildx-action@v2
77-
with:
78-
# fix of containerd issue, see https://github.com/containerd/containerd/issues/7972
79-
# could be removed as soon as new containerd version will be released and included in buildkit
80-
driver-opts: |
81-
image=moby/buildkit:v0.10.6
82-
83-
- name: Log in to the Container registry
84-
uses: docker/login-action@v2
85-
with:
86-
registry: ${{ env.REGISTRY }}
87-
username: ${{ github.actor }}
88-
password: ${{ secrets.GITHUB_TOKEN }}
89-
90-
- name: Cache Docker layers
91-
uses: actions/cache@v3
92-
with:
93-
path: /tmp/.buildx-cache
94-
key: ${{ runner.os }}-buildx-${{ matrix.configuration.image_name }}-${{ github.sha }}
95-
restore-keys: |
96-
${{ runner.os }}-buildx-${{ matrix.configuration.image_name }}-
97-
98-
- name: Docker meta
99-
id: meta
100-
uses: docker/metadata-action@v4
101-
with:
102-
images: ${{ env.REGISTRY }}/${{ github.repository }}/${{ matrix.configuration.image_name }}
103-
tags: |
104-
type=raw,value=${{ env.DOCKER_TAG }}
105-
106-
- name: Build and push
107-
uses: docker/build-push-action@v4
108-
with:
109-
context: .
110-
push: true
111-
tags: |
112-
${{ steps.meta.outputs.tags }}
113-
cache-from: type=local,src=/tmp/.buildx-cache
114-
cache-to: type=local,dest=/tmp/.buildx-cache-new
115-
file: ${{ matrix.configuration.directory }}/Dockerfile
116-
build-args: |
117-
ARTIFACT_PATH=${{ matrix.configuration.directory }}/build/libs/${{ matrix.configuration.directory }}-${{ env.VERSION }}.jar
118-
119-
# Temp fix
120-
# https://github.com/docker/build-push-action/issues/252
121-
# https://github.com/moby/buildkit/issues/1896
122-
- name: Move cache
123-
run: |
124-
rm -rf /tmp/.buildx-cache
125-
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
37+
uses: ./.github/workflows/publish-cli-image-from-branch.yml
38+
secrets: inherit
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: "[M] CLI: publish docker image"
2+
3+
on:
4+
workflow_call:
5+
workflow_dispatch:
6+
7+
env:
8+
REGISTRY: ghcr.io
9+
10+
jobs:
11+
publish-cli-image:
12+
strategy:
13+
fail-fast: false # force to execute all jobs even though some of them have failed
14+
matrix:
15+
configuration:
16+
- image_name: utbot_java_cli
17+
directory: utbot-cli
18+
extra_options: ""
19+
- image_name: utbot_js_cli
20+
directory: utbot-cli-js
21+
extra_options: "-PbuildType=ALL"
22+
# we can't use utbot_python_cli image name because of the bug while pushing image
23+
# ERROR: unexpected status: 403 Forbidden
24+
- image_name: utbot_py_cli
25+
directory: utbot-cli-python
26+
extra_options: ""
27+
runs-on: ubuntu-20.04
28+
container: unittestbot/java-env:java17-zulu-jdk-gradle7.6.1-kotlinc1.8.0
29+
steps:
30+
- uses: actions/checkout@v3
31+
32+
# "You can make an environment variable available to any subsequent steps in a workflow job by
33+
# defining or updating the environment variable and writing this to the GITHUB_ENV environment file."
34+
- name: Set environment variables
35+
run: |
36+
echo VERSION="$(date +%Y).$(date +%-m)" >> $GITHUB_ENV
37+
echo DOCKER_TAG="$(date +%Y).$(date +%-m).$(date +%-d)-$(echo -n ${GITHUB_SHA} | cut -c 1-7)" >> $GITHUB_ENV
38+
39+
- name: Print environment variables
40+
run: printenv
41+
42+
- name: Build UTBot CLI
43+
run: |
44+
cd ${{ matrix.configuration.directory }}
45+
gradle build --no-daemon --build-cache --no-parallel ${{ matrix.configuration.extra_options }} -Dorg.gradle.jvmargs=-Xmx2g -Dkotlin.daemon.jvm.options=-Xmx4g -x test -PsemVer=${{ env.VERSION }}
46+
47+
- name: Set up Docker Buildx
48+
uses: docker/setup-buildx-action@v2
49+
with:
50+
# fix of containerd issue, see https://github.com/containerd/containerd/issues/7972
51+
# could be removed as soon as new containerd version will be released and included in buildkit
52+
driver-opts: |
53+
image=moby/buildkit:v0.10.6
54+
55+
- name: Log in to the Container registry
56+
uses: docker/login-action@v2
57+
with:
58+
registry: ${{ env.REGISTRY }}
59+
username: ${{ github.actor }}
60+
password: ${{ secrets.GITHUB_TOKEN }}
61+
62+
- name: Cache Docker layers
63+
uses: actions/cache@v3
64+
with:
65+
path: /tmp/.buildx-cache
66+
key: ${{ runner.os }}-buildx-${{ matrix.configuration.image_name }}-${{ github.sha }}
67+
restore-keys: |
68+
${{ runner.os }}-buildx-${{ matrix.configuration.image_name }}-
69+
70+
- name: Docker meta
71+
id: meta
72+
uses: docker/metadata-action@v4
73+
with:
74+
images: ${{ env.REGISTRY }}/${{ github.repository }}/${{ matrix.configuration.image_name }}
75+
tags: |
76+
type=raw,value=${{ env.DOCKER_TAG }}
77+
78+
- name: Build and push
79+
uses: docker/build-push-action@v4
80+
with:
81+
context: .
82+
push: true
83+
tags: |
84+
${{ steps.meta.outputs.tags }}
85+
cache-from: type=local,src=/tmp/.buildx-cache
86+
cache-to: type=local,dest=/tmp/.buildx-cache-new
87+
file: ${{ matrix.configuration.directory }}/Dockerfile
88+
build-args: |
89+
ARTIFACT_PATH=${{ matrix.configuration.directory }}/build/libs/${{ matrix.configuration.directory }}-${{ env.VERSION }}.jar
90+
91+
# Temp fix
92+
# https://github.com/docker/build-push-action/issues/252
93+
# https://github.com/moby/buildkit/issues/1896
94+
- name: Move cache
95+
run: |
96+
rm -rf /tmp/.buildx-cache
97+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache

0 commit comments

Comments
 (0)