Skip to content

Commit 3a4e08a

Browse files
authored
Merge pull request libgit2#6488 from libgit2/ethomson/workflow
actions: simplify execution with composite action
2 parents c87a3f8 + 7eb6318 commit 3a4e08a

File tree

4 files changed

+146
-126
lines changed

4 files changed

+146
-126
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Run a build step in a container or directly on the Actions runner
2+
name: Run Build Step
3+
description: Run a build step in a container or directly on the Actions runner
4+
5+
inputs:
6+
command:
7+
description: Command to run
8+
required: true
9+
type: string
10+
container:
11+
description: Optional container to run in
12+
type: string
13+
container-version:
14+
description: Version of the container to run
15+
type: string
16+
17+
runs:
18+
using: 'composite'
19+
steps:
20+
- run: |
21+
if [ -n "${{ inputs.container }}" ]; then
22+
docker run \
23+
--rm \
24+
--user "$(id -u):$(id -g)" \
25+
-v "$(pwd)/source:/home/libgit2/source" \
26+
-v "$(pwd)/build:/home/libgit2/build" \
27+
-w /home/libgit2 \
28+
-e ASAN_SYMBOLIZER_PATH \
29+
-e CC \
30+
-e CFLAGS \
31+
-e CMAKE_GENERATOR \
32+
-e CMAKE_OPTIONS \
33+
-e GITTEST_NEGOTIATE_PASSWORD \
34+
-e GITTEST_FLAKY_STAT \
35+
-e PKG_CONFIG_PATH \
36+
-e SKIP_NEGOTIATE_TESTS \
37+
-e SKIP_SSH_TESTS \
38+
-e TSAN_OPTIONS \
39+
-e UBSAN_OPTIONS \
40+
${{ inputs.container-version }} \
41+
/bin/bash -c "${{ inputs.command }}"
42+
else
43+
${{ inputs.command }}
44+
fi
45+
shell: bash
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Generate the containers that we use for builds.
2+
name: Build Containers
3+
4+
on:
5+
workflow_call:
6+
7+
env:
8+
docker-registry: ghcr.io
9+
docker-config-path: source/ci/docker
10+
11+
jobs:
12+
# Build the docker container images that we will use for our Linux
13+
# builds. This will identify the last commit to the repository that
14+
# updated the docker images, and try to download the image tagged with
15+
# that sha. If it does not exist, we'll do a docker build and push
16+
# the image up to GitHub Packages for the actual CI/CD runs. We tag
17+
# with both the sha and "latest" so that the subsequent runs need not
18+
# know the sha. Only do this on CI builds (when the event is a "push")
19+
# because PR builds from forks lack permission to write packages.
20+
containers:
21+
strategy:
22+
matrix:
23+
container:
24+
- name: xenial
25+
- name: bionic
26+
- name: focal
27+
- name: docurium
28+
- name: bionic-x86
29+
dockerfile: bionic
30+
base: multiarch/ubuntu-core:x86-bionic
31+
qemu: true
32+
- name: bionic-arm32
33+
dockerfile: bionic
34+
base: multiarch/ubuntu-core:armhf-bionic
35+
qemu: true
36+
- name: bionic-arm64
37+
dockerfile: bionic
38+
base: multiarch/ubuntu-core:arm64-bionic
39+
qemu: true
40+
- name: centos7
41+
- name: centos8
42+
runs-on: ubuntu-latest
43+
name: "Create container: ${{ matrix.container.name }}"
44+
steps:
45+
- name: Check out repository
46+
uses: actions/checkout@v3
47+
with:
48+
path: source
49+
fetch-depth: 0
50+
if: github.event_name != 'pull_request'
51+
- name: Setup QEMU
52+
run: docker run --rm --privileged multiarch/qemu-user-static:register --reset
53+
if: matrix.container.qemu == true
54+
- name: Download existing container
55+
run: |
56+
"${{ github.workspace }}/source/ci/getcontainer.sh" "${{ matrix.container.name }}" "${{ matrix.container.dockerfile }}"
57+
env:
58+
DOCKER_REGISTRY: ${{ env.docker-registry }}
59+
GITHUB_TOKEN: ${{ secrets.github_token }}
60+
working-directory: ${{ env.docker-config-path }}
61+
if: github.event_name != 'pull_request'
62+
- name: Build and publish image
63+
run: |
64+
if [ "${{ matrix.container.base }}" != "" ]; then
65+
BASE_ARG="--build-arg BASE=${{ matrix.container.base }}"
66+
fi
67+
docker build -t ${{ env.docker-registry-container-sha }} --build-arg UID=$(id -u) --build-arg GID=$(id -g) ${BASE_ARG} -f ${{ env.dockerfile }} .
68+
docker tag ${{ env.docker-registry-container-sha }} ${{ env.docker-registry-container-latest }}
69+
docker push ${{ env.docker-registry-container-sha }}
70+
docker push ${{ env.docker-registry-container-latest }}
71+
working-directory: ${{ env.docker-config-path }}
72+
if: github.event_name != 'pull_request' && env.docker-container-exists != 'true'

.github/workflows/main.yml

Lines changed: 15 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -14,67 +14,8 @@ env:
1414
docker-config-path: source/ci/docker
1515

1616
jobs:
17-
# Build the docker container images that we will use for our Linux
18-
# builds. This will identify the last commit to the repository that
19-
# updated the docker images, and try to download the image tagged with
20-
# that sha. If it does not exist, we'll do a docker build and push
21-
# the image up to GitHub Packages for the actual CI/CD runs. We tag
22-
# with both the sha and "latest" so that the subsequent runs need not
23-
# know the sha. Only do this on CI builds (when the event is a "push")
24-
# because PR builds from forks lack permission to write packages.
2517
containers:
26-
strategy:
27-
matrix:
28-
container:
29-
- name: xenial
30-
- name: bionic
31-
- name: focal
32-
- name: docurium
33-
- name: bionic-x86
34-
dockerfile: bionic
35-
base: multiarch/ubuntu-core:x86-bionic
36-
qemu: true
37-
- name: bionic-arm32
38-
dockerfile: bionic
39-
base: multiarch/ubuntu-core:armhf-bionic
40-
qemu: true
41-
- name: bionic-arm64
42-
dockerfile: bionic
43-
base: multiarch/ubuntu-core:arm64-bionic
44-
qemu: true
45-
- name: centos7
46-
- name: centos8
47-
runs-on: ubuntu-latest
48-
name: "Create container: ${{ matrix.container.name }}"
49-
steps:
50-
- name: Check out repository
51-
uses: actions/checkout@v3
52-
with:
53-
path: source
54-
fetch-depth: 0
55-
if: github.event_name != 'pull_request'
56-
- name: Setup QEMU
57-
run: docker run --rm --privileged multiarch/qemu-user-static:register --reset
58-
if: matrix.container.qemu == true
59-
- name: Download existing container
60-
run: |
61-
"${{ github.workspace }}/source/ci/getcontainer.sh" "${{ matrix.container.name }}" "${{ matrix.container.dockerfile }}"
62-
env:
63-
DOCKER_REGISTRY: ${{ env.docker-registry }}
64-
GITHUB_TOKEN: ${{ secrets.github_token }}
65-
working-directory: ${{ env.docker-config-path }}
66-
if: github.event_name != 'pull_request'
67-
- name: Build and publish image
68-
run: |
69-
if [ "${{ matrix.container.base }}" != "" ]; then
70-
BASE_ARG="--build-arg BASE=${{ matrix.container.base }}"
71-
fi
72-
docker build -t ${{ env.docker-registry-container-sha }} --build-arg UID=$(id -u) --build-arg GID=$(id -g) ${BASE_ARG} -f ${{ env.dockerfile }} .
73-
docker tag ${{ env.docker-registry-container-sha }} ${{ env.docker-registry-container-latest }}
74-
docker push ${{ env.docker-registry-container-sha }}
75-
docker push ${{ env.docker-registry-container-latest }}
76-
working-directory: ${{ env.docker-config-path }}
77-
if: github.event_name != 'pull_request' && env.docker-container-exists != 'true'
18+
uses: ./.github/workflows/build-containers.yml
7819

7920
# Run our CI/CD builds. We build a matrix with the various build targets
8021
# and their details. Then we build either in a docker container (Linux)
@@ -286,43 +227,20 @@ jobs:
286227
docker build -t ${{ env.docker-registry-container-sha }} --build-arg UID=$(id -u) --build-arg GID=$(id -g) ${BASE_ARG} -f ${{ env.dockerfile }} .
287228
working-directory: ${{ env.docker-config-path }}
288229
if: matrix.platform.container.name != '' && env.docker-container-exists != 'true'
289-
- name: Build and test
290-
run: |
291-
export GITTEST_NEGOTIATE_PASSWORD="${{ secrets.GITTEST_NEGOTIATE_PASSWORD }}"
292-
export GITTEST_GITHUB_SSH_KEY="${{ secrets.GITTEST_GITHUB_SSH_KEY }}"
293-
export GITTEST_GITHUB_SSH_PUBKEY="${{ secrets.GITTEST_GITHUB_SSH_PUBKEY }}"
294-
export GITTEST_GITHUB_SSH_PASSPHRASE="${{ secrets.GITTEST_GITHUB_SSH_PASSPHRASE }}"
295-
export GITTEST_GITHUB_SSH_REMOTE_HOSTKEY="${{ secrets.GITTEST_GITHUB_SSH_REMOTE_HOSTKEY }}"
296-
297-
if [ -n "${{ matrix.platform.container.name }}" ]; then
298-
mkdir build
299-
docker run \
300-
--rm \
301-
--user "$(id -u):$(id -g)" \
302-
-v "$(pwd)/source:/home/libgit2/source" \
303-
-v "$(pwd)/build:/home/libgit2/build" \
304-
-w /home/libgit2 \
305-
-e ASAN_SYMBOLIZER_PATH \
306-
-e CC \
307-
-e CFLAGS \
308-
-e CMAKE_GENERATOR \
309-
-e CMAKE_OPTIONS \
310-
-e GITTEST_NEGOTIATE_PASSWORD \
311-
-e GITTEST_FLAKY_STAT \
312-
-e PKG_CONFIG_PATH \
313-
-e SKIP_NEGOTIATE_TESTS \
314-
-e SKIP_SSH_TESTS \
315-
-e TSAN_OPTIONS \
316-
-e UBSAN_OPTIONS \
317-
${{ env.docker-registry-container-sha }} \
318-
/bin/bash -c "cd build && ../source/ci/build.sh && ../source/ci/test.sh"
319-
else
320-
mkdir build
321-
cd build
322-
../source/ci/build.sh
323-
../source/ci/test.sh
324-
fi
325-
shell: bash
230+
- name: Prepare build
231+
run: mkdir build
232+
- name: Build
233+
uses: ./source/.github/actions/run-build
234+
with:
235+
command: cd build && ../source/ci/build.sh
236+
container: ${{ matrix.platform.container.name }}
237+
container-version: ${{ env.docker-registry-container-sha }}
238+
- name: Test
239+
uses: ./source/.github/actions/run-build
240+
with:
241+
command: cd build && ../source/ci/test.sh
242+
container: ${{ matrix.platform.container.name }}
243+
container-version: ${{ env.docker-registry-container-sha }}
326244
- name: Upload test results
327245
uses: actions/upload-artifact@v3
328246
if: success() || failure()

.github/workflows/nightly.yml

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -340,35 +340,20 @@ jobs:
340340
run: docker build -t ${{ env.docker-registry-container-sha }} -f ${{ env.dockerfile }} .
341341
working-directory: ${{ env.docker-config-path }}
342342
if: matrix.platform.container.name != '' && env.docker-container-exists != 'true'
343-
- name: Build and test
344-
run: |
345-
export GITTEST_NEGOTIATE_PASSWORD="${{ secrets.GITTEST_NEGOTIATE_PASSWORD }}"
346-
347-
if [ -n "${{ matrix.platform.container.name }}" ]; then
348-
docker run \
349-
--rm \
350-
--user libgit2:libgit2 \
351-
-v "$(pwd)/source:/home/libgit2/source" \
352-
-w /home/libgit2 \
353-
-e ASAN_SYMBOLIZER_PATH \
354-
-e CC \
355-
-e CFLAGS \
356-
-e CMAKE_GENERATOR \
357-
-e CMAKE_OPTIONS \
358-
-e GITTEST_NEGOTIATE_PASSWORD \
359-
-e GITTEST_FLAKY_STAT \
360-
-e PKG_CONFIG_PATH \
361-
-e SKIP_NEGOTIATE_TESTS \
362-
-e SKIP_SSH_TESTS \
363-
-e TSAN_OPTIONS \
364-
${{ env.docker-registry-container-sha }} \
365-
/bin/bash -c "mkdir build && cd build && ../source/ci/build.sh && ../source/ci/test.sh"
366-
else
367-
mkdir build && cd build
368-
../source/ci/build.sh
369-
../source/ci/test.sh
370-
fi
371-
shell: bash
343+
- name: Prepare build
344+
run: mkdir build
345+
- name: Build
346+
uses: ./source/.github/actions/run-build
347+
with:
348+
command: cd build && ../source/ci/build.sh
349+
container: ${{ matrix.platform.container.name }}
350+
container-version: ${{ env.docker-registry-container-sha }}
351+
- name: Test
352+
uses: ./source/.github/actions/run-build
353+
with:
354+
command: cd build && ../source/ci/test.sh
355+
container: ${{ matrix.platform.container.name }}
356+
container-version: ${{ env.docker-registry-container-sha }}
372357

373358
coverity:
374359
# Only run scheduled workflows on the main repository; prevents people

0 commit comments

Comments
 (0)