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:.*\(.*\).*:\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 # manifest.json in the source tree is the plugin repository users install from. # Add this version to it; it is committed back once the release exists. - name: Update repository manifest if: steps.version.outputs.release == 'true' env: TAG: ${{ steps.version.outputs.tag }} run: | mkdir -p repo cp manifest.json repo/manifest.json 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 - name: Commit repository manifest if: steps.version.outputs.release == 'true' env: TOKEN: ${{ secrets.GITEA_TOKEN }} TAG: ${{ steps.version.outputs.tag }} run: | cp artifacts/manifest.json manifest.json if git diff --quiet -- manifest.json; then echo "manifest.json is already up to date" exit 0 fi git config user.name "$GITHUB_ACTOR" git config user.email "$GITHUB_ACTOR@noreply.${GITHUB_SERVER_URL#*://}" git add manifest.json git commit -m "chore: add $TAG to the plugin manifest [skip ci]" git push "${GITHUB_SERVER_URL%%://*}://x-access-token:$TOKEN@${GITHUB_SERVER_URL#*://}/$GITHUB_REPOSITORY.git" HEAD:main