Skip to content

Commit a592569

Browse files
committed
fix(ci): install deps once then cache
1 parent e67744b commit a592569

File tree

3 files changed

+135
-63
lines changed

3 files changed

+135
-63
lines changed

.appveyor.yml

Lines changed: 0 additions & 52 deletions
This file was deleted.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: "Install p2pd"
2+
inputs:
3+
os:
4+
required: true
5+
cpu:
6+
required: true
7+
version:
8+
default: v0.9.1
9+
required: false
10+
11+
runs:
12+
using: "composite"
13+
steps:
14+
- name: Download and install p2pd
15+
shell: bash
16+
run: |
17+
set -eux # Fail on error and print each command
18+
mkdir -p .ci-bin
19+
20+
if [[ "${{ inputs.os }}" == windows* ]]; then
21+
# Windows: download the ZIP and extract p2pd.exe
22+
if [ "${{ inputs.cpu }}" = "amd64" ]; then
23+
curl -fsSL -H "Accept: application/octet-stream" -o "p2pd-${{ inputs.version }}-win32-amd64.zip" "https://github.com/libp2p/go-libp2p-daemon/releases/download/${{ inputs.version }}/p2pd-${{ inputs.version }}-win32-amd64.zip"
24+
unzip -o "p2pd-${{ inputs.version }}-win32-amd64.zip"
25+
mv p2pd.exe .ci-bin/p2pd.exe
26+
elif [ "${{ inputs.cpu }}" = "arm64" ]; then
27+
curl -fsSL -H "Accept: application/octet-stream" -o "p2pd-${{ inputs.version }}-win32-arm64.zip" "https://github.com/libp2p/go-libp2p-daemon/releases/download/${{ inputs.version }}/p2pd-${{ inputs.version }}-win32-arm64.zip"
28+
unzip -o "p2pd-${{ inputs.version }}-win32-arm64.zip"
29+
mv p2pd.exe .ci-bin/p2pd.exe
30+
else
31+
echo "No official Windows build for ${{ inputs.cpu }}. Exiting..."
32+
exit 1
33+
fi
34+
35+
elif [[ "${{ inputs.os }}" == macos* ]]; then
36+
# macOS: download and extract the tarball
37+
if [ "${{ inputs.cpu }}" = "arm64" ]; then
38+
echo "No official macOS arm64 build available for p2pd v${{ inputs.version }}. Skipping installation."
39+
# Create a dummy script so later steps don't fail.
40+
echo "#!/bin/bash" > .ci-bin/p2pd
41+
echo "echo 'p2pd is not installed on macOS arm64'" >> .ci-bin/p2pd
42+
elif [ "${{ inputs.cpu }}" = "amd64" ]; then
43+
curl -fsSL -H "Accept: application/octet-stream" -o "p2pd-${{ inputs.version }}-darwin.tar.gz" "https://github.com/libp2p/go-libp2p-daemon/releases/download/${{ inputs.version }}/p2pd-${{ inputs.version }}-darwin.tar.gz"
44+
tar --strip-components=1 -xf "p2pd-${{ inputs.version }}-darwin.tar.gz"
45+
# The tarball should extract a file named “p2pd-darwin” or “p2pd”
46+
if [ -f p2pd-darwin ]; then
47+
mv p2pd-darwin .ci-bin/p2pd
48+
else
49+
mv p2pd .ci-bin/p2pd
50+
fi
51+
else
52+
echo "No official macOS build for ${{ inputs.cpu }}. Exiting..."
53+
exit 1
54+
fi
55+
chmod +x .ci-bin/p2pd
56+
57+
else
58+
# Linux: download and extract the tar archive
59+
if [ "${{ inputs.cpu }}" = "i386" ]; then
60+
curl -fsSL -H "Accept: application/octet-stream" -o "p2pd-${{ inputs.version }}-linux-386.tar.gz" "https://github.com/libp2p/go-libp2p-daemon/releases/download/${{ inputs.version }}/p2pd-${{ inputs.version }}-linux-386.tar.gz"
61+
tar --strip-components=1 -xf "p2pd-${{ inputs.version }}-linux-386.tar.gz"
62+
mv p2pd-linux-386 .ci-bin/p2pd
63+
chmod +x .ci-bin/p2pd
64+
elif [ "${{ inputs.cpu }}" = "arm64" ]; then
65+
curl -fsSL -H "Accept: application/octet-stream" -o "p2pd-${{ inputs.version }}-linux-arm64.tar.gz" "https://github.com/libp2p/go-libp2p-daemon/releases/download/${{ inputs.version }}/p2pd-${{ inputs.version }}-linux-arm64.tar.gz"
66+
tar --strip-components=1 -xf "p2pd-${{ inputs.version }}-linux-arm64.tar.gz"
67+
mv p2pd-linux-arm64 .ci-bin/p2pd
68+
chmod +x .ci-bin/p2pd
69+
else
70+
# Assume amd64
71+
curl -fsSL -H "Accept: application/octet-stream" -o "p2pd-${{ inputs.version }}-linux-amd64.tar.gz" "https://github.com/libp2p/go-libp2p-daemon/releases/download/${{ inputs.version }}/p2pd-${{ inputs.version }}-linux-amd64.tar.gz"
72+
tar --strip-components=1 -xf "p2pd-${{ inputs.version }}-linux-amd64.tar.gz"
73+
mv p2pd-linux-amd64 .ci-bin/p2pd
74+
chmod +x .ci-bin/p2pd
75+
fi
76+
fi
77+
78+
echo "${PWD}/.ci-bin" >> $GITHUB_PATH

.github/workflows/ci.yml

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,27 +78,76 @@ jobs:
7878
shell: ${{ matrix.shell }}
7979
nim_ref: ${{ matrix.nim.ref }}
8080

81-
- name: Setup Go
81+
# Restore p2pd from cache
82+
- name: Restore p2pd from cache
83+
id: p2pd-cache
84+
uses: actions/cache@v3
85+
with:
86+
path: .ci-bin
87+
key: p2pd-${{ matrix.platform.os }}-${{ matrix.platform.cpu }}-v0.9.1-1
88+
89+
# For macOS arm64, build from source
90+
- name: Setup Go for macOS arm64
91+
if: matrix.platform.os == 'macos-14' && matrix.platform.cpu == 'arm64' && steps.p2pd-cache.outputs.cache-hit != 'true'
8292
uses: actions/setup-go@v5
8393
with:
84-
go-version: '~1.16.0' # That's the minimum Go version that works with arm.
94+
go-version: '~1.16.0'
8595

86-
- name: Install p2pd
96+
- name: Build p2pd from source for macOS arm64
97+
if: matrix.platform.os == 'macos-14' && matrix.platform.cpu == 'arm64' && steps.p2pd-cache.outputs.cache-hit != 'true'
8798
run: |
99+
mkdir -p .ci-bin
88100
V=1 bash scripts/build_p2pd.sh p2pdCache 124530a3
101+
102+
# Ensure binary was built and is in .ci-bin
103+
if [ -f p2pd ]; then
104+
mv p2pd .ci-bin/p2pd
105+
chmod +x .ci-bin/p2pd
106+
fi
107+
108+
# Verify it works
109+
.ci-bin/p2pd --version || echo "Warning: p2pd version check failed"
110+
111+
# Add to PATH
112+
echo "${{ github.workspace }}/.ci-bin" >> $GITHUB_PATH
113+
export PATH="${{ github.workspace }}/.ci-bin:$PATH"
114+
115+
# For all other platforms, use pre-built binaries
116+
- name: Install p2pd binary
117+
if: (!(matrix.platform.os == 'macos-14' && matrix.platform.cpu == 'arm64')) && steps.p2pd-cache.outputs.cache-hit != 'true'
118+
uses: "./.github/actions/install_p2pd"
119+
with:
120+
os: ${{ matrix.platform.os }}
121+
cpu: ${{ matrix.platform.cpu }}
89122

123+
# Ensure p2pd is in PATH for all platforms
124+
- name: Add p2pd to PATH
125+
run: |
126+
mkdir -p .ci-bin
127+
if [[ "${{ matrix.platform.os }}" != windows* ]]; then
128+
chmod +x .ci-bin/p2pd || true
129+
fi
130+
echo "${{ github.workspace }}/.ci-bin" >> $GITHUB_PATH
131+
export PATH="${{ github.workspace }}/.ci-bin:$PATH"
132+
133+
# Test p2pd
134+
if [[ "${{ matrix.platform.os }}" == windows* ]]; then
135+
.ci-bin/p2pd.exe --version || echo "Warning: p2pd version check failed"
136+
else
137+
.ci-bin/p2pd --version || echo "Warning: p2pd version check failed"
138+
fi
139+
140+
# Rest of the CI steps
90141
- name: Restore deps from cache
91142
id: deps-cache
92143
uses: actions/cache@v3
93144
with:
94145
path: nimbledeps
95-
# Using nim.ref as a simple way to differentiate between nimble using the "pkgs" or "pkgs2" directories.
96-
# The change happened on Nimble v0.14.0. Also forcing the deps to be reinstalled on each os and cpu.
97-
key: nimbledeps-${{ matrix.nim.ref }}-${{ matrix.builder }}-${{ matrix.platform.cpu }}-${{ hashFiles('.pinned') }} # hashFiles returns a different value on windows
146+
key: nimbledeps-${{ matrix.nim.ref }}-${{ matrix.builder }}-${{ matrix.platform.cpu }}-${{ hashFiles('.pinned') }}
98147

99148
- name: Setup python
100149
run: |
101-
mkdir .venv
150+
mkdir -p .venv
102151
python -m venv .venv
103152
104153
- name: Install deps
@@ -108,21 +157,18 @@ jobs:
108157
nimble install_pinned
109158
110159
- name: Use gcc 14
111-
if : ${{ matrix.platform.os == 'linux-gcc-14'}}
160+
if: ${{ matrix.platform.os == 'linux-gcc-14' }}
112161
run: |
113162
# Add GCC-14 to alternatives
114163
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 14
115-
116164
# Set GCC-14 as the default
117165
sudo update-alternatives --set gcc /usr/bin/gcc-14
118166
119167
- name: Run tests
120168
run: |
121169
source .venv/bin/activate
122-
123170
nim --version
124171
nimble --version
125172
gcc --version
126-
127173
NIMFLAGS="${NIMFLAGS} --mm:${{ matrix.nim.memory_management }}"
128174
nimble test

0 commit comments

Comments
 (0)