mod flow - rel 5 #10
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: Auto Releaser | |
| on: | |
| push: | |
| branches: | |
| - "**" # all branches | |
| tags: | |
| - "v*" # all tags starting with v | |
| permissions: | |
| contents: write | |
| pull-requests: read | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Detect previous tag | |
| id: prev_tag | |
| run: | | |
| prev_tag=$(git describe --tags --abbrev=0 $(git rev-list --tags --skip=1 --max-count=1) 2>/dev/null || echo "none") | |
| echo "previous_tag=$prev_tag" >> $GITHUB_OUTPUT | |
| - name: Generate changelog | |
| id: changelog | |
| run: | | |
| if [ "${{ steps.prev_tag.outputs.previous_tag }}" != "none" ]; then | |
| commit_range="${{ steps.prev_tag.outputs.previous_tag }}..HEAD" | |
| else | |
| commit_range="HEAD~10..HEAD" | |
| fi | |
| commit_count=$(git rev-list --count $commit_range) | |
| echo "commit_count=$commit_count" >> $GITHUB_OUTPUT | |
| # Generate changelog and save to file | |
| { | |
| echo "## 📝 Changelog" | |
| echo "" | |
| echo "| Commit | Message | Author | Date |" | |
| echo "| ------ | ------- | ------ | ---- |" | |
| git log $commit_range \ | |
| --pretty=format:"| [%h](https://github.com/${{ github.repository }}/commit/%H) | %s | %an | %ad |" \ | |
| --date=short | |
| } > changelog.md | |
| - name: Calculate Lines of Code | |
| id: loc | |
| run: | | |
| # Install cloc for counting lines of code | |
| sudo apt-get install -y cloc | |
| # Count lines in /server and /client | |
| server_loc=$(cloc server --quiet --exclude-dir=node_modules --json 2>/dev/null | jq '.SUM.code // 0' 2>/dev/null || echo "0") | |
| client_loc=$(cloc client --quiet --exclude-dir=node_modules --json 2>/dev/null | jq '.SUM.code // 0' 2>/dev/null || echo "0") | |
| # Count total lines for the repo | |
| total_loc=$(cloc . --quiet --exclude-dir=node_modules --json 2>/dev/null | jq '.SUM.code // 0' 2>/dev/null || echo "0") | |
| # Calculate "others" as total - server - client | |
| others_loc=$((total_loc - server_loc - client_loc)) | |
| echo "server_loc=$server_loc" >> $GITHUB_OUTPUT | |
| echo "client_loc=$client_loc" >> $GITHUB_OUTPUT | |
| echo "others_loc=$others_loc" >> $GITHUB_OUTPUT | |
| echo "total_loc=$total_loc" >> $GITHUB_OUTPUT | |
| - name: Set release name & tag | |
| id: set_names | |
| run: | | |
| if [[ "${GITHUB_REF}" == refs/tags/* ]]; then | |
| tag_name="${GITHUB_REF#refs/tags/}" | |
| release_name="$tag_name" | |
| else | |
| branch="${GITHUB_REF#refs/heads/}" | |
| short_sha=$(git rev-parse --short HEAD) | |
| tag_name="snapshot-${branch}-${short_sha}" | |
| release_name="Snapshot - ${branch}" | |
| fi | |
| echo "tag_name=$tag_name" >> $GITHUB_OUTPUT | |
| echo "release_name=$release_name" >> $GITHUB_OUTPUT | |
| - name: Create release notes | |
| run: | | |
| cat > release_notes.md << 'NOTES_EOF' | |
| ## 📦 Release Information | |
| **Tag/Name:** `${{ steps.set_names.outputs.tag_name }}` | |
| **Date:** $(date -u +"%Y-%m-%d %H:%M:%S UTC") | |
| **Author:** ${{ github.actor }} | |
| **Repository:** [${{ github.repository }}](https://github.com/${{ github.repository }}) | |
| **Previous Tag:** `${{ steps.prev_tag.outputs.previous_tag }}` | |
| **Commit Range:** `${{ steps.prev_tag.outputs.previous_tag }}..${{ github.ref_name }}` | |
| **Number of Commits:** `${{ steps.changelog.outputs.commit_count }}` | |
| **Branch:** `${{ github.ref_name }}` | |
| ### 📊 Lines of Code | |
| | Section | LOC | | |
| |----------|-----| | |
| | Server | `${{ steps.loc.outputs.server_loc }}` | | |
| | Client | `${{ steps.loc.outputs.client_loc }}` | | |
| | Others | `${{ steps.loc.outputs.others_loc }}` | | |
| | **Total**| `${{ steps.loc.outputs.total_loc }}` | | |
| --- | |
| NOTES_EOF | |
| cat changelog.md >> release_notes.md | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: ${{ steps.set_names.outputs.tag_name }} | |
| name: ${{ steps.set_names.outputs.release_name }} | |
| body_path: release_notes.md | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |