🔄 Update GitHub workflows and configuration #4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release (Descriptor) | |
| on: | |
| push: | |
| paths: | |
| - release.md | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| actions: read | |
| packages: read | |
| concurrency: | |
| group: release-descriptor | |
| cancel-in-progress: true | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Parse version | |
| id: version | |
| run: | | |
| set -euo pipefail | |
| VERSION_LINE="$(grep -E '^[Vv]ersion:' release.md || true)" | |
| if [ -z "${VERSION_LINE}" ]; then echo "skip=true" >> "$GITHUB_OUTPUT"; exit 0; fi | |
| VERSION="$(echo "${VERSION_LINE}" | cut -d':' -f2 | tr -d '[:space:]')" | |
| if ! echo "${VERSION}" | grep -Eq '^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$'; then echo "skip=true" >> "$GITHUB_OUTPUT"; exit 0; fi | |
| git fetch --tags --quiet | |
| if git rev-parse -q --verify "refs/tags/${VERSION}" >/dev/null; then echo "skip=true" >> "$GITHUB_OUTPUT"; echo "version=${VERSION}" >> "$GITHUB_OUTPUT"; exit 0; fi | |
| echo "version=${VERSION}" >> "$GITHUB_OUTPUT" | |
| echo "skip=false" >> "$GITHUB_OUTPUT" | |
| - name: Stop (skip) | |
| if: steps.version.outputs.skip == 'true' | |
| run: echo "Skipping release - no new version." | |
| - name: Build archives + diff | |
| if: steps.version.outputs.skip != 'true' | |
| run: | | |
| set -euo pipefail | |
| mkdir -p release_out | |
| zip -r release_out/Nerdy-RMMScripts-Windows.zip Windows -x "*/.git/*" | |
| zip -r release_out/Nerdy-RMMScripts-Linux.zip Linux -x "*/.git/*" | |
| PREV="$(git tag --sort=-creatordate | grep -v "^${{ steps.version.outputs.version }}$" | grep '^v' | head -1 || true)" | |
| if [ -n "${PREV}" ]; then git diff --name-status "${PREV}"...HEAD > release_out/diff.txt; else git diff --name-status HEAD > release_out/diff.txt; fi | |
| A=$(grep '^A' release_out/diff.txt | wc -l | tr -d ' ' || true) | |
| M=$(grep '^M' release_out/diff.txt | wc -l | tr -d ' ' || true) | |
| D=$(grep '^D' release_out/diff.txt | wc -l | tr -d ' ' || true) | |
| R=$(grep '^R' release_out/diff.txt | wc -l | tr -d ' ' || true) | |
| { | |
| echo "## 🚀 Release ${{ steps.version.outputs.version }}" | |
| [ -n "${PREV}" ] && echo "Previous Tag: ${PREV}" || echo "Initial Release" | |
| echo | |
| echo "### 📊 Changes" | |
| echo "🆕 Added: ${A} | ✏️ Modified: ${M} | 🗑️ Deleted: ${D} | 🔁 Renamed: ${R}" | |
| echo | |
| echo "### 📄 Files" | |
| if [ -s release_out/diff.txt ]; then | |
| echo '| Status | File |' | |
| echo '|--------|------|' | |
| awk '{c=$1;f=$2;e=(c=="A"?"🆕":c=="M"?"✏️":c=="D"?"🗑️":c=="R"?"🔁":"📄");printf("| %s | %s |\n",e,f);}' release_out/diff.txt | |
| else | |
| echo "_No changes_" | |
| fi | |
| echo | |
| echo "### 📦 Archives" | |
| echo "- Nerdy-RMMScripts-Windows.zip" | |
| echo "- Nerdy-RMMScripts-Linux.zip" | |
| } > release_out/body.md | |
| sha256sum release_out/*.zip > release_out/SHA256SUMS.txt | |
| - name: Create tag | |
| if: steps.version.outputs.skip != 'true' | |
| run: | | |
| set -euo pipefail | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git tag "${{ steps.version.outputs.version }}" | |
| git push origin "${{ steps.version.outputs.version }}" | |
| - name: Publish release | |
| if: steps.version.outputs.skip != 'true' | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: ${{ steps.version.outputs.version }} | |
| name: ${{ steps.version.outputs.version }} | |
| body_path: release_out/body.md | |
| files: | | |
| release_out/Nerdy-RMMScripts-Windows.zip | |
| release_out/Nerdy-RMMScripts-Linux.zip | |
| release_out/SHA256SUMS.txt | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |