Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .PSScriptAnalyzerSettings.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@{
Severity = @('Error', 'Warning')
IncludeRules = @(
'PSAvoidUsingInvokeExpression',
'PSAvoidUsingPlainTextForPassword',
'PSAvoidUsingConvertToSecureStringWithPlainText',
'PSAvoidUsingUsernameAndPasswordParams',
'PSAvoidUsingAllowUnencryptedAuthentication',
'PSAvoidUsingBrokenHashAlgorithms',
'PSAvoidUsingComputerNameHardcoded',
'PSAvoidUsingCmdletAliases',
'PSAvoidUsingWMICmdlet',
'PSPossibleIncorrectComparisonWithNull',
'PSPossibleIncorrectUsageOfAssignmentOperator',
'PSPossibleIncorrectUsageOfRedirectionOperator',
'PSUseDeclaredVarsMoreThanAssignments',
'PSAvoidUsingDoubleQuotesForConstantString',
'PSAvoidDefaultValueSwitchParameter',
'PSReservedCmdletChar',
'PSReservedParams',
'PSMissingModuleManifestField',
'PSAvoidUsingDeprecatedManifestFields'
)
}
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ web/dist/** text eol=lf
/.gitattributes export-ignore
/.gitignore export-ignore
/.github export-ignore
/.PSScriptAnalyzerSettings.psd1 export-ignore
/CONTRIBUTING.md export-ignore
/TODO.md export-ignore
/scripts export-ignore
/tests export-ignore
/web/.gitignore export-ignore
/web/e2e export-ignore
Expand Down
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Default repository owner for pull request review and security governance.
* @Scrates1
40 changes: 33 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-node@8fccf151e3ba8038c300f83b40c8fd1e94f9c5ce # v7.2.0
with:
node-version: 22
cache: npm
cache-dependency-path: web/package-lock.json
- name: Install frontend dependencies
working-directory: web
run: npm ci
- name: Audit production frontend dependencies
working-directory: web
run: npm audit --omit=dev --audit-level=high
- name: Test and build frontend
working-directory: web
run: npm run check
Expand All @@ -38,14 +41,18 @@ jobs:
echo 'web/dist is not synchronized with web/src. Run npm run build in web/ and commit the result.' >&2
exit 1
fi
- name: Verify release metadata and release scripts
run: |
node scripts/verify-release.mjs
node --test tests/test-release-scripts.mjs

browser-e2e:
name: Browser session E2E
runs-on: windows-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-node@8fccf151e3ba8038c300f83b40c8fd1e94f9c5ce # v7.2.0
with:
node-version: 22
cache: npm
Expand All @@ -62,7 +69,7 @@ jobs:
runs-on: windows-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v7
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Run manager tests
shell: powershell
run: .\tests\Test-Manager.ps1
Expand All @@ -72,7 +79,26 @@ jobs:
runs-on: windows-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v7
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Run PSScriptAnalyzer security checks
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
if (-not (Get-Module -ListAvailable -Name PSScriptAnalyzer)) {
Install-Module -Name PSScriptAnalyzer -Scope CurrentUser -Force -ErrorAction Stop
}
Import-Module PSScriptAnalyzer -ErrorAction Stop
$files = @('proxy-manager.ps1', 'proxy-manager-react-host.ps1') + @(
Get-ChildItem -Path src -Recurse -Filter '*.ps1' | ForEach-Object { $_.FullName }
)
$findings = @(foreach ($file in $files) {
Invoke-ScriptAnalyzer -Path $file -Settings .PSScriptAnalyzerSettings.psd1
})
if ($findings.Count -gt 0) {
$findings | Format-Table ScriptName, Line, Severity, RuleName, Message -AutoSize
throw "PSScriptAnalyzer detected $($findings.Count) security/correctness finding(s)."
}
Write-Host "PSScriptAnalyzer passed across $($files.Count) PowerShell files."
- name: Run manager tests
shell: pwsh
run: .\tests\Test-Manager.ps1
Expand All @@ -82,7 +108,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v7
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Check POSIX and Bash shell syntax
run: |
for file in linux/runtime/*.sh; do
Expand Down
133 changes: 89 additions & 44 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,14 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v7
- name: Verify release version
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-node@8fccf151e3ba8038c300f83b40c8fd1e94f9c5ce # v7.2.0
with:
node-version: 22
- name: Verify release metadata and changelog
run: |
version="$(tr -d '[:space:]' < VERSION)"
pkg_version="$(node -p "require('./web/package.json').version")"
if [[ "${GITHUB_REF_NAME}" != "v${version}" ]]; then
echo "Tag ${GITHUB_REF_NAME} does not match VERSION ${version}." >&2
exit 1
fi
if [[ "${pkg_version}" != "${version}" ]]; then
echo "web/package.json version ${pkg_version} does not match VERSION ${version}." >&2
exit 1
fi
node scripts/verify-release.mjs --tag "${GITHUB_REF_NAME}"
node --test tests/test-release-scripts.mjs
- name: Check POSIX and Bash shell syntax
run: |
for file in linux/runtime/*.sh; do
Expand All @@ -46,26 +41,21 @@ jobs:
runs-on: windows-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v7
- name: Verify release version
shell: pwsh
run: |
$version = (Get-Content -Raw -LiteralPath VERSION).Trim()
$packageVersion = (Get-Content -Raw -LiteralPath web/package.json | ConvertFrom-Json).version
if ($env:GITHUB_REF_NAME -ne "v$version") {
throw "Tag $env:GITHUB_REF_NAME does not match VERSION $version."
}
if ($packageVersion -ne $version) {
throw "web/package.json version $packageVersion does not match VERSION $version."
}
- uses: actions/setup-node@v7
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-node@8fccf151e3ba8038c300f83b40c8fd1e94f9c5ce # v7.2.0
with:
node-version: 22
cache: npm
cache-dependency-path: web/package-lock.json
- name: Verify release metadata and changelog
shell: pwsh
run: node scripts/verify-release.mjs --tag "$env:GITHUB_REF_NAME"
- name: Install frontend dependencies
working-directory: web
run: npm ci
- name: Audit production frontend dependencies
working-directory: web
run: npm audit --omit=dev --audit-level=high
- name: Test and build frontend
working-directory: web
run: npm run check
Expand All @@ -80,6 +70,24 @@ jobs:
$changes | Write-Host
throw 'web/dist is not synchronized with web/src.'
}
- name: Run PSScriptAnalyzer security checks
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
if (-not (Get-Module -ListAvailable -Name PSScriptAnalyzer)) {
Install-Module -Name PSScriptAnalyzer -Scope CurrentUser -Force -ErrorAction Stop
}
Import-Module PSScriptAnalyzer -ErrorAction Stop
$files = @('proxy-manager.ps1', 'proxy-manager-react-host.ps1') + @(
Get-ChildItem -Path src -Recurse -Filter '*.ps1' | ForEach-Object { $_.FullName }
)
$findings = @(foreach ($file in $files) {
Invoke-ScriptAnalyzer -Path $file -Settings .PSScriptAnalyzerSettings.psd1
})
if ($findings.Count -gt 0) {
$findings | Format-Table ScriptName, Line, Severity, RuleName, Message -AutoSize
throw "PSScriptAnalyzer detected $($findings.Count) security/correctness finding(s)."
}
- name: Run Windows PowerShell 5.1 manager tests
shell: powershell
run: .\tests\Test-Manager.ps1
Expand All @@ -96,18 +104,24 @@ jobs:
timeout-minutes: 10
permissions:
contents: write
id-token: write
attestations: write
steps:
- uses: actions/checkout@v7
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
- uses: actions/setup-node@8fccf151e3ba8038c300f83b40c8fd1e94f9c5ce # v7.2.0
with:
node-version: 22
- name: Resolve release metadata and changelog notes
run: |
node scripts/verify-release.mjs \
--tag "${GITHUB_REF_NAME}" \
--write-notes "${RUNNER_TEMP}/release-notes.md" \
--github-env "${GITHUB_ENV}"
- name: Create and verify release archive
run: |
version="$(tr -d '[:space:]' < VERSION)"
if [[ "${GITHUB_REF_NAME}" != "v${version}" ]]; then
echo "Tag ${GITHUB_REF_NAME} does not match VERSION ${version}." >&2
exit 1
fi
prefix="clash-ssh-proxy-bootstrap-${version}"
prefix="clash-ssh-proxy-bootstrap-${RELEASE_VERSION}"
archive="${prefix}.zip"
git archive --format=zip --prefix="${prefix}/" --output="${archive}" HEAD
entries="$(unzip -Z1 "${archive}")"
Expand All @@ -124,23 +138,54 @@ jobs:
exit 1
fi
done
if grep -Eq "^${prefix}/(tests|\.github|web/src|web/e2e|web/package-lock\.json)(/|$)" <<< "${entries}"; then
if grep -Eq "^${prefix}/(tests|scripts|\.github|\.PSScriptAnalyzerSettings\.psd1|web/src|web/e2e|web/package-lock\.json)(/|$)" <<< "${entries}"; then
echo "Release archive contains excluded development files:" >&2
grep -E "^${prefix}/(tests|\.github|web/src|web/e2e|web/package-lock\.json)(/|$)" <<< "${entries}" >&2
grep -E "^${prefix}/(tests|scripts|\.github|\.PSScriptAnalyzerSettings\.psd1|web/src|web/e2e|web/package-lock\.json)(/|$)" <<< "${entries}"
exit 1
fi
sha256sum "${archive}" > "${archive}.sha256"
{
echo "RELEASE_VERSION=${version}"
echo "RELEASE_ARCHIVE=${archive}"
} >> "${GITHUB_ENV}"
sha256sum -c "${archive}.sha256"
echo "RELEASE_ARCHIVE=${archive}" >> "${GITHUB_ENV}"
- name: Generate build provenance attestation
uses: actions/attest-build-provenance@96278af6caaf10aea03fd8d33a09a777ca52d62f # v3.2.0
with:
subject-path: ${{ env.RELEASE_ARCHIVE }}
- name: Publish GitHub release
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release create "${GITHUB_REF_NAME}" \
"${RELEASE_ARCHIVE}" \
"${RELEASE_ARCHIVE}.sha256" \
--verify-tag \
--generate-notes \
--title "Clash SSH Proxy Manager ${RELEASE_VERSION}"
args=(
"${GITHUB_REF_NAME}"
"${RELEASE_ARCHIVE}"
"${RELEASE_ARCHIVE}.sha256"
--verify-tag
--notes-file "${RUNNER_TEMP}/release-notes.md"
--title "${RELEASE_TITLE}"
)
if [[ "${IS_PRERELEASE}" == "true" ]]; then
args+=(--prerelease)
fi
gh release create "${args[@]}"
- name: Verify published GitHub release assets
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release view "${GITHUB_REF_NAME}" --json tagName,isPrerelease,assets | node -e "
const fs = require('node:fs');
const data = JSON.parse(fs.readFileSync(0, 'utf8'));
const expectedTag = process.env.GITHUB_REF_NAME;
const expectedPre = process.env.IS_PRERELEASE === 'true';
const expectedZip = process.env.RELEASE_ARCHIVE;
const expectedSha = expectedZip + '.sha256';
if (data.tagName !== expectedTag) {
throw new Error('Unexpected tagName: ' + data.tagName);
}
if (Boolean(data.isPrerelease) !== expectedPre) {
throw new Error('Unexpected isPrerelease: ' + data.isPrerelease);
}
const names = new Set((data.assets || []).map((a) => a.name));
if (!names.has(expectedZip) || !names.has(expectedSha)) {
throw new Error('Missing expected release assets: ' + Array.from(names).join(', '));
}
console.log('Verified published GitHub Release ' + data.tagName + ' (prerelease=' + data.isPrerelease + ').');
"
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ $prep = .\proxy-manager.ps1 prepare-ssh -Name edge-prod -RemoteHost 203.0.113.10
- Maintain compatibility with both **Windows PowerShell 5.1** and **PowerShell 7**.
- Keep `web/dist` synchronized with `web/src` (`cd web && npm run check`).
- Never commit private RFC 1918 IPv4 addresses, personal usernames, or key material (enforced by `tests/test-privacy.sh`). Use RFC 5737 documentation IPs (`203.0.113.10`, `198.51.100.8`, `192.0.2.17`).
- **Release discipline**: Never bypass branch protection on `main` or push a `v*` release tag before all 5 required CI checks (including Windows PowerShell 5.1, PowerShell 7, and Edge E2E) pass on a PR. Use `node scripts/prepare-release.mjs <X.Y.Z>` on a `release/v<X.Y.Z>` branch, fill in `CHANGELOG.md`, verify with `node scripts/verify-release.mjs --tag v<X.Y.Z>`, optionally validate on Windows via a `v<X.Y.Z>-rc.1` pre-release tag, merge the PR to `main`, and only then tag `v<X.Y.Z>` on `main`.
54 changes: 50 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,53 @@ keys, `authorized_keys`, or copied production logs.

## Releases

A `v<version>` tag must match both `VERSION` and `web/package.json`. The release
workflow repeats all platform checks, verifies `web/dist`, and publishes a Git
archive with a SHA-256 checksum. Code signing is intentionally outside this
repository until a trusted signing identity is configured.
Never push release commits or `v*` tags directly to `main` before the required
CI checks pass. Follow this standard release workflow:

1. **Merge all feature PRs into `main` first** and confirm all 5 required CI
checks (`React build and tests`, `Browser session E2E`, `Windows PowerShell 5.1`,
`PowerShell 7`, and `Linux scripts and privacy`) are green.
2. **Create a release branch from `main`** and run the release preparation script:

```bash
git checkout main && git pull
git checkout -b release/v1.6.0
node scripts/prepare-release.mjs 1.6.0
```

This updates `VERSION`, `web/package.json`, `web/package-lock.json`,
`README.md`, `README.zh-CN.md`, `docs/WINDOWS-UI.en-US.md`,
`docs/WINDOWS-UI.zh-CN.md`, inserts a stub in `CHANGELOG.md`, and rebuilds
`web/dist` via `npm run check`.
3. **Fill in `CHANGELOG.md`** under `## 1.6.0 - YYYY-MM-DD` (replacing the
placeholder line) and validate all release metadata:

```bash
node scripts/verify-release.mjs --tag v1.6.0
```

4. **Open a pull request** from `release/v1.6.0` to `main` and wait for all 5
required CI checks to pass.
5. **Optional Windows RC smoke test (recommended for OS / task-scheduler /
self-update changes)**: push a pre-release tag `v1.6.0-rc.1` on the green
release branch commit. `.github/workflows/release.yml` automatically marks
`-rc.N` tags as GitHub **Pre-releases** (ignored by stable in-app update
checks) and attaches `clash-ssh-proxy-bootstrap-1.6.0-rc.1.zip` + `.sha256`
for real Windows verification (including upgrading from the previous stable
release and testing sign-out/sign-in behavior).
6. **Merge the release PR into `main`**, then create and push the stable tag on
the merged `main` commit:

```bash
git checkout main && git pull
git tag -a v1.6.0 -m "Release v1.6.0"
git push origin v1.6.0
```

7. **Verify the published release**: `.github/workflows/release.yml` re-runs
Linux and Windows validation, verifies `web/dist` and `CHANGELOG.md`, builds
a clean Git archive (excluding `tests/`, `scripts/`, `.github/`, and frontend
sources), generates and checks `.sha256`, extracts release notes directly from
`CHANGELOG.md`, publishes the GitHub Release, and verifies the uploaded assets.
Code signing is intentionally outside this repository until a trusted signing
identity is configured.
Loading