diff --git a/.github/workflows/build-runtime.yml b/.github/workflows/build-runtime.yml index f61cfb2..a11e19f 100644 --- a/.github/workflows/build-runtime.yml +++ b/.github/workflows/build-runtime.yml @@ -252,8 +252,7 @@ jobs: } $tag = "runtime-$($env:RELEASE_ID)" git fetch --tags origin - $auth = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("Nwflower:$($env:GITCODE_TOKEN)")) - git -c "http.extraheader=Authorization: Basic $auth" push "https://gitcode.com/Nwflower/Reims-Go.git" "refs/tags/${tag}:refs/tags/${tag}" + git -c credential.helper= push "https://Nwflower:$($env:GITCODE_TOKEN)@gitcode.com/Nwflower/Reims-Go.git" "refs/tags/${tag}:refs/tags/${tag}" python scripts/sync-gitcode-release.py $tag - name: Prune old alpha prereleases diff --git a/.github/workflows/sync-gitcode.yml b/.github/workflows/sync-gitcode.yml index 0fc1b52..7fa6967 100644 --- a/.github/workflows/sync-gitcode.yml +++ b/.github/workflows/sync-gitcode.yml @@ -41,10 +41,19 @@ jobs: exit 0 fi git fetch --tags origin - # Configure token via extraheader so it never appears in remote URLs/logs. - auth="$(printf '%s:%s' "$GITCODE_USER" "$GITCODE_TOKEN" | base64 -w0)" - git -c "http.extraheader=Authorization: Basic $auth" push "https://gitcode.com/${GITCODE_REPO}.git" HEAD:refs/heads/main - git -c "http.extraheader=Authorization: Basic $auth" push "https://gitcode.com/${GITCODE_REPO}.git" --tags + # Use GIT_ASKPASS so the token never appears in URLs or process argv. + askpass="$(mktemp)" + chmod 700 "$askpass" + cat > "$askpass" <<'EOF' + #!/bin/sh + case "$1" in + *Username*) printf '%s\n' "$GITCODE_USER" ;; + *) printf '%s\n' "$GITCODE_TOKEN" ;; + esac + EOF + trap 'rm -f "$askpass"' EXIT + GIT_TERMINAL_PROMPT=0 GIT_ASKPASS="$askpass" git -c credential.helper= push "https://gitcode.com/${GITCODE_REPO}.git" HEAD:refs/heads/main + GIT_TERMINAL_PROMPT=0 GIT_ASKPASS="$askpass" git -c credential.helper= push "https://gitcode.com/${GITCODE_REPO}.git" --tags - name: Sync Release and assets to GitCode if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && inputs.sync_releases) diff --git a/internal/cli/runtime_fetch.go b/internal/cli/runtime_fetch.go index 36fff70..9b79d2e 100644 --- a/internal/cli/runtime_fetch.go +++ b/internal/cli/runtime_fetch.go @@ -108,14 +108,20 @@ func alphaFlag(fs *flag.FlagSet, cfg *config.Config, usage string) *bool { return v } -// flagsFirst moves "-x" arguments before positional ones, so -// "fetch latest --alpha" works like "fetch --alpha latest" (the flag -// package stops at the first positional argument). +// flagsFirst moves "-x" arguments (and their values for value flags like +// --source) before positional ones, so "fetch latest --source gitcode --alpha" +// works like "fetch --source gitcode --alpha latest" (the flag package stops +// at the first positional argument). func flagsFirst(args []string) []string { var flags, rest []string - for _, a := range args { + for i := 0; i < len(args); i++ { + a := args[i] if len(a) > 1 && a[0] == '-' { flags = append(flags, a) + if (a == "-source" || a == "--source") && i+1 < len(args) { + i++ + flags = append(flags, args[i]) + } } else { rest = append(rest, a) }