Compare commits

..
18 changed files with 723 additions and 119 deletions

No files matched your search

+81 -24
View File
@@ -16,11 +16,11 @@ on:
gp_branch: gp_branch:
description: 'GlobalProtect-openconnect ref to build (use the matching tag for stable builds)' description: 'GlobalProtect-openconnect ref to build (use the matching tag for stable builds)'
required: true required: true
default: dev default: release/next
gpgui_branch: gpgui_branch:
description: 'gpgui branch or tag to build and test (use the matching tag for stable builds)' description: 'gpgui branch or tag to build and test (use the matching tag for stable builds)'
required: true required: true
default: dev default: release/next
build_macos: build_macos:
description: 'Build Apple Silicon artifacts for this run' description: 'Build Apple Silicon artifacts for this run'
required: true required: true
@@ -54,6 +54,12 @@ concurrency:
jobs: jobs:
validate-inputs: validate-inputs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions:
actions: read
contents: read
outputs:
gp_sha: ${{ steps.sources.outputs.gp_sha }}
gpgui_sha: ${{ steps.sources.outputs.gpgui_sha }}
steps: steps:
- name: Validate stable refs - name: Validate stable refs
env: env:
@@ -69,6 +75,53 @@ jobs:
fi fi
fi fi
- name: Checkout CI helpers
uses: actions/checkout@v6
- name: Restore selected sources on retry
id: restored
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
artifacts="$(gh api "repos/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID/artifacts?per_page=100")"
existing="$(jq -r '.artifacts[] | select(.name == "build-source-refs") | .id' <<<"$artifacts")"
if [[ -n "$existing" ]]; then
gh run download "$GITHUB_RUN_ID" --repo "$GITHUB_REPOSITORY" \
--name build-source-refs --dir selected-sources
echo "cached=true" >> "$GITHUB_OUTPUT"
elif [[ "$GITHUB_RUN_ATTEMPT" -gt 1 ]]; then
echo "Retained source refs are unavailable; start a fresh dispatch." >&2
exit 1
else
echo "cached=false" >> "$GITHUB_OUTPUT"
fi
- name: Select public source
if: steps.restored.outputs.cached != 'true'
uses: actions/checkout@v6
with:
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.gp_branch || github.sha }}
path: selected/gp
- name: Select private source
if: steps.restored.outputs.cached != 'true'
uses: ./.github/actions/checkout-private
with:
token: ${{ secrets.GH_PAT }}
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.gpgui_branch || github.ref_name }}
path: selected/gpgui
- name: Record selected sources
id: sources
run: |
python3 scripts/record-build-sources.py selected-sources/sources.json \
--gp selected/gp --gpgui selected/gpgui
- name: Retain selected sources for retries
if: steps.restored.outputs.cached != 'true'
uses: actions/upload-artifact@v7
with:
name: build-source-refs
path: selected-sources/sources.json
retention-days: 30
test-gp: test-gp:
needs: validate-inputs needs: validate-inputs
runs-on: ubuntu-latest runs-on: ubuntu-latest
@@ -78,7 +131,7 @@ jobs:
with: with:
token: ${{ secrets.GH_PAT }} token: ${{ secrets.GH_PAT }}
repository: yuezk/GlobalProtect-openconnect repository: yuezk/GlobalProtect-openconnect
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.gp_branch || github.ref }} ref: ${{ needs.validate-inputs.outputs.gp_sha }}
submodules: recursive submodules: recursive
- name: Run Rust tests as a non-root user with focused privilege checks - name: Run Rust tests as a non-root user with focused privilege checks
run: | run: |
@@ -118,7 +171,7 @@ jobs:
uses: actions/checkout@v6 uses: actions/checkout@v6
with: with:
repository: yuezk/GlobalProtect-openconnect repository: yuezk/GlobalProtect-openconnect
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.gp_branch || github.ref }} ref: ${{ needs.validate-inputs.outputs.gp_sha }}
submodules: recursive submodules: recursive
path: source/gp path: source/gp
persist-credentials: false persist-credentials: false
@@ -131,7 +184,7 @@ jobs:
uses: ./.ci/.github/actions/checkout-private uses: ./.ci/.github/actions/checkout-private
with: with:
token: ${{ secrets.GH_PAT }} token: ${{ secrets.GH_PAT }}
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.gpgui_branch || github.ref_name }} ref: ${{ needs.validate-inputs.outputs.gpgui_sha }}
path: source/gpgui path: source/gpgui
- name: Run frontend and Rust unit tests as an ordinary user - name: Run frontend and Rust unit tests as an ordinary user
timeout-minutes: 80 timeout-minutes: 80
@@ -152,7 +205,7 @@ jobs:
with: with:
token: ${{ secrets.GH_PAT }} token: ${{ secrets.GH_PAT }}
repository: yuezk/GlobalProtect-openconnect repository: yuezk/GlobalProtect-openconnect
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.gp_branch || github.ref }} ref: ${{ needs.validate-inputs.outputs.gp_sha }}
path: source/gp path: source/gp
submodules: recursive submodules: recursive
@@ -282,6 +335,7 @@ jobs:
build-gp-${{ matrix.package }}/artifacts/* build-gp-${{ matrix.package }}/artifacts/*
build-docker-image: build-docker-image:
needs: validate-inputs
if: ${{ !(startsWith(github.ref, 'refs/tags/') || (github.event_name == 'workflow_dispatch' && inputs.channel == 'stable')) }} if: ${{ !(startsWith(github.ref, 'refs/tags/') || (github.event_name == 'workflow_dispatch' && inputs.channel == 'stable')) }}
strategy: strategy:
fail-fast: false fail-fast: false
@@ -302,7 +356,7 @@ jobs:
with: with:
token: ${{ secrets.GH_PAT }} token: ${{ secrets.GH_PAT }}
repository: yuezk/GlobalProtect-openconnect repository: yuezk/GlobalProtect-openconnect
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.gp_branch || github.ref }} ref: ${{ needs.validate-inputs.outputs.gp_sha }}
submodules: recursive submodules: recursive
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4 uses: docker/setup-buildx-action@v4
@@ -364,8 +418,8 @@ jobs:
name: build-gpgui (glibc) name: build-gpgui (glibc)
uses: ./.github/workflows/build-gpgui-linux.yaml uses: ./.github/workflows/build-gpgui-linux.yaml
with: with:
gp_ref: ${{ github.event_name == 'workflow_dispatch' && inputs.gp_branch || github.ref }} gp_ref: ${{ needs.validate-inputs.outputs.gp_sha }}
gpgui_ref: ${{ github.event_name == 'workflow_dispatch' && inputs.gpgui_branch || github.ref_name }} gpgui_ref: ${{ needs.validate-inputs.outputs.gpgui_sha }}
channel: ${{ github.event_name == 'workflow_dispatch' && inputs.channel || 'stable' }} channel: ${{ github.event_name == 'workflow_dispatch' && inputs.channel || 'stable' }}
builder: gpgui-builder-tauri2 builder: gpgui-builder-tauri2
verify_desktop_assets: true verify_desktop_assets: true
@@ -377,8 +431,8 @@ jobs:
name: build-gpgui (musl) name: build-gpgui (musl)
uses: ./.github/workflows/build-gpgui-linux.yaml uses: ./.github/workflows/build-gpgui-linux.yaml
with: with:
gp_ref: ${{ github.event_name == 'workflow_dispatch' && inputs.gp_branch || github.ref }} gp_ref: ${{ needs.validate-inputs.outputs.gp_sha }}
gpgui_ref: ${{ github.event_name == 'workflow_dispatch' && inputs.gpgui_branch || github.ref_name }} gpgui_ref: ${{ needs.validate-inputs.outputs.gpgui_sha }}
channel: ${{ github.event_name == 'workflow_dispatch' && inputs.channel || 'stable' }} channel: ${{ github.event_name == 'workflow_dispatch' && inputs.channel || 'stable' }}
builder: gpgui-alpine-builder-tauri2 builder: gpgui-alpine-builder-tauri2
artifact_suffix: -musl artifact_suffix: -musl
@@ -386,7 +440,7 @@ jobs:
GH_PAT: ${{ secrets.GH_PAT }} GH_PAT: ${{ secrets.GH_PAT }}
nix-source: nix-source:
needs: [build-gpgui-glibc] needs: [validate-inputs, build-gpgui-glibc]
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
@@ -407,7 +461,7 @@ jobs:
uses: actions/checkout@v6 uses: actions/checkout@v6
with: with:
token: ${{ secrets.GH_PAT }} token: ${{ secrets.GH_PAT }}
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.gp_branch || github.ref }} ref: ${{ needs.validate-inputs.outputs.gp_sha }}
submodules: recursive submodules: recursive
path: gp path: gp
- name: Download current GUI artifact - name: Download current GUI artifact
@@ -435,7 +489,7 @@ jobs:
--extra-experimental-features "nix-command flakes" --print-build-logs --extra-experimental-features "nix-command flakes" --print-build-logs
nix-prebuilt: nix-prebuilt:
needs: [build-gp, build-gpgui-glibc] needs: [validate-inputs, build-gp, build-gpgui-glibc]
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
@@ -457,7 +511,7 @@ jobs:
uses: actions/checkout@v6 uses: actions/checkout@v6
with: with:
token: ${{ secrets.GH_PAT }} token: ${{ secrets.GH_PAT }}
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.gp_branch || github.ref }} ref: ${{ needs.validate-inputs.outputs.gp_sha }}
submodules: recursive submodules: recursive
path: gp path: gp
- name: Download current Linux binary artifact - name: Download current Linux binary artifact
@@ -499,7 +553,7 @@ jobs:
build-macos: build-macos:
name: build-macos name: build-macos
needs: [test-gp, test-gpgui] needs: [validate-inputs, test-gp, test-gpgui]
if: ${{ (github.event_name == 'workflow_dispatch' && inputs.build_macos) || (startsWith(github.ref, 'refs/tags/') && vars.BUILD_MACOS_ON_TAG == 'true') }} if: ${{ (github.event_name == 'workflow_dispatch' && inputs.build_macos) || (startsWith(github.ref, 'refs/tags/') && vars.BUILD_MACOS_ON_TAG == 'true') }}
permissions: permissions:
contents: read contents: read
@@ -535,14 +589,14 @@ jobs:
uses: ./.ci/.github/actions/checkout-private uses: ./.ci/.github/actions/checkout-private
with: with:
token: ${{ secrets.GH_PAT }} token: ${{ secrets.GH_PAT }}
ref: ${{ (github.event_name == 'workflow_dispatch' && inputs.gpgui_branch || github.ref_name) }} ref: ${{ needs.validate-inputs.outputs.gpgui_sha }}
path: source/gpgui path: source/gpgui
- name: Checkout GlobalProtect-openconnect source - name: Checkout GlobalProtect-openconnect source
uses: actions/checkout@v6 uses: actions/checkout@v6
with: with:
repository: yuezk/GlobalProtect-openconnect repository: yuezk/GlobalProtect-openconnect
ref: ${{ (github.event_name == 'workflow_dispatch' && inputs.gp_branch || github.ref) }} ref: ${{ needs.validate-inputs.outputs.gp_sha }}
path: source/gp path: source/gp
submodules: recursive submodules: recursive
@@ -815,7 +869,7 @@ jobs:
PY PY
build-gpgui-frontend: build-gpgui-frontend:
needs: setup-bsd-matrix needs: [validate-inputs, setup-bsd-matrix]
if: ${{ needs.setup-bsd-matrix.outputs.enabled == 'true' }} if: ${{ needs.setup-bsd-matrix.outputs.enabled == 'true' }}
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
@@ -829,7 +883,7 @@ jobs:
with: with:
token: ${{ secrets.GH_PAT }} token: ${{ secrets.GH_PAT }}
repository: yuezk/GlobalProtect-openconnect repository: yuezk/GlobalProtect-openconnect
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.gp_branch || github.ref }} ref: ${{ needs.validate-inputs.outputs.gp_sha }}
path: gpgui-frontend/gp path: gpgui-frontend/gp
submodules: recursive submodules: recursive
- name: Checkout CI helpers - name: Checkout CI helpers
@@ -841,7 +895,7 @@ jobs:
uses: ./.ci/.github/actions/checkout-private uses: ./.ci/.github/actions/checkout-private
with: with:
token: ${{ secrets.GH_PAT }} token: ${{ secrets.GH_PAT }}
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.gpgui_branch || github.ref_name }} ref: ${{ needs.validate-inputs.outputs.gpgui_sha }}
path: gpgui-frontend/gpgui path: gpgui-frontend/gpgui
- name: Build gpgui frontend - name: Build gpgui frontend
run: | run: |
@@ -863,6 +917,7 @@ jobs:
build-bsd: build-bsd:
needs: needs:
- validate-inputs
- setup-bsd-matrix - setup-bsd-matrix
- build-gpgui-frontend - build-gpgui-frontend
if: ${{ needs.setup-bsd-matrix.outputs.enabled == 'true' }} if: ${{ needs.setup-bsd-matrix.outputs.enabled == 'true' }}
@@ -879,7 +934,7 @@ jobs:
with: with:
token: ${{ secrets.GH_PAT }} token: ${{ secrets.GH_PAT }}
repository: yuezk/GlobalProtect-openconnect repository: yuezk/GlobalProtect-openconnect
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.gp_branch || github.ref }} ref: ${{ needs.validate-inputs.outputs.gp_sha }}
path: ${{ matrix.workspace }}/gp path: ${{ matrix.workspace }}/gp
submodules: recursive submodules: recursive
- name: Checkout CI helpers - name: Checkout CI helpers
@@ -891,7 +946,7 @@ jobs:
uses: ./.ci/.github/actions/checkout-private uses: ./.ci/.github/actions/checkout-private
with: with:
token: ${{ secrets.GH_PAT }} token: ${{ secrets.GH_PAT }}
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.gpgui_branch || github.ref_name }} ref: ${{ needs.validate-inputs.outputs.gpgui_sha }}
path: ${{ matrix.workspace }}/gpgui path: ${{ matrix.workspace }}/gpgui
- name: Download gpgui frontend - name: Download gpgui frontend
uses: actions/download-artifact@v8 uses: actions/download-artifact@v8
@@ -1029,6 +1084,7 @@ jobs:
attestations: write attestations: write
artifact-metadata: write artifact-metadata: write
needs: needs:
- validate-inputs
- test-gp - test-gp
- test-gpgui - test-gpgui
- nix-source - nix-source
@@ -1086,7 +1142,7 @@ jobs:
with: with:
token: ${{ secrets.GH_PAT }} token: ${{ secrets.GH_PAT }}
repository: yuezk/GlobalProtect-openconnect repository: yuezk/GlobalProtect-openconnect
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.gp_branch || github.ref }} ref: ${{ needs.validate-inputs.outputs.gp_sha }}
path: gh-release/gp path: gh-release/gp
submodules: recursive submodules: recursive
@@ -1136,6 +1192,7 @@ jobs:
publish-docker-image: publish-docker-image:
needs: needs:
- validate-inputs
- test-gp - test-gp
- test-gpgui - test-gpgui
- build-docker-image - build-docker-image
+10
View File
@@ -3,6 +3,8 @@ name: Nix
on: on:
pull_request: pull_request:
paths: paths:
- "Cargo.toml"
- "scripts/validate-release-version.py"
- "flake.nix" - "flake.nix"
- "flake.lock" - "flake.lock"
- "nix/**" - "nix/**"
@@ -11,6 +13,8 @@ on:
branches: branches:
- main - main
paths: paths:
- "Cargo.toml"
- "scripts/validate-release-version.py"
- "flake.nix" - "flake.nix"
- "flake.lock" - "flake.lock"
- "nix/**" - "nix/**"
@@ -44,6 +48,9 @@ jobs:
--extra-experimental-features "nix-command flakes" \ --extra-experimental-features "nix-command flakes" \
--print-build-logs --print-build-logs
- name: Check installed release versions
run: python3 scripts/validate-release-version.py --package result
- name: Inspect prebuilt package - name: Inspect prebuilt package
run: | run: |
test -x result/bin/gpclient test -x result/bin/gpclient
@@ -109,6 +116,9 @@ jobs:
package package
' '
- name: Check installed release versions
run: python3 scripts/validate-release-version.py --package result
- name: Inspect module package - name: Inspect module package
run: | run: |
test -x result/bin/gpclient test -x result/bin/gpclient
+2 -1
View File
@@ -472,7 +472,7 @@ jobs:
archive_url="https://github.com/$REPOSITORY/releases/download/$RELEASE_TAG/${{ steps.archive.outputs.name }}" archive_url="https://github.com/$REPOSITORY/releases/download/$RELEASE_TAG/${{ steps.archive.outputs.name }}"
if [[ "$CHANNEL" == "stable" ]] && \ if [[ "$CHANNEL" == "stable" ]] && \
gh release view "$RELEASE_TAG" --repo "$REPOSITORY" --json assets \ gh release view "$RELEASE_TAG" --repo "$REPOSITORY" --json assets \
--jq '.assets[].name' | grep -Fxq appcast.xml; then --jq '.assets[].name' | grep -Fx appcast.xml >/dev/null; then
existing="$RUNNER_TEMP/existing-release-appcast.xml" existing="$RUNNER_TEMP/existing-release-appcast.xml"
gh release download "$RELEASE_TAG" --repo "$REPOSITORY" \ gh release download "$RELEASE_TAG" --repo "$REPOSITORY" \
--pattern appcast.xml --output "$existing" --pattern appcast.xml --output "$existing"
@@ -482,6 +482,7 @@ jobs:
--short-version "${{ steps.bundle.outputs.short_version }}" \ --short-version "${{ steps.bundle.outputs.short_version }}" \
--channel "$CHANNEL" \ --channel "$CHANNEL" \
--archive-url "$archive_url" --archive-url "$archive_url"
cp "$existing" "$appcast"
else else
if [[ "$CHANNEL" == "snapshot" ]]; then if [[ "$CHANNEL" == "snapshot" ]]; then
RELEASE_REPOSITORY="$REPOSITORY" \ RELEASE_REPOSITORY="$REPOSITORY" \
+15
View File
@@ -5,6 +5,11 @@ on:
paths: paths:
- '.github/workflows/**' - '.github/workflows/**'
- '.github/actions/**' - '.github/actions/**'
- 'scripts/record-build-sources.py'
- 'scripts/validate-release-version.py'
- 'scripts/publish-flake-test-branch.sh'
- 'scripts/prepare-release-promotion.sh'
- 'scripts/tests/test_release_flow.py'
- 'scripts/select-macos-artifact.sh' - 'scripts/select-macos-artifact.sh'
- 'scripts/test-private-desktop.sh' - 'scripts/test-private-desktop.sh'
- 'scripts/tests/test_private_ci.py' - 'scripts/tests/test_private_ci.py'
@@ -21,6 +26,11 @@ on:
paths: paths:
- '.github/workflows/**' - '.github/workflows/**'
- '.github/actions/**' - '.github/actions/**'
- 'scripts/record-build-sources.py'
- 'scripts/validate-release-version.py'
- 'scripts/publish-flake-test-branch.sh'
- 'scripts/prepare-release-promotion.sh'
- 'scripts/tests/test_release_flow.py'
- 'scripts/select-macos-artifact.sh' - 'scripts/select-macos-artifact.sh'
- 'scripts/test-private-desktop.sh' - 'scripts/test-private-desktop.sh'
- 'scripts/tests/test_private_ci.py' - 'scripts/tests/test_private_ci.py'
@@ -60,3 +70,8 @@ jobs:
shellcheck scripts/select-macos-artifact.sh scripts/test-private-desktop.sh shellcheck scripts/select-macos-artifact.sh scripts/test-private-desktop.sh
bash -n scripts/test-private-desktop.sh bash -n scripts/test-private-desktop.sh
python3 -m unittest discover -s scripts/tests -p 'test_private_ci.py' python3 -m unittest discover -s scripts/tests -p 'test_private_ci.py'
- name: Test release promotion and source selection
run: |
bash -n scripts/prepare-release-promotion.sh scripts/publish-flake-test-branch.sh
shellcheck scripts/prepare-release-promotion.sh scripts/publish-flake-test-branch.sh
python3 -m unittest discover -s scripts/tests -p 'test_release_flow.py'
+23
View File
@@ -0,0 +1,23 @@
name: Release version consistency
on:
pull_request:
branches: [main]
push:
branches: [main]
permissions:
contents: read
jobs:
release-version:
runs-on: ubuntu-latest
steps:
# The default PR checkout is the candidate merged with the current base.
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Check main release version
env:
BASE_REF: ${{ github.event.pull_request.base.sha || github.event.before }}
run: python3 scripts/validate-release-version.py --base-ref "$BASE_REF"
+20 -7
View File
@@ -73,6 +73,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
outputs: outputs:
matrix: ${{ steps.set-matrix.outputs.result }} matrix: ${{ steps.set-matrix.outputs.result }}
docker_matrix: ${{ steps.set-matrix.outputs.docker_matrix }}
steps: steps:
- name: Set up matrix - name: Set up matrix
id: set-matrix id: set-matrix
@@ -88,6 +89,12 @@ jobs:
"arm64": ["ubuntu-24.04-arm"] "arm64": ["ubuntu-24.04-arm"]
} }
const docker = [
{ runner: 'ubuntu-latest', platform: 'linux/amd64' },
{ runner: 'ubuntu-24.04-arm', platform: 'linux/arm64' },
].filter(item => osMap[arch].includes(item.runner))
core.setOutput('docker_matrix', JSON.stringify({ include: docker }))
const package = Object.entries(inputs) const package = Object.entries(inputs)
.filter(([key, value]) => key.startsWith('release-') && key !== 'release-docker' && value) .filter(([key, value]) => key.startsWith('release-') && key !== 'release-docker' && value)
.map(([key, value]) => key.replace('release-', '')) .map(([key, value]) => key.replace('release-', ''))
@@ -145,15 +152,11 @@ jobs:
build-docker-image: build-docker-image:
needs: needs:
- check - check
- setup-matrix
if: ${{ inputs.release-docker }} if: ${{ inputs.release-docker }}
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix: ${{ fromJson(needs.setup-matrix.outputs.docker_matrix) }}
include:
- runner: ubuntu-latest
platform: linux/amd64
- runner: ubuntu-24.04-arm
platform: linux/arm64
runs-on: ${{ matrix.runner }} runs-on: ${{ matrix.runner }}
steps: steps:
- name: Prepare - name: Prepare
@@ -235,6 +238,17 @@ jobs:
IMAGE: yuezk/globalprotect-openconnect IMAGE: yuezk/globalprotect-openconnect
TAG: ${{ inputs.tag }} TAG: ${{ inputs.tag }}
run: | run: |
# Reject an incomplete or unexpected selection before writing any tag.
shopt -s nullglob
digest_files=(*)
expected_count=1
if [[ "${{ inputs.arch }}" == all ]]; then
expected_count=2
fi
[[ ${#digest_files[@]} -eq $expected_count ]]
for digest in "${digest_files[@]}"; do
[[ "$digest" =~ ^[0-9a-f]{64}$ ]]
done
VERSION="${TAG#v}" VERSION="${TAG#v}"
tags=(-t "$IMAGE:$TAG") tags=(-t "$IMAGE:$TAG")
@@ -335,7 +349,6 @@ jobs:
if: ${{ inputs.release-binary && inputs.arch == 'all' && needs.gh-release.outputs.stable_version != '' }} if: ${{ inputs.release-binary && inputs.arch == 'all' && needs.gh-release.outputs.stable_version != '' }}
permissions: permissions:
contents: write contents: write
pull-requests: write
uses: ./.github/workflows/update-flake-hashes.yaml uses: ./.github/workflows/update-flake-hashes.yaml
with: with:
version: ${{ needs.gh-release.outputs.stable_version }} version: ${{ needs.gh-release.outputs.stable_version }}
+52 -10
View File
@@ -20,14 +20,47 @@ on:
permissions: permissions:
contents: write contents: write
pull-requests: write
jobs: jobs:
update-flake-hashes: update-flake-hashes:
runs-on: ubuntu-latest runs-on: ubuntu-latest
outputs:
version: ${{ steps.release.outputs.version }}
release_tag: ${{ steps.release.outputs.release_tag }}
steps: steps:
- name: Checkout GlobalProtect-openconnect - name: Checkout GlobalProtect-openconnect
uses: actions/checkout@v6 uses: actions/checkout@v6
with:
ref: ${{ github.sha }}
- name: Resolve candidate release
id: release
env:
RELEASE_VERSION: ${{ inputs.version }}
RELEASE_TAG: ${{ inputs.release_tag }}
run: |
python3 - <<'PYRELEASE'
import json, os, re, runpy, subprocess
from pathlib import Path
helpers = runpy.run_path('scripts/validate-release-version.py')
version = os.environ['RELEASE_VERSION'].removeprefix('v') or helpers['cargo_version'](Path('.'))
tag = os.environ['RELEASE_TAG'] or f'v{version}'
if not re.fullmatch(r'(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)', version) or tag not in (f'v{version}', 'snapshot'):
raise SystemExit('Expected a stable version and its matching release tag, or snapshot')
source_slug = re.sub(r'[^A-Za-z0-9._-]', '', re.sub(r'[/\s]+', '-', os.environ['GITHUB_REF_NAME'])).strip('-')
test_branch = f'chore/flake-{source_slug}'
expected_head = ''
if tag == 'snapshot':
remote = subprocess.check_output(['git', 'ls-remote', '--heads', 'origin', f'refs/heads/{test_branch}'], text=True)
expected_head = remote.split()[0] if remote.strip() else ''
with open(os.environ['GITHUB_OUTPUT'], 'a') as output:
output.write(f'version={version}\nrelease_tag={tag}\n')
Path('release-candidate.json').write_text(json.dumps({
'version': version, 'releaseTag': tag, 'sourceSha': os.environ['GITHUB_SHA'],
'workflowRunId': os.environ['GITHUB_RUN_ID'],
'testBranch': test_branch, 'expectedTestHead': expected_head,
}, indent=2) + '\n')
PYRELEASE
- name: Install Nix - name: Install Nix
uses: cachix/install-nix-action@v31 uses: cachix/install-nix-action@v31
@@ -39,8 +72,8 @@ jobs:
- name: Update flake hashes - name: Update flake hashes
env: env:
RELEASE_VERSION: ${{ inputs.version }} RELEASE_VERSION: ${{ steps.release.outputs.version }}
RELEASE_TAG: ${{ inputs.release_tag }} RELEASE_TAG: ${{ steps.release.outputs.release_tag }}
run: | run: |
if [[ -n "$RELEASE_VERSION" ]]; then if [[ -n "$RELEASE_VERSION" ]]; then
scripts/update-flake-hashes.sh "$RELEASE_VERSION" "$RELEASE_TAG" scripts/update-flake-hashes.sh "$RELEASE_VERSION" "$RELEASE_TAG"
@@ -55,6 +88,7 @@ jobs:
path: | path: |
flake.nix flake.nix
flake.lock flake.lock
release-candidate.json
if-no-files-found: error if-no-files-found: error
validate-nix-prebuilt: validate-nix-prebuilt:
@@ -79,6 +113,8 @@ jobs:
steps: steps:
- name: Checkout GlobalProtect-openconnect - name: Checkout GlobalProtect-openconnect
uses: actions/checkout@v6 uses: actions/checkout@v6
with:
ref: ${{ github.sha }}
- name: Download updated flake - name: Download updated flake
uses: actions/download-artifact@v8 uses: actions/download-artifact@v8
@@ -104,6 +140,12 @@ jobs:
--print-build-logs --print-build-logs
fi fi
- name: Validate installed release versions
run: |
python3 scripts/validate-release-version.py \
--version '${{ needs.update-flake-hashes.outputs.version }}' \
--release-tag '${{ needs.update-flake-hashes.outputs.release_tag }}' --package result
- name: Inspect prebuilt Nix package - name: Inspect prebuilt Nix package
run: | run: |
test -x result/bin/gpclient test -x result/bin/gpclient
@@ -126,13 +168,15 @@ jobs:
- name: Verify desktop authorization runs on the host - name: Verify desktop authorization runs on the host
run: bash scripts/tests/nix-desktop-authorization.sh result run: bash scripts/tests/nix-desktop-authorization.sh result
open-pull-request: publish-test-branch:
needs: if: needs.update-flake-hashes.outputs.release_tag == 'snapshot'
- validate-nix-prebuilt needs: [update-flake-hashes, validate-nix-prebuilt]
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout GlobalProtect-openconnect - name: Checkout GlobalProtect-openconnect
uses: actions/checkout@v6 uses: actions/checkout@v6
with:
ref: ${{ github.sha }}
- name: Download updated flake - name: Download updated flake
uses: actions/download-artifact@v8 uses: actions/download-artifact@v8
@@ -140,9 +184,7 @@ jobs:
name: updated-flake name: updated-flake
path: . path: .
- name: Open pull request - name: Publish branch for snapshot testing
env: env:
GH_TOKEN: ${{ github.token }} GH_TOKEN: ${{ github.token }}
RELEASE_VERSION: ${{ inputs.version }} run: scripts/publish-flake-test-branch.sh
RELEASE_TAG: ${{ inputs.release_tag }}
run: scripts/open-flake-hashes-pr.sh "$RELEASE_VERSION" "$RELEASE_TAG"
+37 -9
View File
@@ -2,6 +2,7 @@
//! No process is forked after authentication or OpenConnect has started its threads. //! No process is forked after authentication or OpenConnect has started its threads.
use std::{ use std::{
cell::RefCell,
ffi::OsString, ffi::OsString,
fs::{File, OpenOptions}, fs::{File, OpenOptions},
io::{self, Write}, io::{self, Write},
@@ -27,7 +28,8 @@ use tokio::{io::AsyncReadExt, process::Command};
const READY: u8 = 1; const READY: u8 = 1;
pub(crate) struct BackgroundWorker { pub(crate) struct BackgroundWorker {
ready: UnixStream, // Consumed after detachment; later tunnels stay in the same background session.
ready: RefCell<Option<UnixStream>>,
log: File, log: File,
input: File, input: File,
} }
@@ -82,10 +84,17 @@ impl BackgroundWorker {
"Background log must not be readable or writable by other users" "Background log must not be readable or writable by other users"
); );
let input = File::open("/dev/null")?; let input = File::open("/dev/null")?;
Ok(Self { ready, log, input }) Ok(Self {
ready: RefCell::new(Some(ready)),
log,
input,
})
} }
pub(crate) fn redirect_stdio(&self) -> anyhow::Result<BackgroundStdio> { pub(crate) fn redirect_stdio(&self) -> anyhow::Result<BackgroundStdio> {
if self.ready.borrow().is_none() {
return Ok(BackgroundStdio { saved: None });
}
io::stdout().flush()?; io::stdout().flush()?;
io::stderr().flush()?; io::stderr().flush()?;
let save = |fd| -> anyhow::Result<OwnedFd> { let save = |fd| -> anyhow::Result<OwnedFd> {
@@ -107,13 +116,18 @@ impl BackgroundWorker {
} }
pub(crate) fn detach(&self, stdio: &mut BackgroundStdio) -> anyhow::Result<()> { pub(crate) fn detach(&self, stdio: &mut BackgroundStdio) -> anyhow::Result<()> {
let mut ready = self.ready.borrow_mut();
let Some(socket) = ready.as_mut() else {
return Ok(());
};
// The worker inherited the launcher's foreground group, so it can prompt normally. // The worker inherited the launcher's foreground group, so it can prompt normally.
// It becomes a session leader only when sign-in and tunnel configuration are done. // It becomes a session leader only when sign-in and tunnel configuration are done.
setsid().context("Cannot detach the VPN session from the terminal")?; setsid().context("Cannot detach the VPN session from the terminal")?;
(&self.ready) socket
.write_all(&[READY]) .write_all(&[READY])
.context("Background launcher exited before tunnel setup")?; .context("Background launcher exited before tunnel setup")?;
stdio.saved.take(); stdio.saved.take();
ready.take();
Ok(()) Ok(())
} }
} }
@@ -205,12 +219,13 @@ mod tests {
} }
#[tokio::test] #[tokio::test]
async fn detached_worker_survives_launcher_and_disconnects_by_pid() { async fn detached_worker_reconnects_after_launcher_exits() {
let directory = tempfile::tempdir().unwrap(); let directory = tempfile::tempdir().unwrap();
tokio::time::timeout(Duration::from_secs(5), launch(fixture(directory.path()), &[])) tokio::time::timeout(Duration::from_secs(5), launch(fixture(directory.path()), &[]))
.await .await
.unwrap() .unwrap()
.unwrap(); .unwrap();
std::fs::write(directory.path().join("reconnect"), "").unwrap();
let pid = std::fs::read_to_string(directory.path().join("pid")) let pid = std::fs::read_to_string(directory.path().join("pid"))
.unwrap() .unwrap()
.parse::<i32>() .parse::<i32>()
@@ -222,18 +237,19 @@ mod tests {
"Worker must own a terminal-independent session" "Worker must own a terminal-independent session"
); );
kill(pid, None).unwrap(); kill(pid, None).unwrap();
tokio::time::timeout(Duration::from_secs(5), async { let reconnected = tokio::time::timeout(Duration::from_secs(5), async {
while !std::fs::read_to_string(directory.path().join("worker.log")) while !std::fs::read_to_string(directory.path().join("worker.log"))
.unwrap() .unwrap()
.contains("helper-output") .contains("reconnected-output")
{ {
tokio::time::sleep(Duration::from_millis(10)).await; tokio::time::sleep(Duration::from_millis(10)).await;
} }
}) })
.await .await;
.unwrap();
let log = std::fs::read_to_string(directory.path().join("worker.log")).unwrap(); let log = std::fs::read_to_string(directory.path().join("worker.log")).unwrap();
assert!(reconnected.is_ok(), "Worker did not reconnect:\n{log}");
assert!(log.contains("failed-attempt-output")); assert!(log.contains("failed-attempt-output"));
assert!(log.contains("helper-output"));
assert!(!log.contains("restored-foreground-output")); assert!(!log.contains("restored-foreground-output"));
#[derive(clap::Parser)] #[derive(clap::Parser)]
struct Disconnect { struct Disconnect {
@@ -295,8 +311,20 @@ mod tests {
worker.detach(&mut stdio).unwrap(); worker.detach(&mut stdio).unwrap();
println!("detached-output"); println!("detached-output");
io::stdout().flush().unwrap(); io::stdout().flush().unwrap();
interrupt.recv().await; tokio::time::timeout(Duration::from_secs(5), async {
while !directory.join("reconnect").exists() {
tokio::time::sleep(Duration::from_millis(10)).await;
}
})
.await
.unwrap();
helper.wait().unwrap(); helper.wait().unwrap();
let mut stdio = worker.redirect_stdio().unwrap();
worker.detach(&mut stdio).unwrap();
assert_eq!(getsid(None).unwrap(), getpid());
println!("reconnected-output");
io::stdout().flush().unwrap();
interrupt.recv().await;
std::fs::write(directory.join("stopped"), "stopped").unwrap(); std::fs::write(directory.join("stopped"), "stopped").unwrap();
} }
} }
+1
View File
@@ -18,6 +18,7 @@
- Fixed VPN shutdown waiting too long when a gateway stops responding to logout. - Fixed VPN shutdown waiting too long when a gateway stops responding to logout.
- Fixed segmented controls sometimes losing the selected option when clicked. - Fixed segmented controls sometimes losing the selected option when clicked.
- Fixed app shortcuts failing to open with some Linux and BSD desktop launchers. - Fixed app shortcuts failing to open with some Linux and BSD desktop launchers.
- Fixed invisible desktop icons on systems using older versions of librsvg.
## 3.1.0 ## 3.1.0
Generated
+3 -3
View File
@@ -63,11 +63,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1792116957, "lastModified": 1793494649,
"narHash": "sha256-EjZqHKObBfIOeHZnMRVV87HB3pPq/WBkmRJWyFxmZu8=", "narHash": "sha256-Thn0OE71NF80ZfOMGCgJvKtbCcnnz0fToT/qsvb/Gtc=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "f20cd90e28fe0403873f473b29e42662cd86e8c4", "rev": "d357a2b54f0b6dc4aeb4e993190a52cf151b6f24",
"type": "github" "type": "github"
}, },
"original": { "original": {
+6 -6
View File
@@ -29,8 +29,8 @@
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml); cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
pname = "globalprotect-openconnect"; pname = "globalprotect-openconnect";
version = cargoToml.workspace.package.version; version = cargoToml.workspace.package.version;
releaseTag = "v3.1.0"; releaseTag = "snapshot";
releaseVersion = "3.1.0"; releaseVersion = "3.2.0";
toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
@@ -55,8 +55,8 @@
cpu = pkgs.stdenv.hostPlatform.parsed.cpu.name; cpu = pkgs.stdenv.hostPlatform.parsed.cpu.name;
gpguiHashes = { gpguiHashes = {
x86_64 = "sha256-wk3fCh8IQR9ffp63fL0PWvYO/KTJYktWCY+fr1v9d4Q="; x86_64 = "sha256-W0ijBnwPmbkyLQgVwB1cwfgbKDe+o8KD+gm/zw+KXK4=";
aarch64 = "sha256-N50XA3eBbdUblZz/FdCbGpHrURkmPTgc9SZPn7XD5g8="; aarch64 = "sha256-uuAFFYMVbxbNzCtI9SBXu/v24iNNqHFoNaYP5PlJRVE=";
}; };
gpguiArchive = pkgs.fetchurl { gpguiArchive = pkgs.fetchurl {
@@ -70,8 +70,8 @@
}; };
binaryHashes = { binaryHashes = {
x86_64 = "sha256-FfyzQyGrWr5og0Ud++lUpzn3M8AmXAvGfV7bhbDYfk0="; x86_64 = "sha256-uc6D7tbU5/xS5KBUd1L4ssygVo8b372c/eX5w6lxsOE=";
aarch64 = "sha256-LCcm0JFF7lsc/txzALorFBSjHad7R4ZBK+mYMnJ7pm8="; aarch64 = "sha256-/4IbFqtt6hVATSKHxmMyxRDfFaBfYtZMYIo+bXE6KFo=";
}; };
binaryArchive = pkgs.fetchurl { binaryArchive = pkgs.fetchurl {
-59
View File
@@ -1,59 +0,0 @@
#!/usr/bin/env bash
set -euo pipefail
release_version="${1:-}"
release_tag="${2:-}"
if git diff --quiet -- flake.nix flake.lock; then
echo "flake hashes and lock are already up to date"
exit 0
fi
if [[ -z "$release_version" ]]; then
release_version="$(grep '^version' Cargo.toml | head -1 | sed 's/version *= *"\(.*\)"/\1/')"
fi
version="${release_version#v}"
if [[ -z "$release_tag" ]]; then
release_tag="v$version"
fi
branch_suffix="v${version}"
title="chore: update flake hashes for v${version}"
body="Updates the Nix flake fetchurl hashes for v${version} release assets and refreshes the Nixpkgs lock."
if [[ "$release_tag" != "v$version" ]]; then
branch_suffix="${branch_suffix}-${release_tag}"
title="chore: update flake hashes for v${version} from ${release_tag}"
body="Updates the Nix flake fetchurl hashes for v${version} using ${release_tag} release assets and refreshes the Nixpkgs lock."
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
if [[ "$release_tag" == "snapshot" ]]; then
source_branch="${GITHUB_REF_NAME:-$(git branch --show-current)}"
source_branch_slug="$(printf '%s' "$source_branch" | sed -E 's#[/[:space:]]+#-#g; s#[^A-Za-z0-9._-]##g; s#^-+##; s#-+$##')"
branch="chore/flake-${source_branch_slug}"
git switch -C "$branch"
git add flake.nix flake.lock
git commit -m "$title"
git push --force origin "$branch"
echo "Updated snapshot flake hashes on branch $branch from $source_branch; skipping PR creation"
exit 0
fi
branch="chore/update-flake-hashes-${branch_suffix}"
git switch -C "$branch"
git add flake.nix flake.lock
git commit -m "$title"
git push --force origin "$branch"
pr_number="$(gh pr list --head "$branch" --state open --json number --jq '.[0].number')"
if [[ -n "$pr_number" ]]; then
gh pr edit "$pr_number" --title "$title" --body "$body"
else
gh pr create --title "$title" --body "$body" --base main --head "$branch"
fi
+48
View File
@@ -0,0 +1,48 @@
#!/usr/bin/env bash
# Prepare a reviewable main candidate; publishing and merging remain explicit.
set -euo pipefail
tag="${1:?Usage: prepare-release-promotion.sh <vX.Y.Z> <updated-flake-directory>}"
artifact_dir="$(cd "${2:?Updated flake artifact directory is required}" && pwd)"
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if [[ ! "$tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "A stable release tag is required" >&2
exit 1
fi
if [[ -n "$(git status --porcelain)" ]]; then
echo "Start with a clean working tree" >&2
exit 1
fi
python3 - "$artifact_dir/release-candidate.json" "$tag" <<'PY'
import json, sys
from pathlib import Path
candidate = json.loads(Path(sys.argv[1]).read_text())
if candidate['releaseTag'] != sys.argv[2] or candidate['version'] != sys.argv[2][1:]:
raise SystemExit('Flake artifact does not belong to the requested release')
PY
python3 "$script_dir/validate-release-version.py" --root "$artifact_dir" --version "${tag#v}"
git fetch origin refs/heads/main:refs/remotes/origin/main
git fetch origin "refs/tags/$tag"
release_sha="$(git rev-parse 'FETCH_HEAD^{commit}')"
python3 - "$tag" <<'PY'
import re, subprocess, sys
cargo = subprocess.check_output(['git', 'show', 'origin/main:Cargo.toml'], text=True)
version = re.search(r'^version\s*=\s*"([0-9.]+)"', cargo, re.M)[1]
if tuple(map(int, sys.argv[1][1:].split('.'))) < tuple(map(int, version.split('.'))):
raise SystemExit('Refusing to prepare a release older than main')
PY
branch="chore/promote-$tag"
git switch -c "$branch" origin/main
git merge --no-commit --no-ff "$release_sha"
cp "$artifact_dir/flake.nix" "$artifact_dir/flake.lock" .
python3 "$script_dir/validate-release-version.py" --version "${tag#v}"
# Check against Cargo too: overriding the expectation above is only for artifacts.
python3 "$script_dir/validate-release-version.py"
git add flake.nix flake.lock
if ! git diff --cached --quiet || [[ -f "$(git rev-parse --git-path MERGE_HEAD)" ]]; then
git commit -m "release: promote $tag sources and Nix packages together"
fi
echo "Prepared $branch. Review the candidate, push normally, and open one PR against main."
+36
View File
@@ -0,0 +1,36 @@
#!/usr/bin/env bash
# Publish a tested snapshot flake beside its source branch; never open a main PR.
set -euo pipefail
source_branch="${GITHUB_REF_NAME:?Run this workflow from the source branch}"
read -r branch expected version < <(python3 - <<'PYMETA'
import json, re
from pathlib import Path
metadata = json.loads(Path('release-candidate.json').read_text())
if metadata['releaseTag'] != 'snapshot':
raise SystemExit('Only snapshot test branches can be published')
head = metadata['expectedTestHead']
if head and not re.fullmatch('[0-9a-f]{40}', head):
raise SystemExit('Invalid test branch lease')
print(metadata['testBranch'], head or '-', metadata['version'])
PYMETA
)
if [[ "$expected" == - ]]; then
expected=""
fi
git check-ref-format "refs/heads/$branch"
python3 scripts/validate-release-version.py --version "$version" --release-tag snapshot
if git diff --quiet -- flake.nix flake.lock; then
echo "Snapshot flake files are already up to date"
exit 0
fi
# The lease was captured before candidate generation and Nix validation.
# Concurrent or delayed runs cannot replace a newer branch update.
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git switch -c "$branch"
git add flake.nix flake.lock
git commit -m "test: prepare snapshot flake for $source_branch"
git push --force-with-lease="refs/heads/$branch:$expected" origin "HEAD:refs/heads/$branch"
echo "Published $branch from $source_branch for Nix testing"
+46
View File
@@ -0,0 +1,46 @@
#!/usr/bin/env python3
"""Retain one source pair per build run so retries cannot move branch refs."""
import argparse
import json
import os
import re
import subprocess
from pathlib import Path
def record(path, gp, gpgui, output):
if path.exists():
sources = json.loads(path.read_text())
else:
sources = {
name: subprocess.check_output(["git", "-C", str(root), "rev-parse", "HEAD"],
text=True, stderr=subprocess.DEVNULL).strip()
for name, root in (("gp_sha", gp), ("gpgui_sha", gpgui))
}
if set(sources) != {"gp_sha", "gpgui_sha"} or any(
not isinstance(value, str) or not re.fullmatch(r"[0-9a-f]{40}", value)
for value in sources.values()
):
raise ValueError("invalid retained build source refs")
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(json.dumps(sources, indent=2) + "\n")
with output.open("a") as stream:
for name, sha in sources.items():
stream.write(f"{name}={sha}\n")
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("path", type=Path)
parser.add_argument("--gp", type=Path, required=True)
parser.add_argument("--gpgui", type=Path, required=True)
args = parser.parse_args()
try:
record(args.path, args.gp, args.gpgui, Path(os.environ["GITHUB_OUTPUT"]))
except (OSError, ValueError, subprocess.CalledProcessError):
parser.exit(1, "Could not retain the selected build source refs.\n")
if __name__ == "__main__":
main()
+218
View File
@@ -0,0 +1,218 @@
import importlib.util
import json
import os
from pathlib import Path
import re
import subprocess
import tempfile
import unittest
ROOT = Path(__file__).resolve().parents[2]
def load(name):
spec = importlib.util.spec_from_file_location(name, ROOT / 'scripts' / f'{name}.py')
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
versions = load('validate-release-version')
sources = load('record-build-sources')
def git(root, *args):
return subprocess.check_output(['git', '-C', str(root), *args], text=True,
stderr=subprocess.DEVNULL).strip()
def initialize(root):
root.mkdir(parents=True, exist_ok=True)
git(root, 'init', '-b', 'main')
git(root, 'config', 'user.name', 'Release Test')
git(root, 'config', 'user.email', '[email protected]')
def write_version(root, cargo='3.1.0', flake=None, tag=None):
flake = flake or cargo
(root / 'Cargo.toml').write_text(f'[workspace.package]\nversion = "{cargo}"\n')
(root / 'flake.nix').write_text(f'releaseVersion = "{flake}";\nreleaseTag = "{tag or "v" + flake}";\n')
(root / 'flake.lock').write_text('{}\n')
def commit(root, title):
git(root, 'add', '.')
git(root, 'commit', '-m', title)
return git(root, 'rev-parse', 'HEAD')
class ReleaseVersionTests(unittest.TestCase):
def test_main_rejects_old_new_and_snapshot_flakes(self):
with tempfile.TemporaryDirectory() as temp:
root = Path(temp)
for selected, tag in [('3.1.0', 'v3.1.0'), ('3.3.0', 'v3.3.0'), ('3.2.0', 'snapshot')]:
write_version(root, '3.2.0', selected, tag)
with self.subTest(selected=selected, tag=tag), self.assertRaises(ValueError):
versions.validate(root)
write_version(root, '3.2.0')
self.assertEqual(versions.validate(root), '3.2.0')
def test_snapshot_candidate_is_allowed_outside_main(self):
with tempfile.TemporaryDirectory() as temp:
root = Path(temp)
write_version(root, '3.2.0', tag='snapshot')
self.assertEqual(versions.validate(root, release_tag='snapshot'), '3.2.0')
def test_rollback_of_both_version_fields_is_rejected(self):
with tempfile.TemporaryDirectory() as temp:
root = Path(temp)
initialize(root)
write_version(root, '3.3.0')
base = commit(root, 'new main')
write_version(root, '3.2.0')
with self.assertRaisesRegex(ValueError, 'older'):
versions.validate(root, base_ref=base)
def test_actual_package_version_must_match(self):
with tempfile.TemporaryDirectory() as temp:
root = Path(temp)
write_version(root, '3.2.0')
package = root / 'result'
(package / 'bin').mkdir(parents=True)
for name in ('gpclient', 'gpservice', 'gpauth', 'gpgui'):
tool = package / 'bin' / name
tool.write_text(f'#!/bin/sh\necho "{name} 3.2.0 (PRIVATE_IDENTITY)"\n')
tool.chmod(0o755)
versions.validate(root, package=package)
(package / 'bin/gpgui').write_text('#!/bin/sh\necho "gpgui 3.1.0 PRIVATE_DETAIL"\n')
with self.assertRaisesRegex(ValueError, 'gpgui'):
versions.validate(root, package=package)
class SourceSelectionTests(unittest.TestCase):
def test_retry_uses_original_sources_after_both_branches_advance(self):
with tempfile.TemporaryDirectory() as temp:
root = Path(temp)
paths = [root / 'gp', root / 'gpgui']
for repo in paths:
initialize(repo)
(repo / 'source').write_text('first')
commit(repo, 'first')
path, output = root / 'sources.json', root / 'output'
sources.record(path, *paths, output)
original = json.loads(path.read_text())
for repo in paths:
(repo / 'source').write_text('second')
commit(repo, 'second')
sources.record(path, *paths, output)
self.assertEqual(json.loads(path.read_text()), original)
self.assertEqual(output.read_text().count(f"gp_sha={original['gp_sha']}"), 2)
def test_corrupt_retained_sources_do_not_resolve_again(self):
with tempfile.TemporaryDirectory() as temp:
root = Path(temp)
path = root / 'sources.json'
path.write_text('{"gp_sha":"main","gpgui_sha":"main"}')
with self.assertRaises(ValueError):
sources.record(path, root, root, root / 'output')
class PromotionTests(unittest.TestCase):
def test_sources_and_flake_are_committed_together_preserving_main_work(self):
with tempfile.TemporaryDirectory() as temp:
root = Path(temp)
repo, origin, artifact = root / 'repo', root / 'origin.git', root / 'artifact'
initialize(repo)
write_version(repo)
old = commit(repo, '3.1')
git(repo, 'switch', '-c', 'release/next')
write_version(repo, '3.2.0', '3.1.0')
(repo / 'feature').write_text('released product feature')
release = commit(repo, '3.2 source')
git(repo, 'tag', 'v3.2.0')
git(repo, 'switch', 'main')
(repo / 'infrastructure').write_text('preserve newer main work')
main = commit(repo, 'main infrastructure')
git(root, 'init', '--bare', str(origin))
git(repo, 'remote', 'add', 'origin', str(origin))
git(repo, 'push', 'origin', 'main', 'v3.2.0')
artifact.mkdir()
write_version(artifact, '3.2.0')
(artifact / 'release-candidate.json').write_text(json.dumps({'version': '3.2.0', 'releaseTag': 'v3.2.0'}))
result = subprocess.run(['bash', str(ROOT / 'scripts/prepare-release-promotion.sh'),
'v3.2.0', str(artifact)], cwd=repo, capture_output=True, text=True)
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
self.assertEqual(versions.validate(repo), '3.2.0')
self.assertEqual(git(repo, 'rev-parse', 'main'), main)
self.assertEqual(git(repo, 'rev-parse', 'v3.2.0'), release)
self.assertEqual(git(repo, 'show', f'{old}:Cargo.toml'), '[workspace.package]\nversion = "3.1.0"')
self.assertTrue((repo / 'infrastructure').exists())
self.assertTrue((repo / 'feature').exists())
self.assertEqual(git(repo, 'rev-list', '--parents', '-1', 'HEAD').split()[1:], [main, release])
self.assertEqual(git(repo, 'status', '--porcelain'), '')
class SnapshotBranchTests(unittest.TestCase):
def run_publish(self, root, expected, version='3.2.0'):
write_version(root, version, tag='snapshot')
metadata = {'releaseTag': 'snapshot', 'version': version,
'testBranch': 'chore/flake-feature-example', 'expectedTestHead': expected}
(root / 'release-candidate.json').write_text(json.dumps(metadata))
env = dict(os.environ, GITHUB_REF_NAME='feature/example')
# CI checks out the same helper at its selected SHA. Use the real validator here.
(root / 'scripts').mkdir(exist_ok=True)
validator = root / 'scripts/validate-release-version.py'
validator.write_bytes((ROOT / 'scripts/validate-release-version.py').read_bytes())
return subprocess.run(['bash', str(ROOT / 'scripts/publish-flake-test-branch.sh')],
cwd=root, env=env, capture_output=True, text=True)
def test_branch_publication_and_stale_lease(self):
with tempfile.TemporaryDirectory() as temp:
root = Path(temp)
repo, origin = root / 'repo', root / 'origin.git'
initialize(repo)
write_version(repo, '3.2.0')
base = commit(repo, 'source')
git(root, 'init', '--bare', str(origin))
git(repo, 'remote', 'add', 'origin', str(origin))
first = self.run_publish(repo, '')
self.assertEqual(first.returncode, 0, first.stdout + first.stderr)
head = git(repo, 'rev-parse', 'HEAD')
self.assertEqual(git(origin, 'rev-parse', 'refs/heads/chore/flake-feature-example'), head)
git(repo, 'switch', '--detach', base)
git(repo, 'branch', '-D', 'chore/flake-feature-example')
# Another run already created the branch after this run captured an absent head.
stale = self.run_publish(repo, '', '3.2.1')
self.assertNotEqual(stale.returncode, 0)
self.assertIn('stale info', stale.stderr)
self.assertEqual(git(origin, 'rev-parse', 'refs/heads/chore/flake-feature-example'), head)
git(repo, 'switch', '--detach', base)
git(repo, 'branch', '-D', 'chore/flake-feature-example')
fresh = self.run_publish(repo, head, '3.2.1')
self.assertEqual(fresh.returncode, 0, fresh.stdout + fresh.stderr)
self.assertNotEqual(git(origin, 'rev-parse', 'refs/heads/chore/flake-feature-example'), head)
self.assertEqual(git(origin, 'branch', '--list', 'main'), '')
class DockerMatrixTests(unittest.TestCase):
def test_workflow_matrix_follows_all_architecture_choices(self):
source = (ROOT / '.github/workflows/release.yaml').read_text()
block = source.split(' const inputs = ${{ toJson(inputs) }}\n', 1)[1].split('\n build:', 1)[0]
# Execute the actual github-script block, including both returned matrices.
lines = []
for line in block.splitlines():
if line.strip() and not line.startswith(' '):
break
lines.append(line[10:])
js = '\n'.join(lines)
for arch, expected in [('all', ['linux/amd64', 'linux/arm64']),
('x86_64', ['linux/amd64']), ('arm64', ['linux/arm64'])]:
harness = 'const core={setOutput:(k,v)=>console.log(v)}; const inputs=' + json.dumps({'arch': arch}) + ';\n'
result = subprocess.check_output(['node', '-e', harness + '(function(){\n' + js + '\n})();'], text=True)
matrix = json.loads(result.splitlines()[0])
self.assertEqual([row['platform'] for row in matrix['include']], expected)
if __name__ == '__main__':
unittest.main()
@@ -1,8 +1,14 @@
import os
import shutil
import subprocess import subprocess
import sys
import tempfile import tempfile
import textwrap
import unittest import unittest
from pathlib import Path from pathlib import Path
from test_private_ci import run_block
REPOSITORY = "yuezk/GlobalProtect-openconnect" REPOSITORY = "yuezk/GlobalProtect-openconnect"
SCRIPT = Path(__file__).parents[1] / "validate-macos-appcast.py" SCRIPT = Path(__file__).parents[1] / "validate-macos-appcast.py"
@@ -112,5 +118,54 @@ class ValidateMacosAppcastTests(unittest.TestCase):
self.assertIn("unexpected update archive URL", result.stderr) self.assertIn("unexpected update archive URL", result.stderr)
class PublishMacosAppcastTests(unittest.TestCase):
def test_retry_reuses_existing_stable_appcast_without_uploading(self):
archive = f"https://github.com/{REPOSITORY}/releases/download/v2.6.4/GPConnect_2.6.4_arm64.zip"
existing = appcast(item("806.1", "2.6.4", archive))
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
(root / "updates").mkdir()
(root / "updates/appcast.xml").write_text("newly generated candidate")
(root / "existing.xml").write_text(existing)
(root / "scripts").mkdir()
shutil.copy(SCRIPT, root / "scripts/validate-macos-appcast.py")
(root / "python3").symlink_to(sys.executable)
gh = root / "gh"
gh.write_text(f"#!{sys.executable}\n" + textwrap.dedent('''\
import os, shutil, signal, sys
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
if sys.argv[1:3] == ['release', 'view']:
print('appcast.xml', flush=True)
for number in range(10000):
print(f'other-asset-{number}')
elif sys.argv[1:3] == ['release', 'download']:
shutil.copy(os.environ['EXISTING_APPCAST'],
sys.argv[sys.argv.index('--output') + 1])
else:
sys.exit(99)
'''))
gh.chmod(0o755)
uploader = root / "gp-release/scripts/upload-release-assets.sh"
uploader.parent.mkdir(parents=True)
uploader.write_text("#!/bin/sh\ntouch upload-attempted\nexit 7\n")
uploader.chmod(0o755)
command = run_block('.github/workflows/publish-update-feeds.yaml', 'Publish appcast')
for expression, value in {
'${{ steps.archive.outputs.name }}': 'GPConnect_2.6.4_arm64.zip',
'${{ steps.bundle.outputs.version }}': '806.1',
'${{ steps.bundle.outputs.short_version }}': '2.6.4',
}.items():
command = command.replace(expression, value)
result = subprocess.run(['bash', '-e', '-o', 'pipefail', '-c', command], cwd=root,
env=dict(os.environ, PATH=f'{root}:{os.environ["PATH"]}',
RUNNER_TEMP=str(root), CHANNEL='stable',
RELEASE_TAG='v2.6.4', REPOSITORY=REPOSITORY,
EXISTING_APPCAST=str(root / 'existing.xml')),
capture_output=True, text=True)
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
self.assertFalse((root / 'upload-attempted').exists())
self.assertEqual((root / 'updates/appcast.xml').read_text(), existing)
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()
+70
View File
@@ -0,0 +1,70 @@
#!/usr/bin/env python3
"""Check the release selected by a flake and, optionally, its installed tools."""
import argparse
import re
import subprocess
from pathlib import Path
def cargo_version(root, cargo=None):
if cargo is None:
cargo = (root / "Cargo.toml").read_text()
workspace = re.search(r"(?ms)^\[workspace\.package\]\s*\n(.*?)(?=^\[|\Z)", cargo)
if workspace is None:
raise ValueError("Cargo.toml has no workspace.package section")
return field(workspace[1], "version")
def field(text, name):
matches = re.findall(rf'^\s*{name}\s*=\s*"([^"]+)"\s*;?\s*$', text, re.M)
if len(matches) != 1:
raise ValueError(f"expected one {name} declaration")
return matches[0]
def validate(root, version=None, release_tag=None, package=None, base_ref=None):
expected = version or cargo_version(root)
if not re.fullmatch(r"(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)", expected):
raise ValueError("expected a stable X.Y.Z version")
tag = release_tag or f"v{expected}"
if tag not in (f"v{expected}", "snapshot"):
raise ValueError("release tag does not match the expected version")
flake = (root / "flake.nix").read_text()
if field(flake, "releaseVersion") != expected or field(flake, "releaseTag") != tag:
raise ValueError(f"flake must select {tag} at version {expected}")
if base_ref:
cargo = subprocess.check_output(["git", "-C", str(root), "show", f"{base_ref}:Cargo.toml"],
text=True, stderr=subprocess.DEVNULL)
base = cargo_version(root, cargo)
if tuple(map(int, expected.split("."))) < tuple(map(int, base.split("."))):
raise ValueError("candidate release is older than the main base")
if package:
for name in ("gpclient", "gpservice", "gpauth", "gpgui"):
result = subprocess.run([str(package / "bin" / name), "--version"],
capture_output=True, text=True, check=True)
# Keep private source identity and other command output out of logs.
match = re.match(rf"{name}\s+(\d+\.\d+\.\d+)(?:\s|$)", result.stdout)
if match is None or match[1] != expected:
raise ValueError(f"installed {name} does not report version {expected}")
return expected
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--root", type=Path, default=Path("."))
parser.add_argument("--version", help="Explicit candidate version; defaults to Cargo.toml")
parser.add_argument("--release-tag", help="Explicit candidate tag; defaults to v<version>")
parser.add_argument("--package", type=Path)
parser.add_argument("--base-ref", help="Reject a release older than this main commit")
args = parser.parse_args()
try:
version = validate(args.root, args.version, args.release_tag, args.package, args.base_ref)
except (OSError, ValueError, subprocess.CalledProcessError) as error:
# CalledProcessError does not include captured stdout/stderr in its string.
parser.exit(1, f"Release version check failed: {error}\n")
print(f"Verified release version {version}")
if __name__ == "__main__":
main()