Skip to content

Add star history chart to README #28

Add star history chart to README

Add star history chart to README #28

name: Create Release from main
on:
push:
branches:
- main
permissions:
contents: write # needed to create releases
jobs:
release:
runs-on: ubuntu-latest
steps:
# 1️⃣ Checkout the repository
- name: Checkout repository
uses: actions/checkout@v4
# 2️⃣ Extract version from pbs_chunk_checker.py
- name: Read version from pbs_chunk_checker.py
id: version
run: |
VERSION=$(grep '__version__' pbs_chunk_checker.py | head -n1 | sed -E 's/.*"([^"]+)".*/\1/')
if [ -z "$VERSION" ]; then
echo "❌ Version not found in pbs_chunk_checker.py"
exit 1
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Detected version: $VERSION"
# 3️⃣ Check if release for this version already exists
- name: Check if release exists
id: check_release
run: |
VERSION=${{ steps.version.outputs.version }}
EXISTING=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/releases/tags/v${VERSION} \
| jq -r '.id // empty')
if [ -n "$EXISTING" ]; then
echo "exists=true" >> $GITHUB_OUTPUT
echo "✅ Release for v${VERSION} already exists."
else
echo "exists=false" >> $GITHUB_OUTPUT
echo "ℹ️ No release found for v${VERSION}, continuing..."
fi
# 4️⃣ Stop if release already exists
- name: Stop if release already exists
if: steps.check_release.outputs.exists == 'true'
run: echo "Release already exists, skipping." && exit 0
# 5️⃣ (Optional) Copy file to include version for clarity
- name: Copy versioned script
if: steps.check_release.outputs.exists == 'false'
run: |
cp pbs_chunk_checker.py pbs_chunk_checker_v${{ steps.version.outputs.version }}.py
# 6️⃣ Generate release notes including the matching CHANGELOG section
- name: Build release body from CHANGELOG.md
if: steps.check_release.outputs.exists == 'false'
run: |
VERSION=${{ steps.version.outputs.version }}
CLEAN_VER="${VERSION#v}"
echo "🚀 Automated release from main branch " > RELEASE_BODY.md
echo "Version: v${VERSION} " >> RELEASE_BODY.md
echo "Commit: ${{ github.sha }}" >> RELEASE_BODY.md
echo "" >> RELEASE_BODY.md
echo "Changes in v${VERSION}:" >> RELEASE_BODY.md
echo "" >> RELEASE_BODY.md
# Extract the section for this version from CHANGELOG.md
awk -v ver="$CLEAN_VER" '
BEGIN { keep=0 }
$0 ~ ("^- " ver "([ \t]|$)") { keep=1; print; next }
keep && $0 ~ "^- [0-9]" { keep=0 }
keep { print }
' CHANGELOG.md > CHANGELOG_EXTRACT.md || true
if [ ! -s CHANGELOG_EXTRACT.md ]; then
echo "- No specific changelog entry found for v${VERSION}. See CHANGELOG.md." >> RELEASE_BODY.md
else
cat CHANGELOG_EXTRACT.md >> RELEASE_BODY.md
fi
# Cleanup temporary extract file regardless of outcome
rm -f CHANGELOG_EXTRACT.md
# 7️⃣ Create GitHub Release
- name: Create GitHub Release
if: steps.check_release.outputs.exists == 'false'
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.version.outputs.version }}
name: "PBS_Chunk_Checker v${{ steps.version.outputs.version }}"
body_path: RELEASE_BODY.md
files: pbs_chunk_checker_v${{ steps.version.outputs.version }}.py