Skip to content

Commit 2cd9fee

Browse files
committed
Make larger use of github variables
1 parent c70cdd8 commit 2cd9fee

1 file changed

Lines changed: 40 additions & 48 deletions

File tree

.github/workflows/build-python.yml

Lines changed: 40 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ jobs:
2525
build:
2626
runs-on: ubuntu-24.04-riscv
2727
env:
28-
CPYTHON_TAG: ${{ inputs.cpython_tag }}
29-
FREETHREADED: ${{ inputs.freethreaded }}
3028
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3129
steps:
3230
- name: Checkout this repo
@@ -66,109 +64,103 @@ jobs:
6664
- name: Compute normalised version
6765
id: vars
6866
run: |
69-
tag="$CPYTHON_TAG"
67+
# Make sure tag starts by v*
68+
tag="${{ inputs.cpython_tag }}"
69+
tag="${tag#v}"
70+
tag="v${tag}"
7071
# Strip leading v, expand a/b/rc suffixes
7172
normalised="${tag#v}"
7273
normalised="$(echo "$normalised" | sed -E 's/a([0-9]+)$/-alpha.\1/; s/b([0-9]+)$/-beta.\1/; s/rc([0-9]+)$/-rc.\1/')"
7374
# X.Y
7475
minor_num="$(echo "$normalised" | cut -d. -f2)"
7576
minor="3.${minor_num}"
77+
echo "tag=${tag}" >> "$GITHUB_OUTPUT"
7678
echo "normalised=${normalised}" >> "$GITHUB_OUTPUT"
7779
echo "minor=${minor}" >> "$GITHUB_OUTPUT"
7880
echo "minor_num=${minor_num}" >> "$GITHUB_OUTPUT"
7981
echo "archive_base=python-${normalised}-linux-24.04-riscv64" >> "$GITHUB_OUTPUT"
8082
echo "Normalised version: ${normalised}"
8183
echo "Python X.Y: ${minor}"
82-
if [ "${FREETHREADED}" = "true" ] && [ "${minor_num}" -lt 13 ]; then
84+
if [ "${{ inputs.freethreaded }}" = "true" ] && [ "${minor_num}" -lt 13 ]; then
8385
echo "ERROR: freethreaded build requires CPython 3.13+" >&2
8486
exit 1
8587
fi
8688
8789
- name: Checkout CPython
88-
run: git clone --depth 1 --branch "$CPYTHON_TAG" https://github.com/python/cpython.git src
90+
run: git clone --depth 1 --branch "${{ steps.vars.outputs.tag }}" https://github.com/python/cpython.git src
8991

9092
- name: Build standard CPython
91-
env:
92-
MINOR: ${{ steps.vars.outputs.minor }}
93-
ARCHIVE_BASE: ${{ steps.vars.outputs.archive_base }}
94-
NORMALISED: ${{ steps.vars.outputs.normalised }}
9593
run: |
9694
mkdir -p output
9795
pushd src
98-
./configure --prefix=/opt/hostedtoolcache/Python/${NORMALISED}/riscv64 --with-ensurepip=install --enable-shared
96+
./configure --prefix=/opt/hostedtoolcache/Python/${{ steps.vars.outputs.normalised }}/riscv64 --with-ensurepip=install --enable-shared
9997
make -j"$(nproc)" 2>&1 | tee ../build_output.txt
10098
make install DESTDIR="$PWD/../staging-std"
10199
popd
102100
103-
mkdir -p "$ARCHIVE_BASE"
104-
cp -a staging-std/usr/local/bin "$ARCHIVE_BASE/"
105-
cp -a staging-std/usr/local/include "$ARCHIVE_BASE/"
106-
cp -a staging-std/usr/local/lib "$ARCHIVE_BASE/"
107-
cp -a staging-std/usr/local/share "$ARCHIVE_BASE/"
101+
mkdir -p "${{ steps.vars.outputs.archive_base }}"
102+
cp -a staging-std/usr/local/bin "${{ steps.vars.outputs.archive_base }}/"
103+
cp -a staging-std/usr/local/include "${{ steps.vars.outputs.archive_base }}/"
104+
cp -a staging-std/usr/local/lib "${{ steps.vars.outputs.archive_base }}/"
105+
cp -a staging-std/usr/local/share "${{ steps.vars.outputs.archive_base }}/"
108106
109-
ln -srf "$ARCHIVE_BASE/bin/python${MINOR}" "$ARCHIVE_BASE/bin/python"
110-
ln -srf "$ARCHIVE_BASE/bin/pip${MINOR}" "$ARCHIVE_BASE/bin/pip"
107+
ln -srf "${{ steps.vars.outputs.archive_base }}/bin/python${{ steps.vars.outputs.minor }}" "${{ steps.vars.outputs.archive_base }}/bin/python"
108+
ln -srf "${{ steps.vars.outputs.archive_base }}/bin/pip${{ steps.vars.outputs.minor }}" "${{ steps.vars.outputs.archive_base }}/bin/pip"
111109
112-
sed -e "s|{{__VERSION_FULL__}}|${NORMALISED}|g" \
110+
sed -e "s|{{__VERSION_FULL__}}|${{ steps.vars.outputs.normalised }}|g" \
113111
-e "s|{{__ARCH__}}|riscv64|g" \
114-
installers/nix-setup-template.sh > "$ARCHIVE_BASE/setup.sh"
112+
installers/nix-setup-template.sh > "${{ steps.vars.outputs.archive_base }}/setup.sh"
115113
116-
chmod +x "$ARCHIVE_BASE/setup.sh"
114+
chmod +x "${{ steps.vars.outputs.archive_base }}/setup.sh"
117115
118-
mv build_output.txt "$ARCHIVE_BASE/build_output.txt"
116+
mv build_output.txt "${{ steps.vars.outputs.archive_base }}/build_output.txt"
119117
120-
(cd "$ARCHIVE_BASE" && find . \( -type f -o -type l \) | sed 's|^\./|/|') > "$ARCHIVE_BASE/tools_structure.txt"
118+
(cd "${{ steps.vars.outputs.archive_base }}" && find . \( -type f -o -type l \) | sed 's|^\./|/|') > "${{ steps.vars.outputs.archive_base }}/tools_structure.txt"
121119
122-
tar -czf "output/${ARCHIVE_BASE}.tar.gz" -C "$ARCHIVE_BASE" .
123-
rm -rf "$ARCHIVE_BASE" staging-std
120+
tar -czf "output/${{ steps.vars.outputs.archive_base }}.tar.gz" -C "${{ steps.vars.outputs.archive_base }}" .
121+
rm -rf "${{ steps.vars.outputs.archive_base }}" staging-std
124122
125123
- name: Build free-threaded CPython
126124
if: ${{ inputs.freethreaded == true }}
127-
env:
128-
MINOR: ${{ steps.vars.outputs.minor }}
129-
ARCHIVE_BASE: ${{ format('{0}-freethreaded', steps.vars.outputs.archive_base) }}
130-
NORMALISED: ${{ steps.vars.outputs.normalised }}
131125
run: |
132126
pushd src
133127
git clean -fdx
134-
./configure --prefix=/opt/hostedtoolcache/Python/${NORMALISED}/riscv64-freethreaded --with-ensurepip=install --enable-shared --disable-gil
128+
./configure --prefix=/opt/hostedtoolcache/Python/${{ steps.vars.outputs.normalised }}/riscv64-freethreaded --with-ensurepip=install --enable-shared --disable-gil
135129
make -j"$(nproc)" 2>&1 | tee ../build_output.txt
136130
make install DESTDIR="$PWD/../staging-ft"
137131
popd
138132
139-
mkdir -p "$ARCHIVE_BASE"
140-
cp -a staging-ft/usr/local/bin "$ARCHIVE_BASE/"
141-
cp -a staging-ft/usr/local/include "$ARCHIVE_BASE/"
142-
cp -a staging-ft/usr/local/lib "$ARCHIVE_BASE/"
143-
cp -a staging-ft/usr/local/share "$ARCHIVE_BASE/"
133+
mkdir -p "${{ steps.vars.outputs.archive_base }}-freethreaded"
134+
cp -a staging-ft/usr/local/bin "${{ steps.vars.outputs.archive_base }}-freethreaded/"
135+
cp -a staging-ft/usr/local/include "${{ steps.vars.outputs.archive_base }}-freethreaded/"
136+
cp -a staging-ft/usr/local/lib "${{ steps.vars.outputs.archive_base }}-freethreaded/"
137+
cp -a staging-ft/usr/local/share "${{ steps.vars.outputs.archive_base }}-freethreaded/"
144138
145-
ln -srf "$ARCHIVE_BASE/bin/python${MINOR}" "$ARCHIVE_BASE/bin/python"
146-
ln -srf "$ARCHIVE_BASE/bin/pip${MINOR}" "$ARCHIVE_BASE/bin/pip"
139+
ln -srf "${{ steps.vars.outputs.archive_base }}-freethreaded/bin/python${{ steps.vars.outputs.minor }}" "${{ steps.vars.outputs.archive_base }}-freethreaded/bin/python"
140+
ln -srf "${{ steps.vars.outputs.archive_base }}-freethreaded/bin/pip${{ steps.vars.outputs.minor }}" "${{ steps.vars.outputs.archive_base }}-freethreaded/bin/pip"
147141
148-
sed -e "s|{{__VERSION_FULL__}}|${NORMALISED}|g" \
142+
sed -e "s|{{__VERSION_FULL__}}|${{ steps.vars.outputs.normalised }}|g" \
149143
-e "s|{{__ARCH__}}|riscv64-freethreaded|g" \
150-
installers/nix-setup-template.sh > "$ARCHIVE_BASE/setup.sh"
144+
installers/nix-setup-template.sh > "${{ steps.vars.outputs.archive_base }}-freethreaded/setup.sh"
151145
152-
chmod +x "$ARCHIVE_BASE/setup.sh"
146+
chmod +x "${{ steps.vars.outputs.archive_base }}-freethreaded/setup.sh"
153147
154-
mv build_output.txt "$ARCHIVE_BASE/build_output.txt"
148+
mv build_output.txt "${{ steps.vars.outputs.archive_base }}-freethreaded/build_output.txt"
155149
156-
(cd "$ARCHIVE_BASE" && find . \( -type f -o -type l \) | sed 's|^\./|/|') > "$ARCHIVE_BASE/tools_structure.txt"
150+
(cd "${{ steps.vars.outputs.archive_base }}-freethreaded" && find . \( -type f -o -type l \) | sed 's|^\./|/|') > "${{ steps.vars.outputs.archive_base }}-freethreaded/tools_structure.txt"
157151
158-
tar -czf "output/${ARCHIVE_BASE}.tar.gz" -C "$ARCHIVE_BASE" .
159-
rm -rf "$ARCHIVE_BASE" staging-ft
152+
tar -czf "output/${{ steps.vars.outputs.archive_base }}-freethreaded.tar.gz" -C "${{ steps.vars.outputs.archive_base }}-freethreaded" .
153+
rm -rf "${{ steps.vars.outputs.archive_base }}-freethreaded" staging-ft
160154
161155
- name: Print tarball hashes
162156
run: sha256sum output/*.tar.gz
163157

164158
- name: Publish release
165-
env:
166-
NORMALISED: ${{ steps.vars.outputs.normalised }}
167159
run: |
168-
TAG="${NORMALISED}-${GITHUB_RUN_ID}"
160+
TAG="${{ steps.vars.outputs.normalised }}-${GITHUB_RUN_ID}"
169161
gh release create "$TAG" --repo "$GITHUB_REPOSITORY" \
170-
--title "$NORMALISED" \
171-
--notes "Python $NORMALISED" \
162+
--title "${{ steps.vars.outputs.normalised }}" \
163+
--notes "Python ${{ steps.vars.outputs.normalised }}" \
172164
./output/*.tar.gz
173165
174166
- name: Trigger manifest refresh

0 commit comments

Comments
 (0)