A push to main whose build.yaml version has no tag yet creates the tag and a release with the plugin zip and an updated repository manifest.
128 lines
3.8 KiB
YAML
128 lines
3.8 KiB
YAML
name: Build
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
pull_request:
|
|
workflow_dispatch:
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
concurrency:
|
|
group: build-${{ github.ref }}
|
|
cancel-in-progress: false
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
version: ${{ steps.version.outputs.version }}
|
|
tag: ${{ steps.version.outputs.tag }}
|
|
release: ${{ steps.version.outputs.release }}
|
|
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:
|
|
GH_TOKEN: ${{ github.token }}
|
|
TAG: ${{ steps.version.outputs.tag }}
|
|
run: |
|
|
mkdir -p repo
|
|
if ! gh release download --repo "$GITHUB_REPOSITORY" --pattern manifest.json --dir repo 2>/dev/null; then
|
|
jprm repo init repo
|
|
fi
|
|
zip="$(ls artifacts/*.zip)"
|
|
jprm repo add \
|
|
--plugin-url "https://github.com/$GITHUB_REPOSITORY/releases/download/$TAG/$(basename "$zip")" \
|
|
repo "$zip"
|
|
cp repo/manifest.json artifacts/manifest.json
|
|
cat artifacts/manifest.json
|
|
|
|
- uses: actions/upload-artifact@v4
|
|
with:
|
|
name: plugin
|
|
path: |
|
|
artifacts/*.zip
|
|
artifacts/manifest.json
|
|
if-no-files-found: error
|
|
|
|
release:
|
|
if: needs.build.outputs.release == 'true'
|
|
needs: build
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: write
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- uses: actions/download-artifact@v4
|
|
with:
|
|
name: plugin
|
|
path: artifacts
|
|
|
|
- name: Create tag and release
|
|
env:
|
|
GH_TOKEN: ${{ github.token }}
|
|
TAG: ${{ needs.build.outputs.tag }}
|
|
run: |
|
|
sed -n '/^changelog:/,$p' build.yaml | sed '1d; s/^ //' > notes.md
|
|
gh release create "$TAG" artifacts/*.zip artifacts/manifest.json \
|
|
--target "$GITHUB_SHA" \
|
|
--title "Herald ${TAG#v}" \
|
|
--notes-file notes.md
|