Skip to content

Commit 87d4190

Browse files
committed
Refactor CI with composite action
1 parent 820d0c1 commit 87d4190

File tree

4 files changed

+100
-36
lines changed

4 files changed

+100
-36
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Setup Nix
2+
description: Initialize nixos/nix container
3+
inputs:
4+
image:
5+
description: 'Set up an environment with specified nix container image'
6+
required: false
7+
default: 'docker.io/nixos/nix:latest'
8+
packages:
9+
description: 'Set up an environment in which the specified packages are present'
10+
required: false
11+
default: ''
12+
runs:
13+
using: composite
14+
steps:
15+
- run: /usr/bin/docker pull ${{ inputs.image }}
16+
shell: bash
17+
18+
- id: container
19+
run: echo "id=$(/usr/bin/docker create --workdir "$GITHUB_WORKSPACE" -e GITHUB_ACTIONS=true -e CI=true -v /var/run/docker.sock:/var/run/docker.sock -v "$GITHUB_WORKSPACE:$GITHUB_WORKSPACE" --entrypoint sleep ${{ inputs.image }} infinity)" | tee -a "$GITHUB_OUTPUT"
20+
shell: bash
21+
22+
- run: /usr/bin/docker start ${{ steps.container.outputs.id }}
23+
shell: bash
24+
25+
- run: /usr/bin/docker ps --all --filter id=${{ steps.container.outputs.id }} --filter status=running --no-trunc --format "{{.ID}} {{.Status}}"
26+
shell: bash
27+
28+
- run: /usr/bin/docker inspect --format "{{range .Config.Env}}{{println .}}{{end}}" ${{ steps.container.outputs.id }}
29+
shell: bash
30+
31+
- run: |
32+
mkdir -p "$HOME/.local/bin" && tee "$HOME/.local/bin/bash" <<'EOF' && chmod a+x "$HOME/.local/bin/bash"
33+
#!/bin/bash --
34+
exec /usr/bin/docker exec -i -w "$PWD" ${{ steps.container.outputs.id }} nix-shell --packages ${{ inputs.packages }} --run "exec bash$(test $# -gt 0 && printf ' %q' "${@:1:$#-1}")" <"${@:$#}"
35+
EOF
36+
shell: bash
37+
38+
- run: env
39+
shell: bash
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Setup vm
2+
description: Initialize virtual machine
3+
inputs:
4+
os:
5+
description: 'Set up an environment with specified os'
6+
required: true
7+
run:
8+
description: 'Set up an environment with specified run command'
9+
required: false
10+
default: ''
11+
runs:
12+
using: composite
13+
steps:
14+
- uses: vmactions/freebsd-vm@v1
15+
if: inputs.os == 'freebsd'
16+
with:
17+
copyback: false
18+
usesh: true
19+
prepare: pkg install -y bash
20+
run: set -e; ${{ inputs.run }}
21+
22+
- uses: vmactions/openbsd-vm@v1
23+
if: inputs.os == 'openbsd'
24+
with:
25+
copyback: false
26+
usesh: true
27+
prepare: pkg_add bash
28+
run: set -e; ${{ inputs.run }}
29+
30+
- run: |
31+
mkdir -p "$HOME/.local/bin" && tee "$HOME/.local/bin/bash" <<'EOF' && chmod a+x "$HOME/.local/bin/bash"
32+
#!/bin/bash --
33+
exec ssh ${{ inputs.os }} "cd $(printf %q "$PWD") && exec bash$(test $# -gt 0 && printf ' %q' "${@:1:$#-1}")" <"${@:$#}"
34+
EOF
35+
shell: bash
36+
37+
- run: env
38+
shell: bash

.github/dependabot.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
version: 2
22
updates:
33
- package-ecosystem: "github-actions"
4-
directory: "/"
4+
directories:
5+
- "/"
6+
- "/.github/actions/*/"
57
schedule:
68
interval: "daily"
79

.github/workflows/build.yml

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -70,51 +70,36 @@ jobs:
7070
container:
7171
image: docker.io/nixos/nix:latest
7272
- os: ubuntu-latest
73-
vm: freebsd
73+
vm:
74+
os: freebsd
75+
run: pkg install -y node npm protobuf ruby rubygem-bundler rubygem-rake
7476
- os: ubuntu-latest
75-
vm: openbsd
77+
vm:
78+
os: openbsd
79+
run: |
80+
ruby=$(pkg_info -Q ruby | grep '^ruby-[0-9]' | sort -rV | head -n 1)
81+
pkg_add node protobuf "$ruby"
82+
pkg_info "$ruby" | grep 'ln -sf' | $SHELL
7683
7784
steps:
7885
- name: Checkout
7986
uses: actions/checkout@v4
8087

81-
- name: Setup vm (freebsd)
82-
if: matrix.vm == 'freebsd'
83-
uses: vmactions/freebsd-vm@v1
84-
85-
- name: Setup vm (openbsd)
86-
if: matrix.vm == 'openbsd'
87-
uses: vmactions/openbsd-vm@v1
88-
89-
- name: Setup vm shell
88+
- name: Initialize vm
9089
if: matrix.vm
91-
run: |
92-
mkdir -p "$HOME/.local/bin" && tee "$HOME/.local/bin/bash" <<'EOF' && chmod a+x "$HOME/.local/bin/bash"
93-
#!/bin/bash --
94-
exec ssh ${{ matrix.vm }} "cd $(printf %q "$PWD") && exec \"\$SHELL\"$(test $# -gt 0 && printf ' %q' "${@:1:$#-1}")" <"${@:$#}"
95-
EOF
90+
uses: ./.github/actions/setup-vm
91+
with:
92+
os: ${{ matrix.vm.os }}
93+
run: ${{ matrix.vm.run }}
9694

97-
- name: Setup nix-shell
95+
- name: Initialize nix
9896
if: matrix.container.image == 'docker.io/nixos/nix:latest'
99-
run: |
100-
docker run --rm -d --name nix --volume "$PWD:$PWD" --entrypoint sleep ${{ matrix.container.image }} infinity
101-
mkdir -p "$HOME/.local/bin" && tee "$HOME/.local/bin/bash" <<'EOF' && chmod a+x "$HOME/.local/bin/bash"
102-
#!/bin/bash --
103-
exec docker exec -i -w "$PWD" nix nix-shell --packages ruby --run "exec \"\$SHELL\"$(test $# -gt 0 && printf ' %q' "${@:1:$#-1}")" <"${@:$#}"
104-
EOF
105-
106-
- name: Install dependencies (freebsd)
107-
if: matrix.vm == 'freebsd'
108-
run: pkg install -y node npm protobuf ruby rubygem-bundler rubygem-rake
109-
110-
- name: Install dependencies (openbsd)
111-
if: matrix.vm == 'openbsd'
112-
run: |
113-
ruby=$(pkg_info -Q ruby | grep '^ruby-[0-9]' | sort -rV | head -n 1)
114-
pkg_add node protobuf "$ruby"
115-
pkg_info "$ruby" | grep 'ln -sf' | $SHELL
97+
uses: ./.github/actions/setup-nix
98+
with:
99+
image: ${{ matrix.container.image }}
100+
packages: ruby
116101

117-
- name: Install dependencies (alpine)
102+
- name: Install dependencies
118103
if: endsWith(matrix.container.image, ':alpine') || endsWith(matrix.container.image, '-alpine')
119104
run: apk add build-base
120105

0 commit comments

Comments
 (0)