371 lines
13 KiB
YAML
371 lines
13 KiB
YAML
# Release (GitHub) — pipeline release primaria
|
|
#
|
|
# Triggerata quando un tag v* viene propagato dal mirror Gitea.
|
|
# Costruisce gli artifact per tutte le architetture e crea la GitHub Release.
|
|
|
|
name: Release
|
|
|
|
on:
|
|
push:
|
|
tags: ['v*']
|
|
workflow_dispatch:
|
|
inputs:
|
|
tag:
|
|
description: 'Tag versione (es. v1.7.0)'
|
|
required: true
|
|
gitea_only:
|
|
description: 'Esegui solo sync release body su Gitea (salta build e GitHub release)'
|
|
required: false
|
|
default: 'false'
|
|
|
|
permissions:
|
|
contents: write
|
|
|
|
jobs:
|
|
build:
|
|
if: ${{ !(github.event_name == 'workflow_dispatch' && inputs.gitea_only == 'true') }}
|
|
runs-on: windows-latest
|
|
strategy:
|
|
fail-fast: true
|
|
matrix:
|
|
config: [x86-ansi, x86-unicode, x64-unicode]
|
|
steps:
|
|
- uses: actions/checkout@v6
|
|
with:
|
|
submodules: recursive
|
|
|
|
- uses: actions/setup-python@v6
|
|
with:
|
|
python-version: '3.11'
|
|
|
|
- uses: microsoft/setup-msbuild@v3
|
|
|
|
- name: Build ${{ matrix.config }}
|
|
run: python build_plugin.py --config ${{ matrix.config }}
|
|
|
|
- name: Determine version & arch
|
|
id: meta
|
|
shell: pwsh
|
|
run: |
|
|
$tag = "${{ github.ref_name }}"
|
|
if ([string]::IsNullOrEmpty($tag) -or $tag -eq "main") { $tag = "${{ inputs.tag }}" }
|
|
$v = $tag -replace '^v',''
|
|
$map = @{ 'x86-ansi' = 'x86-ansi'; 'x86-unicode' = 'x86-unicode'; 'x64-unicode' = 'amd64-unicode' }
|
|
$dir = $map['${{ matrix.config }}']
|
|
echo "version=$v" >> $env:GITHUB_OUTPUT
|
|
echo "tag=$tag" >> $env:GITHUB_OUTPUT
|
|
echo "dir=$dir" >> $env:GITHUB_OUTPUT
|
|
|
|
- name: Package
|
|
shell: pwsh
|
|
run: |
|
|
$name = "${{ github.event.repository.name }}-${{ steps.meta.outputs.version }}-${{ steps.meta.outputs.dir }}"
|
|
$stage = "stage/$name"
|
|
New-Item -ItemType Directory -Force -Path $stage | Out-Null
|
|
Copy-Item "dist/${{ steps.meta.outputs.dir }}/*" $stage -Recurse
|
|
Copy-Item README.md, LICENSE, VERSION, CHANGELOG.md $stage
|
|
if (Test-Path "include") { Copy-Item "include" $stage -Recurse }
|
|
if (Test-Path "examples") { Copy-Item "examples" $stage -Recurse }
|
|
Compress-Archive -Path "$stage/*" -DestinationPath "$name.zip" -Force
|
|
|
|
- uses: actions/upload-artifact@v7
|
|
with:
|
|
name: pkg-${{ matrix.config }}
|
|
path: '*.zip'
|
|
|
|
build-linux:
|
|
if: ${{ !(github.event_name == 'workflow_dispatch' && inputs.gitea_only == 'true') }}
|
|
runs-on: ubuntu-latest
|
|
strategy:
|
|
fail-fast: true
|
|
matrix:
|
|
config: [x86-ansi, x86-unicode, x64-unicode]
|
|
steps:
|
|
- uses: actions/checkout@v6
|
|
with:
|
|
submodules: recursive
|
|
|
|
- uses: actions/setup-python@v6
|
|
with:
|
|
python-version: '3.11'
|
|
|
|
- name: Install MinGW toolchain
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install -y \
|
|
make \
|
|
binutils-mingw-w64-i686 \
|
|
binutils-mingw-w64-x86-64 \
|
|
g++-mingw-w64-i686 \
|
|
g++-mingw-w64-x86-64
|
|
|
|
- name: Build ${{ matrix.config }} on Linux
|
|
run: python build_plugin.py --host linux --configs ${{ matrix.config }}
|
|
|
|
- name: Collect DLL
|
|
run: |
|
|
case "${{ matrix.config }}" in
|
|
x86-ansi) dir="x86-ansi" ;;
|
|
x86-unicode) dir="x86-unicode" ;;
|
|
x64-unicode) dir="amd64-unicode" ;;
|
|
esac
|
|
dst="dist/${{ matrix.config }}"
|
|
mkdir -p "$dst"
|
|
cp "plugins/$dir/nsis7z.dll" "$dst/"
|
|
|
|
- uses: actions/upload-artifact@v7
|
|
with:
|
|
name: linux-build-${{ matrix.config }}
|
|
path: dist/**
|
|
if-no-files-found: error
|
|
|
|
publish:
|
|
if: ${{ !(github.event_name == 'workflow_dispatch' && inputs.gitea_only == 'true') }}
|
|
needs: [build, build-linux]
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v6
|
|
|
|
- uses: actions/download-artifact@v8
|
|
with:
|
|
path: artifacts
|
|
merge-multiple: true
|
|
|
|
- name: Extract changelog section
|
|
run: |
|
|
tag="${{ github.ref_name }}"
|
|
if [ -z "$tag" ] || [ "$tag" = "main" ]; then
|
|
tag="${{ inputs.tag }}"
|
|
fi
|
|
version="${tag#v}"
|
|
awk -v ver="[$version]" '
|
|
/^## / && index($0, ver) { found=1; next }
|
|
found && /^## / { exit }
|
|
found { print }
|
|
' CHANGELOG.md > release_body.md
|
|
# Append Gitea notice
|
|
echo "" >> release_body.md
|
|
echo "---" >> release_body.md
|
|
echo "_Repository primario: vedi link Gitea nel README. Il mirror GitHub è generato automaticamente._" >> release_body.md
|
|
|
|
- name: SHA256SUMS
|
|
run: |
|
|
cd artifacts
|
|
sha256sum *.zip > SHA256SUMS.txt
|
|
cat SHA256SUMS.txt
|
|
|
|
- name: Create GitHub Release
|
|
uses: softprops/action-gh-release@v3
|
|
with:
|
|
files: |
|
|
artifacts/*.zip
|
|
artifacts/SHA256SUMS.txt
|
|
body_path: release_body.md
|
|
|
|
- name: Update Gitea Release body
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
INPUT_TAG: ${{ inputs.tag }}
|
|
GITEA_TAG: ${{ github.ref_name }}
|
|
run: |
|
|
python3 - <<'PY'
|
|
import json
|
|
import os
|
|
import urllib.error
|
|
import urllib.request
|
|
|
|
base = "https://gitea.emulab.it/api/v1"
|
|
repo = "Simone/nsis-plugin-ns7zip"
|
|
tag = os.environ.get("GITEA_TAG", "").strip()
|
|
if not tag or tag == "main":
|
|
tag = os.environ.get("INPUT_TAG", "").strip()
|
|
token = os.environ.get("GITEA_TOKEN", "").strip()
|
|
|
|
if not tag:
|
|
raise SystemExit("Tag non disponibile: imposta input 'tag' in workflow_dispatch")
|
|
if not token:
|
|
raise SystemExit("GITEA_TOKEN is missing or empty")
|
|
|
|
with open("release_body.md", "r", encoding="utf-8") as f:
|
|
body = f.read()
|
|
|
|
def request(method, path, payload=None, auth_scheme="token"):
|
|
data = json.dumps(payload).encode("utf-8") if payload is not None else None
|
|
req = urllib.request.Request(
|
|
f"{base}{path}",
|
|
data=data,
|
|
method=method,
|
|
headers={
|
|
"Authorization": f"{auth_scheme} {token}",
|
|
"Content-Type": "application/json",
|
|
"Accept": "application/json",
|
|
},
|
|
)
|
|
with urllib.request.urlopen(req) as resp:
|
|
return json.loads(resp.read().decode("utf-8"))
|
|
|
|
auth_scheme = None
|
|
last_error = None
|
|
for scheme in ("token", "Bearer"):
|
|
try:
|
|
user = request("GET", "/user", auth_scheme=scheme)
|
|
auth_scheme = scheme
|
|
print(f"Gitea auth OK via '{scheme}' as user: {user.get('login', '<unknown>')}")
|
|
break
|
|
except urllib.error.HTTPError as e:
|
|
try:
|
|
details = e.read().decode("utf-8", errors="replace")
|
|
except Exception:
|
|
details = ""
|
|
last_error = f"HTTP {e.code} {e.reason} ({scheme}) {details}".strip()
|
|
|
|
if not auth_scheme:
|
|
raise SystemExit(
|
|
"Gitea authentication failed for both 'token' and 'Bearer'. "
|
|
"Check secret GITEA_TOKEN value and permissions (Repository Read+Write). "
|
|
f"Last error: {last_error}"
|
|
)
|
|
|
|
try:
|
|
release = request("GET", f"/repos/{repo}/releases/tags/{tag}", auth_scheme=auth_scheme)
|
|
rid = release["id"]
|
|
request("PATCH", f"/repos/{repo}/releases/{rid}", {"body": body}, auth_scheme=auth_scheme)
|
|
print(f"Updated existing Gitea release id={rid} for tag {tag}")
|
|
except urllib.error.HTTPError as e:
|
|
if e.code != 404:
|
|
try:
|
|
details = e.read().decode("utf-8", errors="replace")
|
|
except Exception:
|
|
details = ""
|
|
raise SystemExit(f"Gitea release lookup/update failed: HTTP {e.code} {e.reason}. {details}".strip())
|
|
|
|
created = request(
|
|
"POST",
|
|
f"/repos/{repo}/releases",
|
|
{
|
|
"tag_name": tag,
|
|
"name": tag,
|
|
"body": body,
|
|
"draft": False,
|
|
"prerelease": False,
|
|
},
|
|
auth_scheme=auth_scheme,
|
|
)
|
|
print(f"Created Gitea release id={created['id']} for tag {tag}")
|
|
PY
|
|
|
|
sync-gitea-only:
|
|
if: ${{ github.event_name == 'workflow_dispatch' && inputs.gitea_only == 'true' }}
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v6
|
|
|
|
- name: Extract changelog section
|
|
run: |
|
|
tag="${{ inputs.tag }}"
|
|
version="${tag#v}"
|
|
awk -v ver="[$version]" '
|
|
/^## / && index($0, ver) { found=1; next }
|
|
found && /^## / { exit }
|
|
found { print }
|
|
' CHANGELOG.md > release_body.md
|
|
if [ ! -s release_body.md ]; then
|
|
echo "Sezione CHANGELOG non trovata per $tag"
|
|
exit 1
|
|
fi
|
|
echo "" >> release_body.md
|
|
echo "---" >> release_body.md
|
|
echo "_Repository primario: vedi link Gitea nel README. Il mirror GitHub è generato automaticamente._" >> release_body.md
|
|
|
|
- name: Update Gitea Release body
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
INPUT_TAG: ${{ inputs.tag }}
|
|
GITEA_TAG: ${{ github.ref_name }}
|
|
run: |
|
|
python3 - <<'PY'
|
|
import json
|
|
import os
|
|
import urllib.error
|
|
import urllib.request
|
|
|
|
base = "https://gitea.emulab.it/api/v1"
|
|
repo = "Simone/nsis-plugin-ns7zip"
|
|
tag = os.environ.get("GITEA_TAG", "").strip()
|
|
if not tag or tag == "main":
|
|
tag = os.environ.get("INPUT_TAG", "").strip()
|
|
token = os.environ.get("GITEA_TOKEN", "").strip()
|
|
|
|
if not tag:
|
|
raise SystemExit("Tag non disponibile: imposta input 'tag' in workflow_dispatch")
|
|
if not token:
|
|
raise SystemExit("GITEA_TOKEN is missing or empty")
|
|
|
|
with open("release_body.md", "r", encoding="utf-8") as f:
|
|
body = f.read()
|
|
|
|
def request(method, path, payload=None, auth_scheme="token"):
|
|
data = json.dumps(payload).encode("utf-8") if payload is not None else None
|
|
req = urllib.request.Request(
|
|
f"{base}{path}",
|
|
data=data,
|
|
method=method,
|
|
headers={
|
|
"Authorization": f"{auth_scheme} {token}",
|
|
"Content-Type": "application/json",
|
|
"Accept": "application/json",
|
|
},
|
|
)
|
|
with urllib.request.urlopen(req) as resp:
|
|
return json.loads(resp.read().decode("utf-8"))
|
|
|
|
auth_scheme = None
|
|
last_error = None
|
|
for scheme in ("token", "Bearer"):
|
|
try:
|
|
user = request("GET", "/user", auth_scheme=scheme)
|
|
auth_scheme = scheme
|
|
print(f"Gitea auth OK via '{scheme}' as user: {user.get('login', '<unknown>')}")
|
|
break
|
|
except urllib.error.HTTPError as e:
|
|
try:
|
|
details = e.read().decode("utf-8", errors="replace")
|
|
except Exception:
|
|
details = ""
|
|
last_error = f"HTTP {e.code} {e.reason} ({scheme}) {details}".strip()
|
|
|
|
if not auth_scheme:
|
|
raise SystemExit(
|
|
"Gitea authentication failed for both 'token' and 'Bearer'. "
|
|
"Check secret GITEA_TOKEN value and permissions (Repository Read+Write). "
|
|
f"Last error: {last_error}"
|
|
)
|
|
|
|
try:
|
|
release = request("GET", f"/repos/{repo}/releases/tags/{tag}", auth_scheme=auth_scheme)
|
|
rid = release["id"]
|
|
request("PATCH", f"/repos/{repo}/releases/{rid}", {"body": body}, auth_scheme=auth_scheme)
|
|
print(f"Updated existing Gitea release id={rid} for tag {tag}")
|
|
except urllib.error.HTTPError as e:
|
|
if e.code != 404:
|
|
try:
|
|
details = e.read().decode("utf-8", errors="replace")
|
|
except Exception:
|
|
details = ""
|
|
raise SystemExit(f"Gitea release lookup/update failed: HTTP {e.code} {e.reason}. {details}".strip())
|
|
|
|
created = request(
|
|
"POST",
|
|
f"/repos/{repo}/releases",
|
|
{
|
|
"tag_name": tag,
|
|
"name": tag,
|
|
"body": body,
|
|
"draft": False,
|
|
"prerelease": False,
|
|
},
|
|
auth_scheme=auth_scheme,
|
|
)
|
|
print(f"Created Gitea release id={created['id']} for tag {tag}")
|
|
PY
|