This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
name: Build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
|
||||
concurrency:
|
||||
group: build-${{ gitea.ref }}
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
# build.yaml is the source of truth for the plugin version.
|
||||
# A version without a matching tag on main gets released.
|
||||
- name: Read version
|
||||
id: version
|
||||
run: |
|
||||
version="$(sed -n 's/^version:[[:space:]]*"\{0,1\}\([0-9][0-9.]*\)"\{0,1\}[[:space:]]*$/\1/p' build.yaml)"
|
||||
if [ -z "$version" ]; then
|
||||
echo "::error file=build.yaml::could not read the version"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
props="$(sed -n 's:.*<Version>\(.*\)</Version>.*:\1:p' Directory.Build.props)"
|
||||
if [ "$props" != "$version" ]; then
|
||||
echo "::error::build.yaml says $version but Directory.Build.props says $props"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
tag="v$version"
|
||||
release=false
|
||||
if [ "$GITHUB_EVENT_NAME" != "pull_request" ] && [ "$GITHUB_REF" = "refs/heads/main" ]; then
|
||||
if [ -z "$(git ls-remote --tags origin "refs/tags/$tag")" ]; then
|
||||
release=true
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "version=$version" >> "$GITHUB_OUTPUT"
|
||||
echo "tag=$tag" >> "$GITHUB_OUTPUT"
|
||||
echo "release=$release" >> "$GITHUB_OUTPUT"
|
||||
echo "Version $version, tag $tag, release: $release"
|
||||
|
||||
- uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: 9.0.x
|
||||
|
||||
- name: Build
|
||||
run: dotnet build -c Release
|
||||
|
||||
- name: Test
|
||||
run: dotnet test -c Release --no-build
|
||||
|
||||
- uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.12'
|
||||
|
||||
- name: Package
|
||||
run: |
|
||||
pip install jprm
|
||||
mkdir -p artifacts
|
||||
jprm plugin build . --output artifacts --version "${{ steps.version.outputs.version }}"
|
||||
ls -l artifacts
|
||||
|
||||
# The repository manifest travels with the releases: take the one from the
|
||||
# latest release, add this version, and publish it again as an asset.
|
||||
- name: Update repository manifest
|
||||
if: steps.version.outputs.release == 'true'
|
||||
env:
|
||||
TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
TAG: ${{ steps.version.outputs.tag }}
|
||||
run: |
|
||||
api="$GITHUB_API_URL/repos/$GITHUB_REPOSITORY"
|
||||
mkdir -p repo
|
||||
previous="$(curl -fsS -H "Authorization: token $TOKEN" "$api/releases/latest" 2>/dev/null \
|
||||
| python3 -c 'import json,sys; print(next((a["browser_download_url"] for a in json.load(sys.stdin).get("assets", []) if a["name"] == "manifest.json"), ""))' 2>/dev/null || true)"
|
||||
if [ -n "$previous" ] && curl -fsSL -H "Authorization: token $TOKEN" -o repo/manifest.json "$previous"; then
|
||||
echo "Continuing the manifest of the latest release"
|
||||
else
|
||||
rm -f repo/manifest.json
|
||||
jprm repo init repo
|
||||
fi
|
||||
|
||||
zip="$(ls artifacts/*.zip)"
|
||||
jprm repo add \
|
||||
--plugin-url "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/download/$TAG/$(basename "$zip")" \
|
||||
repo "$zip"
|
||||
cp repo/manifest.json artifacts/manifest.json
|
||||
cat artifacts/manifest.json
|
||||
|
||||
- name: Create tag and release
|
||||
if: steps.version.outputs.release == 'true'
|
||||
env:
|
||||
TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
TAG: ${{ steps.version.outputs.tag }}
|
||||
run: |
|
||||
api="$GITHUB_API_URL/repos/$GITHUB_REPOSITORY"
|
||||
sed -n '/^changelog:/,$p' build.yaml | sed '1d; s/^ //' > notes.md
|
||||
|
||||
python3 - > release.json <<'PY'
|
||||
import json, os
|
||||
tag = os.environ["TAG"]
|
||||
print(json.dumps({
|
||||
"tag_name": tag,
|
||||
"target_commitish": os.environ["GITHUB_SHA"],
|
||||
"name": "Herald " + tag[1:],
|
||||
"body": open("notes.md", encoding="utf-8").read(),
|
||||
}))
|
||||
PY
|
||||
|
||||
id="$(curl -fsS -X POST -H "Authorization: token $TOKEN" -H "Content-Type: application/json" \
|
||||
--data @release.json "$api/releases" | python3 -c 'import json,sys; print(json.load(sys.stdin)["id"])')"
|
||||
|
||||
for file in artifacts/*.zip artifacts/manifest.json; do
|
||||
curl -fsS -X POST -H "Authorization: token $TOKEN" \
|
||||
-F "attachment=@$file" "$api/releases/$id/assets?name=$(basename "$file")" > /dev/null
|
||||
echo "Attached $(basename "$file")"
|
||||
done
|
||||
Reference in New Issue
Block a user