generated from MrSphay/codex-agent-repository-kit
103 lines
3.9 KiB
YAML
103 lines
3.9 KiB
YAML
name: Build MrTrust
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
pull_request:
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
env:
|
|
MRTRUST_VERSION: 0.1.3
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup .NET
|
|
uses: actions/setup-dotnet@v4
|
|
with:
|
|
dotnet-version: 8.0.x
|
|
|
|
- name: Build Windows EXE
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
dotnet publish src/MrTrustLauncher.csproj \
|
|
--configuration Release \
|
|
--runtime win-x64 \
|
|
--output dist/build \
|
|
-p:EnableWindowsTargeting=true \
|
|
-p:PublishSingleFile=true \
|
|
-p:SelfContained=true
|
|
cp dist/build/MrTrust.exe dist/MrTrust.exe
|
|
|
|
- name: Build release ZIP
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
version="${MRTRUST_VERSION}"
|
|
package_root="dist/MrTrust-${version}"
|
|
rm -rf "$package_root" "dist/MrTrust-${version}.zip"
|
|
mkdir -p "$package_root"
|
|
cp dist/MrTrust.exe "$package_root/"
|
|
cp README.md "$package_root/"
|
|
(cd dist && zip -r "MrTrust-${version}.zip" "MrTrust-${version}")
|
|
|
|
- name: Show package contents
|
|
shell: bash
|
|
run: |
|
|
find dist -maxdepth 4 -type f -printf '%p %s bytes\n'
|
|
|
|
- name: Upload release artifact
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: MrTrust-${{ env.MRTRUST_VERSION }}
|
|
path: dist/MrTrust-${{ env.MRTRUST_VERSION }}.zip
|
|
|
|
- name: Attach ZIP to Gitea release
|
|
if: github.ref == 'refs/heads/main'
|
|
shell: bash
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
run: |
|
|
set -euo pipefail
|
|
version="${MRTRUST_VERSION}"
|
|
asset_name="MrTrust-${version}.zip"
|
|
api="https://git.wilkensxl.de/api/v1/repos/MrSphay/MrTrust"
|
|
release_response="$(mktemp)"
|
|
status="$(curl -sS -o "$release_response" -w "%{http_code}" -H "Authorization: token ${GITEA_TOKEN}" "${api}/releases/tags/v${version}")"
|
|
if [ "$status" = "404" ]; then
|
|
release_json="$(VERSION="$version" python3 -c 'import json, os; version = os.environ["VERSION"]; print(json.dumps({"tag_name": f"v{version}", "target_commitish": "main", "name": f"MrTrust v{version}", "body": f"MrTrust v{version} release built by the Gitea runner.", "draft": False, "prerelease": False}))')"
|
|
curl -fsS \
|
|
-X POST \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "$release_json" \
|
|
"${api}/releases" > "$release_response"
|
|
elif [ "$status" != "200" ]; then
|
|
cat "$release_response" >&2
|
|
exit 1
|
|
fi
|
|
release_json="$(cat "$release_response")"
|
|
release_id="$(printf '%s' "$release_json" | python3 -c 'import json,sys; print(json.load(sys.stdin)["id"])')"
|
|
if [ -z "$release_id" ]; then
|
|
echo "Could not resolve release id for v${version}" >&2
|
|
exit 1
|
|
fi
|
|
existing_asset_id="$(RELEASE_JSON="$release_json" ASSET_NAME="$asset_name" python3 -c 'import json, os; release = json.loads(os.environ["RELEASE_JSON"]); asset_name = os.environ["ASSET_NAME"]; print(next((str(asset.get("id", "")) for asset in release.get("assets", []) if asset.get("name") == asset_name), ""))')"
|
|
if [ -n "$existing_asset_id" ]; then
|
|
curl -fsS \
|
|
-X DELETE \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
"${api}/releases/${release_id}/assets/${existing_asset_id}"
|
|
fi
|
|
curl -fsS \
|
|
-X POST \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
-F "attachment=@dist/${asset_name}" \
|
|
"${api}/releases/${release_id}/assets?name=${asset_name}"
|