Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2491f0eba1 | ||
|
|
0053ce8fcc | ||
|
|
13787d1af9 | ||
|
|
62e066c754 | ||
|
|
e4362a3d02 |
+12
-37
@@ -8,23 +8,26 @@
|
||||
# Trigger:
|
||||
# - push su main (incluso quello propagato dal mirror Gitea)
|
||||
# - PR aperte su GitHub
|
||||
# - run manuale via UI
|
||||
# - run manuale via UI (senza input)
|
||||
|
||||
name: Build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
branches:
|
||||
- main
|
||||
paths-ignore:
|
||||
- '**.md'
|
||||
- 'docs/**'
|
||||
- 'examples/**'
|
||||
pull_request:
|
||||
branches: [main]
|
||||
branches:
|
||||
- main
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
if: ${{ false }}
|
||||
runs-on: windows-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
@@ -44,13 +47,6 @@ jobs:
|
||||
- name: Setup MSBuild
|
||||
uses: microsoft/setup-msbuild@v3
|
||||
|
||||
- name: Read VERSION
|
||||
id: version
|
||||
shell: pwsh
|
||||
run: |
|
||||
$v = (Get-Content VERSION -Raw).Trim()
|
||||
"version=$v" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
|
||||
|
||||
- name: Build ${{ matrix.config }}
|
||||
run: python build_plugin.py --configs ${{ matrix.config }} --verbosity normal
|
||||
|
||||
@@ -58,20 +54,22 @@ jobs:
|
||||
shell: pwsh
|
||||
run: |
|
||||
$map = @{ 'x86-ansi' = 'x86-ansi'; 'x86-unicode' = 'x86-unicode'; 'x64-unicode' = 'amd64-unicode' }
|
||||
$src = "plugins\$($map['${{ matrix.config }}'])\nsis7z.dll"
|
||||
$dst = "dist\${{ matrix.config }}"
|
||||
$dir = $map['${{ matrix.config }}']
|
||||
$src = "plugins\$dir\nsis7z.dll"
|
||||
$dst = "dll-bundle\$dir"
|
||||
New-Item -ItemType Directory -Force -Path $dst | Out-Null
|
||||
Copy-Item $src $dst
|
||||
|
||||
- name: Upload DLL
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: ${{ github.event.repository.name }}-${{ steps.version.outputs.version }}-${{ matrix.config }}
|
||||
path: dist/**
|
||||
name: dll-win-${{ matrix.config }}
|
||||
path: dll-bundle/**
|
||||
if-no-files-found: error
|
||||
retention-days: 30
|
||||
|
||||
build-linux:
|
||||
if: ${{ false }}
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
@@ -98,30 +96,7 @@ jobs:
|
||||
g++-mingw-w64-i686 \
|
||||
g++-mingw-w64-x86-64
|
||||
|
||||
- name: Read VERSION
|
||||
id: version_linux
|
||||
run: |
|
||||
v="$(tr -d '\r\n' < VERSION)"
|
||||
echo "version=$v" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Build ${{ matrix.config }} on Linux
|
||||
run: python build_plugin.py --host linux --configs ${{ matrix.config }} --verbose
|
||||
|
||||
- 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/"
|
||||
|
||||
- name: Upload DLL
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: ${{ github.event.repository.name }}-${{ steps.version_linux.outputs.version }}-${{ matrix.config }}-linux
|
||||
path: dist/**
|
||||
if-no-files-found: error
|
||||
retention-days: 30
|
||||
|
||||
+122
-190
@@ -1,92 +1,86 @@
|
||||
# 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.
|
||||
# Strategia hosting:
|
||||
# - Repo primario su Gitea (push iniziale)
|
||||
# - Push mirror automatico Gitea -> GitHub
|
||||
# - GitHub esegue TUTTA la CI (Gitea non esegue Actions)
|
||||
#
|
||||
# Trigger:
|
||||
# - push di un tag v* (propagato dal mirror Gitea)
|
||||
#
|
||||
# - run manuale via UI (con input 'tag')
|
||||
|
||||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags: ['v*']
|
||||
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)'
|
||||
type: boolean
|
||||
required: false
|
||||
default: false
|
||||
type: string
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
build:
|
||||
if: ${{ !(github.event_name == 'workflow_dispatch' && inputs.gitea_only) }}
|
||||
runs-on: windows-latest
|
||||
strategy:
|
||||
fail-fast: true
|
||||
fail-fast: false
|
||||
matrix:
|
||||
config: [x86-ansi, x86-unicode, x64-unicode]
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v6
|
||||
with:
|
||||
submodules: recursive
|
||||
|
||||
- uses: actions/setup-python@v6
|
||||
- name: Setup Python
|
||||
uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: '3.11'
|
||||
|
||||
- uses: microsoft/setup-msbuild@v3
|
||||
- name: Setup MSBuild
|
||||
uses: microsoft/setup-msbuild@v3
|
||||
|
||||
- name: Build ${{ matrix.config }}
|
||||
run: python build_plugin.py --config ${{ matrix.config }}
|
||||
run: python build_plugin.py --configs ${{ matrix.config }} --verbosity normal
|
||||
|
||||
- name: Determine version & arch
|
||||
id: meta
|
||||
- name: Collect DLL
|
||||
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
|
||||
$src = "plugins\$dir\nsis7z.dll"
|
||||
$dst = "dll-bundle\$dir"
|
||||
New-Item -ItemType Directory -Force -Path $dst | Out-Null
|
||||
Copy-Item $src $dst
|
||||
|
||||
- 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
|
||||
- name: Upload DLL
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: pkg-${{ matrix.config }}
|
||||
path: '*.zip'
|
||||
name: dll-win-${{ matrix.config }}
|
||||
path: dll-bundle/**
|
||||
if-no-files-found: error
|
||||
|
||||
build-linux:
|
||||
if: ${{ !(github.event_name == 'workflow_dispatch' && inputs.gitea_only) }}
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: true
|
||||
fail-fast: false
|
||||
matrix:
|
||||
config: [x86-ansi, x86-unicode, x64-unicode]
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v6
|
||||
with:
|
||||
submodules: recursive
|
||||
|
||||
- uses: actions/setup-python@v6
|
||||
- name: Setup Python
|
||||
uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: '3.11'
|
||||
|
||||
@@ -101,43 +95,45 @@ jobs:
|
||||
g++-mingw-w64-x86-64
|
||||
|
||||
- name: Build ${{ matrix.config }} on Linux
|
||||
run: python build_plugin.py --host linux --configs ${{ matrix.config }}
|
||||
run: python build_plugin.py --host linux --configs ${{ matrix.config }} --verbose
|
||||
|
||||
- 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) }}
|
||||
needs: [build, build-linux]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v6
|
||||
|
||||
- uses: actions/download-artifact@v8
|
||||
with:
|
||||
path: artifacts
|
||||
merge-multiple: true
|
||||
|
||||
- name: Extract changelog section
|
||||
- name: Resolve release tag
|
||||
id: tag
|
||||
shell: bash
|
||||
run: |
|
||||
tag="${{ github.ref_name }}"
|
||||
if [ -z "$tag" ] || [ "$tag" = "main" ]; then
|
||||
tag="${{ inputs.tag }}"
|
||||
fi
|
||||
if [ -z "$tag" ]; then
|
||||
echo "Tag non disponibile. Imposta l'input 'tag' (es. v2.2.1)." >&2
|
||||
exit 1
|
||||
fi
|
||||
case "$tag" in
|
||||
v*) ;;
|
||||
*) tag="v$tag" ;;
|
||||
esac
|
||||
echo "tag=$tag" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Download DLL artifacts
|
||||
uses: actions/download-artifact@v8
|
||||
with:
|
||||
path: dll-bundle
|
||||
pattern: dll-win-*
|
||||
merge-multiple: true
|
||||
|
||||
- name: Extract changelog section
|
||||
run: |
|
||||
tag="${{ steps.tag.outputs.tag }}"
|
||||
version="${tag#v}"
|
||||
awk -v ver="[$version]" '
|
||||
/^## / && index($0, ver) { found=1; next }
|
||||
@@ -149,38 +145,49 @@ jobs:
|
||||
echo "---" >> release_body.md
|
||||
echo "_Repository primario: vedi link Gitea nel README. Il mirror GitHub è generato automaticamente._" >> release_body.md
|
||||
|
||||
- name: Package plugins ZIP
|
||||
id: pkg
|
||||
run: |
|
||||
tag="${{ steps.tag.outputs.tag }}"
|
||||
version="${tag#v}"
|
||||
zip_name="${{ github.event.repository.name }}-${version}-plugins.zip"
|
||||
(cd dll-bundle && zip -r "../$zip_name" .)
|
||||
echo "zip_name=$zip_name" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: SHA256SUMS
|
||||
run: |
|
||||
cd artifacts
|
||||
sha256sum *.zip > SHA256SUMS.txt
|
||||
sha256sum "${{ steps.pkg.outputs.zip_name }}" > SHA256SUMS.txt
|
||||
cat SHA256SUMS.txt
|
||||
|
||||
- name: Create GitHub Release
|
||||
uses: softprops/action-gh-release@v3
|
||||
with:
|
||||
tag_name: ${{ steps.tag.outputs.tag }}
|
||||
name: ${{ steps.tag.outputs.tag }}
|
||||
files: |
|
||||
artifacts/*.zip
|
||||
artifacts/SHA256SUMS.txt
|
||||
${{ steps.pkg.outputs.zip_name }}
|
||||
SHA256SUMS.txt
|
||||
body_path: release_body.md
|
||||
|
||||
- name: Update Gitea Release body
|
||||
- name: Update Gitea Release and upload assets
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
INPUT_TAG: ${{ inputs.tag }}
|
||||
GITEA_TAG: ${{ github.ref_name }}
|
||||
GITEA_TAG: ${{ steps.tag.outputs.tag }}
|
||||
ZIP_NAME: ${{ steps.pkg.outputs.zip_name }}
|
||||
run: |
|
||||
python3 - <<'PY'
|
||||
import json
|
||||
import mimetypes
|
||||
import os
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
from pathlib import Path
|
||||
|
||||
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()
|
||||
zip_name = os.environ.get("ZIP_NAME", "").strip()
|
||||
|
||||
if not tag:
|
||||
raise SystemExit("Tag non disponibile: imposta input 'tag' in workflow_dispatch")
|
||||
@@ -206,6 +213,29 @@ jobs:
|
||||
with urllib.request.urlopen(req) as resp:
|
||||
return json.loads(resp.read().decode("utf-8"))
|
||||
|
||||
def upload_asset(rid, path, auth_scheme):
|
||||
p = Path(path)
|
||||
mime = mimetypes.guess_type(p.name)[0] or "application/octet-stream"
|
||||
data = p.read_bytes()
|
||||
boundary = "----FormBoundary7MA4YWxkTrZu0gW"
|
||||
body_parts = (
|
||||
f"--{boundary}\r\n"
|
||||
f'Content-Disposition: form-data; name="attachment"; filename="{p.name}"\r\n'
|
||||
f"Content-Type: {mime}\r\n\r\n"
|
||||
).encode() + data + f"\r\n--{boundary}--\r\n".encode()
|
||||
req = urllib.request.Request(
|
||||
f"{base}/repos/{repo}/releases/{rid}/assets?name={p.name}",
|
||||
data=body_parts,
|
||||
method="POST",
|
||||
headers={
|
||||
"Authorization": f"{auth_scheme} {token}",
|
||||
"Content-Type": f"multipart/form-data; boundary={boundary}",
|
||||
"User-Agent": "GitHubActions-GiteaReleaseSync/1.0",
|
||||
},
|
||||
)
|
||||
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"):
|
||||
@@ -253,121 +283,23 @@ jobs:
|
||||
},
|
||||
auth_scheme=auth_scheme,
|
||||
)
|
||||
print(f"Created Gitea release id={created['id']} for tag {tag}")
|
||||
rid = created["id"]
|
||||
print(f"Created Gitea release id={rid} for tag {tag}")
|
||||
|
||||
# Rimuovi asset giĂ presenti con lo stesso nome (retag idempotente)
|
||||
existing = request("GET", f"/repos/{repo}/releases/{rid}/assets", auth_scheme=auth_scheme)
|
||||
upload_names = {zip_name, "SHA256SUMS.txt"}
|
||||
for asset in existing:
|
||||
if asset["name"] in upload_names:
|
||||
request("DELETE", f"/repos/{repo}/releases/assets/{asset['id']}", auth_scheme=auth_scheme)
|
||||
print(f"Deleted existing asset: {asset['name']}")
|
||||
|
||||
# Carica ZIP e SHA256SUMS
|
||||
for f in [zip_name, "SHA256SUMS.txt"]:
|
||||
if Path(f).exists():
|
||||
result = upload_asset(rid, f, auth_scheme)
|
||||
print(f"Uploaded {f} -> {result.get('browser_download_url', result.get('id'))}")
|
||||
else:
|
||||
print(f"WARNING: {f} not found, skipping upload")
|
||||
PY
|
||||
|
||||
sync-gitea-only:
|
||||
if: ${{ github.event_name == 'workflow_dispatch' && inputs.gitea_only }}
|
||||
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",
|
||||
"User-Agent": "GitHubActions-GiteaReleaseSync/1.0",
|
||||
},
|
||||
)
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user