Skip to content

Commit f487b84

Browse files
ethomsonEdward Thomson
authored andcommitted
actions: simplify execution with composite action
1 parent 795758d commit f487b84

File tree

2 files changed

+59
-37
lines changed

2 files changed

+59
-37
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

.github/workflows/main.yml

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -286,43 +286,20 @@ jobs:
286286
docker build -t ${{ env.docker-registry-container-sha }} --build-arg UID=$(id -u) --build-arg GID=$(id -g) ${BASE_ARG} -f ${{ env.dockerfile }} .
287287
working-directory: ${{ env.docker-config-path }}
288288
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
289+
- name: Prepare build
290+
run: mkdir build
291+
- name: Build
292+
uses: ./.github/actions/run-build
293+
with:
294+
command: cd build && ../source/ci/build.sh
295+
container: ${{ matrix.platform.container.name }}
296+
container-version: ${{ env.docker-registry-container-sha }}
297+
- name: Test
298+
uses: .github/workflows/run-build.yml@ethomson/workflow
299+
with:
300+
command: cd build && ../source/ci/test.sh
301+
container: ${{ matrix.platform.container.name }}
302+
container-version: ${{ env.docker-registry-container-sha }}
326303
- name: Upload test results
327304
uses: actions/upload-artifact@v3
328305
if: success() || failure()

0 commit comments

Comments
 (0)