Skip to content

Commit aae6c2c

Browse files
authored
Fix GHA token missing bug (crazywhalecc#731)
* Update test-extensions.php * Enable UPX test * Add debug messages * Test * Revert * Update tests.yml * Update tests.yml * Explict define GITHUB_TOKEN * What's this??? * Check GITHUB_TOKEN in workflow * Test token variable in step * Test token variable inside php * Test token in command * Get env in commands * Revert workflow env, add passthrough GITHUB_TOKEN into docker * See build commands * See build commands * Typo fix * Remove debug symbol for normal mode
1 parent ca6f19f commit aae6c2c

5 files changed

Lines changed: 35 additions & 23 deletions

File tree

.github/workflows/tests.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ on:
1717
- 'box.json'
1818
- '.php-cs-fixer.php'
1919

20-
permissions:
21-
contents: read
20+
permissions: read-all
2221

2322
env:
2423
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -191,7 +190,7 @@ jobs:
191190
echo "UPX_CMD=$(php src/globals/test-extensions.php upx)" >> $GITHUB_ENV
192191
193192
- name: "Run Build Tests (download)"
194-
run: php src/globals/test-extensions.php download_cmd ${{ matrix.os }} ${{ matrix.php }}
193+
run: GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} php src/globals/test-extensions.php download_cmd ${{ matrix.os }} ${{ matrix.php }}
195194

196195
- name: "Run Build Tests (build)"
197196
run: php src/globals/test-extensions.php build_cmd ${{ matrix.os }} ${{ matrix.php }}

bin/spc-alpine-docker

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ if [ -f "$(pwd)/craft.yml" ]; then
121121
MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/craft.yml:/app/craft.yml"
122122
fi
123123

124+
# Environment variable passthrough
125+
ENV_LIST=""
126+
ENV_LIST="$ENV_LIST -e SPC_FIX_DEPLOY_ROOT="$(pwd)""
127+
if [ ! -z "$GITHUB_TOKEN" ]; then
128+
ENV_LIST="$ENV_LIST -e GITHUB_TOKEN=$GITHUB_TOKEN"
129+
fi
130+
124131
# Run docker
125132
# shellcheck disable=SC2068
126133
# shellcheck disable=SC2086
@@ -139,8 +146,8 @@ if [ "$SPC_DOCKER_DEBUG" = "yes" ]; then
139146
echo "* ./downloads: $(pwd)/downloads"
140147
echo "* ./pkgroot: $(pwd)/pkgroot"
141148
echo "*"
142-
143-
$DOCKER_EXECUTABLE run --rm $INTERACT -e SPC_FIX_DEPLOY_ROOT="$(pwd)" $MOUNT_LIST cwcc-spc-$SPC_USE_ARCH-$SPC_DOCKER_VERSION
149+
set -ex
150+
$DOCKER_EXECUTABLE run --rm $INTERACT $ENV_LIST $MOUNT_LIST cwcc-spc-$SPC_USE_ARCH-$SPC_DOCKER_VERSION
144151
else
145-
$DOCKER_EXECUTABLE run --rm $INTERACT -e SPC_FIX_DEPLOY_ROOT="$(pwd)" $MOUNT_LIST cwcc-spc-$SPC_USE_ARCH-$SPC_DOCKER_VERSION bin/spc $@
152+
$DOCKER_EXECUTABLE run --rm $INTERACT $ENV_LIST $MOUNT_LIST cwcc-spc-$SPC_USE_ARCH-$SPC_DOCKER_VERSION bin/spc $@
146153
fi

bin/spc-gnu-docker

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#!/usr/bin/env bash
22

3-
# This file is using docker to run commands
4-
set -e
5-
63
# Detect docker can run
74
if ! which docker >/dev/null; then
85
echo "Docker is not installed, please install docker first !"
@@ -143,6 +140,13 @@ echo 'SPC_LIBC=glibc' >> /tmp/spc-gnu-docker.env
143140
echo 'SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM="-Wl,-O1 -pie"' >> /tmp/spc-gnu-docker.env
144141
echo 'SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lpthread -lm -lresolv -lutil -lrt"' >> /tmp/spc-gnu-docker.env
145142

143+
# Environment variable passthrough
144+
ENV_LIST=""
145+
ENV_LIST="$ENV_LIST -e SPC_FIX_DEPLOY_ROOT="$(pwd)""
146+
if [ ! -z "$GITHUB_TOKEN" ]; then
147+
ENV_LIST="$ENV_LIST -e GITHUB_TOKEN=$GITHUB_TOKEN"
148+
fi
149+
146150
# Run docker
147151
# shellcheck disable=SC2068
148152
# shellcheck disable=SC2086
@@ -162,8 +166,8 @@ if [ "$SPC_DOCKER_DEBUG" = "yes" ]; then
162166
echo "* ./downloads: $(pwd)/downloads"
163167
echo "* ./pkgroot: $(pwd)/pkgroot"
164168
echo "*"
165-
166-
$DOCKER_EXECUTABLE run --rm -it --privileged $INTERACT -e SPC_FIX_DEPLOY_ROOT="$(pwd)" --env-file /tmp/spc-gnu-docker.env $MOUNT_LIST cwcc-spc-gnu-$SPC_USE_ARCH
169+
set -ex
170+
$DOCKER_EXECUTABLE run --rm -it --privileged $INTERACT $ENV_LIST --env-file /tmp/spc-gnu-docker.env $MOUNT_LIST cwcc-spc-gnu-$SPC_USE_ARCH
167171
else
168-
$DOCKER_EXECUTABLE run --rm $INTERACT -e SPC_FIX_DEPLOY_ROOT="$(pwd)" --env-file /tmp/spc-gnu-docker.env $MOUNT_LIST cwcc-spc-gnu-$SPC_USE_ARCH bin/spc $@
172+
$DOCKER_EXECUTABLE run --rm $INTERACT $ENV_LIST --env-file /tmp/spc-gnu-docker.env $MOUNT_LIST cwcc-spc-gnu-$SPC_USE_ARCH bin/spc $@
169173
fi

src/SPC/store/CurlHook.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,20 @@ class CurlHook
1515
*/
1616
public static function setupGithubToken(string $method, string $url, array &$headers): void
1717
{
18-
if (!getenv('GITHUB_TOKEN')) {
18+
$token = getenv('GITHUB_TOKEN');
19+
if (!$token) {
20+
logger()->debug('no github token found, skip');
1921
return;
2022
}
2123
if (getenv('GITHUB_USER')) {
22-
$auth = base64_encode(getenv('GITHUB_USER') . ':' . getenv('GITHUB_TOKEN'));
24+
$auth = base64_encode(getenv('GITHUB_USER') . ':' . $token);
2325
$he = "Authorization: Basic {$auth}";
2426
if (!in_array($he, $headers)) {
2527
$headers[] = $he;
2628
}
2729
logger()->info("using basic github token for {$method} {$url}");
2830
} else {
29-
$auth = getenv('GITHUB_TOKEN');
31+
$auth = $token;
3032
$he = "Authorization: Bearer {$auth}";
3133
if (!in_array($he, $headers)) {
3234
$headers[] = $he;

src/globals/test-extensions.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@
1313

1414
// test php version (8.1 ~ 8.4 available, multiple for matrix)
1515
$test_php_version = [
16-
'8.1',
17-
'8.2',
18-
'8.3',
16+
// '8.1',
17+
// '8.2',
18+
// '8.3',
1919
'8.4',
2020
];
2121

2222
// test os (macos-13, macos-14, macos-15, ubuntu-latest, windows-latest are available)
2323
$test_os = [
24-
'macos-13',
24+
// 'macos-13',
2525
// 'macos-14',
2626
'macos-15',
2727
'ubuntu-latest',
28-
'ubuntu-22.04',
28+
// 'ubuntu-22.04',
2929
// 'ubuntu-24.04',
30-
'ubuntu-22.04-arm',
31-
'ubuntu-24.04-arm',
30+
// 'ubuntu-22.04-arm',
31+
// 'ubuntu-24.04-arm',
3232
// 'windows-latest',
3333
];
3434

@@ -131,7 +131,7 @@ function quote2(string $param): string
131131
$doctor_cmd = 'doctor --auto-fix --debug';
132132
}
133133
if ($argv[1] === 'install_upx_cmd') {
134-
$install_upx_cmd = 'install-pkg upx';
134+
$install_upx_cmd = 'install-pkg upx --debug';
135135
}
136136

137137
$prefix = match ($argv[2] ?? null) {

0 commit comments

Comments
 (0)