Skip to content

Commit 41e6a55

Browse files
Refactor to composite actions
1 parent 4185483 commit 41e6a55

File tree

6 files changed

+145
-97
lines changed

6 files changed

+145
-97
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: 'Colima Setup'
2+
description: 'Sets up Colima'
3+
inputs:
4+
runner:
5+
description: 'The runner type (e.g., macos-latest)'
6+
required: true
7+
runs:
8+
using: "composite"
9+
steps:
10+
- name: Colima constraints
11+
shell: bash
12+
run: |
13+
if [[ ! "${{ inputs.runner }}" =~ ^macos.* ]]; then
14+
echo "::error::Colima is only supported on macOS"
15+
exit 1
16+
fi
17+
- name: Colima setup
18+
shell: bash
19+
run: |
20+
brew install docker docker-compose colima
21+
colima start --cpu 3 --memory 14 --disk 14 --runtime docker
22+
colima status
23+
colima --version
24+
echo "DOCKER_HOST=unix://${HOME}/.colima/default/docker.sock" >> $GITHUB_ENV
25+
echo "TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE=/var/run/docker.sock" >> $GITHUB_ENV
26+
echo "NODE_OPTIONS=--dns-result-order=ipv4first" >> $GITHUB_ENV
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: 'Docker Rootless Setup'
2+
description: 'Sets up Docker in rootless mode'
3+
runs:
4+
using: "composite"
5+
steps:
6+
- name: Docker rootless setup 1/2
7+
uses: ScribeMD/[email protected]
8+
- name: Docker rootless setup 2/2
9+
shell: bash
10+
run: |
11+
sudo rm -rf /var/run/docker.sock
12+
echo "CI_ROOTLESS=true" >> $GITHUB_ENV
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: 'Podman Setup'
2+
description: 'Sets up Podman'
3+
runs:
4+
using: "composite"
5+
steps:
6+
- name: Podman setup
7+
shell: bash
8+
run: |
9+
curl -fsSL "https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/unstable/xUbuntu_$(lsb_release -rs)/Release.key" | gpg --dearmor | sudo tee /etc/apt/keyrings/devel_kubic_libcontainers_unstable.gpg > /dev/null
10+
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/devel_kubic_libcontainers_unstable.gpg] https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/unstable/xUbuntu_$(lsb_release -rs)/ /" | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:unstable.list > /dev/null
11+
sudo apt-get update
12+
sudo apt-get -y install podman
13+
systemctl enable --now --user podman podman.socket
14+
podman info
15+
echo "DOCKER_HOST=unix://${XDG_RUNTIME_DIR}/podman/podman.sock" >> $GITHUB_ENV
16+
echo "CI_ROOTLESS=true" >> $GITHUB_ENV
17+
echo "CI_PODMAN=true" >> $GITHUB_ENV
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: 'Rancher Desktop Setup'
2+
description: 'Sets up Rancher Desktop'
3+
inputs:
4+
runner:
5+
description: 'The runner type (e.g., macos-latest)'
6+
required: true
7+
runs:
8+
using: "composite"
9+
steps:
10+
- name: Rancher Desktop constraints
11+
shell: bash
12+
run: |
13+
if [[ ! "${{ inputs.runner }}" =~ ^macos.* ]]; then
14+
echo "::error::Rancher Desktop is only supported on macOS"
15+
exit 1
16+
fi
17+
- name: Rancher Desktop setup
18+
shell: bash
19+
run: |
20+
brew install docker docker-compose
21+
brew install --cask rancher
22+
23+
TIMEOUT_SECS_CLI_TOOLS=60
24+
TIMEOUT_SECS_USER_SOCKET=300
25+
26+
echo "Open Rancher Desktop app"
27+
open "/Applications/Rancher Desktop.app"
28+
29+
echo "Wait max of ${TIMEOUT_SECS_CLI_TOOLS}s for Rancher Desktop to create CLI tools"
30+
for i in $(seq 1 ${TIMEOUT_SECS_CLI_TOOLS}); do
31+
if [ -e "$HOME/.rd/bin/rdctl" ]; then
32+
echo "Rancher Desktop CLI tools created after ${i}s"
33+
break
34+
fi
35+
sleep 1
36+
done
37+
38+
if [ ! -e "$HOME/.rd/bin/rdctl" ]; then
39+
echo "Rancher Desktop CLI tools not found"
40+
exit 1
41+
fi
42+
43+
echo "Rancher Desktop initialised successfully, now configure the container runtime"
44+
$HOME/.rd/bin/rdctl set \
45+
--container-engine.name=moby \
46+
--application.admin-access=false \
47+
--kubernetes.enabled=false \
48+
--application.start-in-background=true \
49+
--application.path-management-strategy=manual \
50+
--virtual-machine.number-cpus=3 \
51+
--virtual-machine.memory-in-gb=14 \
52+
|| true
53+
54+
echo "Restart Rancher Desktop"
55+
$HOME/.rd/bin/rdctl shutdown
56+
$HOME/.rd/bin/rdctl start
57+
58+
echo "Wait max of ${TIMEOUT_SECS_USER_SOCKET}s for Rancher socket"
59+
60+
for i in $(seq 1 ${TIMEOUT_SECS_USER_SOCKET}); do
61+
if [ -e "$HOME/.rd/docker.sock" ]; then
62+
echo "Rancher Desktop socket created after ${i}s"
63+
break
64+
fi
65+
sleep 1
66+
done
67+
68+
if [ ! -e "$HOME/.rd/docker.sock" ]; then
69+
echo "Rancher Desktop socket not found"
70+
exit 1
71+
fi
72+
73+
echo "{}" > $HOME/.docker/config.json
74+
75+
echo "DOCKER_HOST=unix://${HOME}/.rd/docker.sock" >> $GITHUB_ENV
76+
echo "TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE=/var/run/docker.sock" >> $GITHUB_ENV
77+
echo "NODE_OPTIONS=--dns-result-order=ipv4first" >> $GITHUB_ENV

.github/workflows/test-template.yml

Lines changed: 11 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -18,110 +18,25 @@ jobs:
1818
test:
1919
runs-on: ${{ inputs.runner }}
2020
steps:
21-
- name: Docker rootless setup 1/2
21+
- name: Docker rootless setup
2222
if: ${{ inputs.container-runtime == 'docker-rootless' }}
23-
uses: ScribeMD/[email protected]
24-
- name: Docker rootless setup 2/2
25-
if: ${{ inputs.container-runtime == 'docker-rootless' }}
26-
run: |
27-
sudo rm -rf /var/run/docker.sock
28-
echo "CI_ROOTLESS=true" >> $GITHUB_ENV
23+
uses: ./.github/actions/docker-rootless-setup
2924

3025
- name: Podman setup
3126
if: ${{ inputs.container-runtime == 'podman' }}
32-
run: |
33-
curl -fsSL "https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/unstable/xUbuntu_$(lsb_release -rs)/Release.key" | gpg --dearmor | sudo tee /etc/apt/keyrings/devel_kubic_libcontainers_unstable.gpg > /dev/null
34-
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/devel_kubic_libcontainers_unstable.gpg] https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/unstable/xUbuntu_$(lsb_release -rs)/ /" | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:unstable.list > /dev/null
35-
sudo apt-get update
36-
sudo apt-get -y install podman
37-
systemctl enable --now --user podman podman.socket
38-
podman info
39-
echo "DOCKER_HOST=unix://${XDG_RUNTIME_DIR}/podman/podman.sock" >> $GITHUB_ENV
40-
echo "CI_ROOTLESS=true" >> $GITHUB_ENV
41-
echo "CI_PODMAN=true" >> $GITHUB_ENV
27+
uses: ./.github/actions/podman-setup
4228

43-
- name: Colima constraints
44-
if: ${{ inputs.container-runtime == 'colima' && !startsWith(inputs.runner, 'macos') }}
45-
run: |
46-
run: echo "::error::Colima is only supported on macOS"
47-
exit 1
4829
- name: Colima setup
4930
if: ${{ inputs.container-runtime == 'colima' }}
50-
run: |
51-
brew install docker docker-compose colima
52-
colima start --cpu 3 --memory 14 --disk 14 --runtime docker
53-
colima status
54-
colima --version
55-
echo "DOCKER_HOST=unix://${HOME}/.colima/default/docker.sock" >> $GITHUB_ENV
56-
echo "TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE=/var/run/docker.sock" >> $GITHUB_ENV
57-
echo "NODE_OPTIONS=--dns-result-order=ipv4first" >> $GITHUB_ENV
31+
uses: ./.github/actions/colima-setup
32+
with:
33+
runner: ${{ inputs.runner }}
5834

59-
- name: Rancher Desktop constraints
60-
if: ${{ inputs.container-runtime == 'rancher-desktop' && !startsWith(inputs.runner, 'macos') }}
61-
run: |
62-
run: echo "::error::Rancher Desktop is only supported on macOS"
63-
exit 1
6435
- name: Rancher Desktop setup
6536
if: ${{ inputs.container-runtime == 'rancher-desktop' }}
66-
run: |
67-
brew install docker docker-compose
68-
brew install --cask rancher
69-
70-
TIMEOUT_SECS_CLI_TOOLS=60
71-
TIMEOUT_SECS_USER_SOCKET=300
72-
73-
echo "Open Rancher Desktop app"
74-
open "/Applications/Rancher Desktop.app"
75-
76-
echo "Wait max of ${TIMEOUT_SECS_CLI_TOOLS}s for Rancher Desktop to create CLI tools"
77-
for i in $(seq 1 ${TIMEOUT_SECS_CLI_TOOLS}); do
78-
if [ -e "$HOME/.rd/bin/rdctl" ]; then
79-
echo "Rancher Desktop CLI tools created after ${i}s"
80-
break
81-
fi
82-
sleep 1
83-
done
84-
85-
if [ ! -e "$HOME/.rd/bin/rdctl" ]; then
86-
echo "Rancher Desktop CLI tools not found"
87-
exit 1
88-
fi
89-
90-
echo "Rancher Desktop initialised successfully, now configure the container runtime"
91-
$HOME/.rd/bin/rdctl set \
92-
--container-engine.name=moby \
93-
--application.admin-access=false \
94-
--kubernetes.enabled=false \
95-
--application.start-in-background=true \
96-
--application.path-management-strategy=manual \
97-
--virtual-machine.number-cpus=3 \
98-
--virtual-machine.memory-in-gb=14 \
99-
|| true
100-
101-
echo "Restart Rancher Desktop"
102-
$HOME/.rd/bin/rdctl shutdown
103-
$HOME/.rd/bin/rdctl start
104-
105-
echo "Wait max of ${TIMEOUT_SECS_USER_SOCKET}s for Rancher socket"
106-
107-
for i in $(seq 1 ${TIMEOUT_SECS_USER_SOCKET}); do
108-
if [ -e "$HOME/.rd/docker.sock" ]; then
109-
echo "Rancher Desktop socket created after ${i}s"
110-
break
111-
fi
112-
sleep 1
113-
done
114-
115-
if [ ! -e "$HOME/.rd/docker.sock" ]; then
116-
echo "Rancher Desktop socket not found"
117-
exit 1
118-
fi
119-
120-
echo "{}" > $HOME/.docker/config.json
121-
122-
echo "DOCKER_HOST=unix://${HOME}/.rd/docker.sock" >> $GITHUB_ENV
123-
echo "TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE=/var/run/docker.sock" >> $GITHUB_ENV
124-
echo "NODE_OPTIONS=--dns-result-order=ipv4first" >> $GITHUB_ENV
37+
uses: ./.github/actions/rancher-desktop-setup
38+
with:
39+
runner: ${{ inputs.runner }}
12540

12641
- name: Code checkout
12742
uses: actions/checkout@v4
@@ -135,4 +50,5 @@ jobs:
13550
workspace: "${{ inputs.workspace }}"
13651

13752
- name: Run tests
138-
run: npm run test:ci -- --coverage.include=${{ steps.npm-install.outputs.workspace_path }} ${{ steps.npm-install.outputs.workspace_path }}
53+
run:
54+
npm run test:ci -- --coverage.include=${{ steps.npm-install.outputs.workspace_path }} ${{ steps.npm-install.outputs.workspace_path }}

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ jobs:
6262
- name: Code checkout
6363
uses: actions/checkout@v4
6464
- name: Install Node and Dependencies
65-
id: npm-install
65+
id: npm-install-modules
6666
uses: ./.github/actions/npm-setup
6767
with:
6868
runner: ubuntu-22.04
6969
node-version: 24.x
7070
workspace: "${{ matrix.module }}"
7171
- name: Code linting
7272
env:
73-
WORKSPACE_PATH: ${{ steps.npm-install.outputs.workspace_path }}
73+
WORKSPACE_PATH: ${{ steps.npm-install-modules.outputs.workspace_path }}
7474
run: npm run lint:ci
7575

7676
compile:

0 commit comments

Comments
 (0)