name: Release On-Demand on: workflow_dispatch: jobs: build-and-release: runs-on: ubuntu-latest permissions: contents: write steps: - name: Checkout repository uses: actions/checkout@v4 with: fetch-depth: 0 submodules: recursive - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: '20' - name: Setup Python uses: actions/setup-python@v5 with: python-version: '3.x' - name: Extract Version id: version run: | VERSION=$(grep '#define PKGMGR_VERSION' include/version.h | awk '{print $3}' | tr -d '"' | tr -d '\r') if [ -z "$VERSION" ]; then echo "Error: Could not find PKGMGR_VERSION in include/version.h" exit 1 fi echo "Extracted version: $VERSION" echo "tag=v${VERSION}" >> $GITHUB_OUTPUT echo "version=${VERSION}" >> $GITHUB_OUTPUT - name: Check if release exists env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | TAG="${{ steps.version.outputs.tag }}" if gh release view "$TAG" >/dev/null 2>&1; then echo "Release $TAG already exists. Aborting." exit 1 fi echo "Release $TAG does not exist. Proceeding." - name: Build PKG Manager run: | chmod +x build_release.sh ./build_release.sh SHORT_HASH=$(git rev-parse --short HEAD) mv "pkg-manager_v${{ steps.version.outputs.version }}-dev-${SHORT_HASH}.elf" \ "pkg-manager_v${{ steps.version.outputs.version }}.elf" - name: Create Release env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | TAG="${{ steps.version.outputs.tag }}" VERSION="${{ steps.version.outputs.version }}" PREV_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") TAG="$TAG" PREV_TAG="$PREV_TAG" REPOSITORY="${{ github.repository }}" python3 - <<'PY' import os from pathlib import Path tag = os.environ["TAG"] lines = Path("CHANGELOG.md").read_text().splitlines() section = [] found = False for line in lines: if not found: if line.strip() == f"## {tag}": found = True continue if line.startswith("## "): break section.append(line) changelog = "\n".join(section).strip() while changelog.endswith("---"): changelog = changelog[:-3].rstrip() notes = changelog or f"No exact {tag} section found in CHANGELOG.md." previous = os.environ.get("PREV_TAG", "") if previous: notes += f"\n\nFull Changelog: https://github.com/{os.environ['REPOSITORY']}/compare/{previous}...{tag}" Path("release-notes.md").write_text(notes + "\n") PY gh release create "$TAG" \ --title "$TAG" \ --notes-file release-notes.md \ "pkg-manager_v${VERSION}.elf"