grub-basket_SP/.github/workflows/release.yml

75 lines
2.2 KiB
YAML

name: Release
on:
push:
branches: [main]
paths: ['manifest.json']
workflow_dispatch:
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Read version from manifest.json
id: version
run: echo "version=$(jq -r .version manifest.json)" >> "$GITHUB_OUTPUT"
- name: Check if tag already exists
id: check
run: |
if git rev-parse "${{ steps.version.outputs.version }}" >/dev/null 2>&1; then
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Generate release notes
if: steps.check.outputs.exists == 'false'
id: notes
env:
VERSION: ${{ steps.version.outputs.version }}
run: |
NOTES_FILE="release-notes/${VERSION}.md"
{
echo "notes<<EOF"
if [ -f "$NOTES_FILE" ]; then
cat "$NOTES_FILE"
else
PREV_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -z "$PREV_TAG" ]; then
LOG=$(git log --pretty=format:'- %s')
else
LOG=$(git log "$PREV_TAG"..HEAD --pretty=format:'- %s')
fi
echo "## Changes since ${PREV_TAG:-the beginning}"
echo ""
echo "$LOG"
fi
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Create and push tag
if: steps.check.outputs.exists == 'false'
env:
TAG: ${{ steps.version.outputs.version }}
run: |
git tag "$TAG"
git push origin "$TAG"
- name: Create release and upload plugin assets
if: steps.check.outputs.exists == 'false'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ steps.version.outputs.version }}
NOTES: ${{ steps.notes.outputs.notes }}
run: |
gh release view "$TAG" >/dev/null 2>&1 \
|| gh release create "$TAG" --title "$TAG" --notes "$NOTES"
gh release upload "$TAG" main.js manifest.json styles.css --clobber