Catalog Lite
This commit is contained in:
parent
398cfa310e
commit
181229aa41
18 changed files with 1435 additions and 0 deletions
199
.forgejo/workflows/build-catalog-lite.yml
Normal file
199
.forgejo/workflows/build-catalog-lite.yml
Normal file
|
|
@ -0,0 +1,199 @@
|
|||
name: Build Catalog Lite
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
expiration_date:
|
||||
description: Catalog Lite expiration date, yyyy-MM-dd
|
||||
required: true
|
||||
default: '2026-12-31'
|
||||
publish_release:
|
||||
description: Publish Forgejo release when running on a tag ref
|
||||
required: true
|
||||
default: 'false'
|
||||
|
||||
env:
|
||||
DOTNET_VERSION: 10.0.x
|
||||
PROJECT_PATH: CatalogLite/CatalogLite.csproj
|
||||
CATALOG_LITE_EXPIRATION_DATE: ${{ inputs.expiration_date }}
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: docker
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- runtime: win-x64
|
||||
artifact_name: catalog-lite-win-x64
|
||||
- runtime: linux-x64
|
||||
artifact_name: catalog-lite-linux-x64
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: ${{ env.DOTNET_VERSION }}
|
||||
|
||||
- name: Validate expiration date
|
||||
run: |
|
||||
set -eu
|
||||
case "${CATALOG_LITE_EXPIRATION_DATE}" in
|
||||
????-??-??) ;;
|
||||
*)
|
||||
echo "expiration_date must use yyyy-MM-dd format"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
- name: Restore
|
||||
run: dotnet restore "${{ env.PROJECT_PATH }}" -r "${{ matrix.runtime }}" --configfile NuGet.Config
|
||||
|
||||
- name: Publish Catalog Lite
|
||||
env:
|
||||
PUBLISH_DIR: artifacts/publish/${{ matrix.runtime }}
|
||||
run: |
|
||||
set -eu
|
||||
dotnet publish "${{ env.PROJECT_PATH }}" \
|
||||
-c Release \
|
||||
-r "${{ matrix.runtime }}" \
|
||||
--self-contained true \
|
||||
--no-restore \
|
||||
-p:CatalogLiteExpirationDate="${CATALOG_LITE_EXPIRATION_DATE}" \
|
||||
-p:PublishSingleFile=true \
|
||||
-p:PublishTrimmed=false \
|
||||
-p:PublishReadyToRun=false \
|
||||
-o "${PUBLISH_DIR}"
|
||||
|
||||
- name: Validate published files
|
||||
env:
|
||||
PUBLISH_DIR: artifacts/publish/${{ matrix.runtime }}
|
||||
run: |
|
||||
set -eu
|
||||
if [ "${{ matrix.runtime }}" = "win-x64" ]; then
|
||||
file_count="$(find "${PUBLISH_DIR}" -maxdepth 1 -type f -iname '*.exe' | wc -l | tr -d ' ')"
|
||||
else
|
||||
file_count="$(find "${PUBLISH_DIR}" -maxdepth 1 -type f -name 'CatalogLite' | wc -l | tr -d ' ')"
|
||||
fi
|
||||
|
||||
if [ "${file_count}" -eq 0 ]; then
|
||||
echo "No Catalog Lite executable produced in ${PUBLISH_DIR}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Upload publish artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: ${{ matrix.artifact_name }}
|
||||
path: artifacts/publish/${{ matrix.runtime }}
|
||||
if-no-files-found: error
|
||||
|
||||
release:
|
||||
if: ${{ inputs.publish_release == 'true' && startsWith(github.ref, 'refs/tags/') }}
|
||||
needs: build
|
||||
runs-on: docker
|
||||
env:
|
||||
FORGEJO_TOKEN: ${{ secrets.FORGEJO_TOKEN }}
|
||||
|
||||
steps:
|
||||
- name: Download Windows artifact
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: catalog-lite-win-x64
|
||||
path: artifacts/release/win-x64
|
||||
|
||||
- name: Download Linux artifact
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: catalog-lite-linux-x64
|
||||
path: artifacts/release/linux-x64
|
||||
|
||||
- name: Validate release token
|
||||
run: |
|
||||
set -eu
|
||||
if [ -z "${FORGEJO_TOKEN}" ]; then
|
||||
echo "secrets.FORGEJO_TOKEN is required for Catalog Lite releases"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Create or update release
|
||||
run: |
|
||||
set -eu
|
||||
api_base="${GITHUB_SERVER_URL%/}/api/v1/repos/${GITHUB_REPOSITORY}"
|
||||
tag="${GITHUB_REF_NAME}"
|
||||
create_payload="$(printf '{"tag_name":"%s","name":"%s","body":"Catalog Lite\\n\\nScadenza build: %s","draft":false,"prerelease":false}' "${tag}" "${tag}" "${CATALOG_LITE_EXPIRATION_DATE}")"
|
||||
update_payload="$(printf '{"body":"Catalog Lite\\n\\nScadenza build: %s"}' "${CATALOG_LITE_EXPIRATION_DATE}")"
|
||||
|
||||
http_code="$(curl -sS -o release.json -w '%{http_code}' \
|
||||
-H "Authorization: token ${FORGEJO_TOKEN}" \
|
||||
"${api_base}/releases/tags/${tag}")"
|
||||
|
||||
if [ "${http_code}" = "200" ]; then
|
||||
release_id="$(sed -n 's/.*"id":\([0-9][0-9]*\).*/\1/p' release.json | head -n1)"
|
||||
curl -fsS \
|
||||
-H "Authorization: token ${FORGEJO_TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-X PATCH \
|
||||
-d "${update_payload}" \
|
||||
"${api_base}/releases/${release_id}" \
|
||||
-o release.json
|
||||
elif [ "${http_code}" = "404" ]; then
|
||||
curl -fsS \
|
||||
-H "Authorization: token ${FORGEJO_TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-X POST \
|
||||
-d "${create_payload}" \
|
||||
"${api_base}/releases" \
|
||||
-o release.json
|
||||
release_id="$(sed -n 's/.*"id":\([0-9][0-9]*\).*/\1/p' release.json | head -n1)"
|
||||
else
|
||||
echo "Unexpected response while loading release for tag ${tag}: ${http_code}"
|
||||
cat release.json
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "${release_id}" ]; then
|
||||
echo "Unable to resolve Forgejo release id"
|
||||
cat release.json
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "RELEASE_ID=${release_id}" >> "${GITHUB_ENV}"
|
||||
|
||||
- name: Upload release assets
|
||||
run: |
|
||||
set -eu
|
||||
api_base="${GITHUB_SERVER_URL%/}/api/v1/repos/${GITHUB_REPOSITORY}"
|
||||
short_sha="$(printf '%s' "${GITHUB_SHA}" | cut -c1-12)"
|
||||
|
||||
windows_exe="$(find artifacts/release/win-x64 -maxdepth 1 -type f -iname '*.exe' | head -n1)"
|
||||
linux_exe="$(find artifacts/release/linux-x64 -maxdepth 1 -type f -name 'CatalogLite' | head -n1)"
|
||||
|
||||
if [ -z "${windows_exe}" ]; then
|
||||
echo "No Windows executable found in downloaded artifact"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "${linux_exe}" ]; then
|
||||
echo "No Linux executable found in downloaded artifact"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
linux_archive="CatalogLite-linux-x64-${GITHUB_REF_NAME}-${short_sha}.tar.gz"
|
||||
tar -czf "${linux_archive}" -C "$(dirname "${linux_exe}")" "$(basename "${linux_exe}")"
|
||||
|
||||
upload_asset() {
|
||||
asset_path="$1"
|
||||
asset_name="$2"
|
||||
curl -fsS \
|
||||
-H "Authorization: token ${FORGEJO_TOKEN}" \
|
||||
-H "Content-Type: application/octet-stream" \
|
||||
--data-binary @"${asset_path}" \
|
||||
"${api_base}/releases/${RELEASE_ID}/assets?name=${asset_name}"
|
||||
}
|
||||
|
||||
upload_asset "${windows_exe}" "CatalogLite-win-x64-${GITHUB_REF_NAME}-${short_sha}.exe"
|
||||
upload_asset "${linux_archive}" "${linux_archive}"
|
||||
Loading…
Add table
Add a link
Reference in a new issue