Auto Releaser By MicroResearch Corporation #61
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 By MicroResearch Corporation | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: '0 0 * * *' # Daily at 00:00 UTC | |
| permissions: | |
| contents: write | |
| concurrency: | |
| group: auto-release | |
| cancel-in-progress: false | |
| jobs: | |
| auto-release: | |
| runs-on: ubuntu-latest | |
| steps: | |
| # ------------------------------------------------- | |
| # 1. Checkout repository (full history required) | |
| # ------------------------------------------------- | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| # ------------------------------------------------- | |
| # 2. Get latest release info safely | |
| # ------------------------------------------------- | |
| - name: Get latest release | |
| id: latest | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| try { | |
| const r = await github.rest.repos.getLatestRelease({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo | |
| }); | |
| core.setOutput('tag', r.data.tag_name); | |
| core.setOutput('published_at', r.data.published_at); | |
| } catch { | |
| core.setOutput('tag', ''); | |
| core.setOutput('published_at', ''); | |
| } | |
| # ------------------------------------------------- | |
| # 3. Decide whether a release should run (daily) | |
| # ------------------------------------------------- | |
| - name: Decide release | |
| id: decide | |
| run: | | |
| DATE=$(date -u +'%Y.%m.%d') | |
| echo "DATE=$DATE" >> $GITHUB_ENV | |
| if [ -z "${{ steps.latest.outputs.published_at }}" ]; then | |
| echo "release=true" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| LAST=$(date -d "${{ steps.latest.outputs.published_at }}" +%s) | |
| NOW=$(date +%s) | |
| DAYS=$(( (NOW - LAST) / 86400 )) | |
| if [ "$DAYS" -ge 1 ]; then | |
| echo "release=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "release=false" >> $GITHUB_OUTPUT | |
| fi | |
| # ------------------------------------------------- | |
| # 4. Prevent duplicate tag creation | |
| # ------------------------------------------------- | |
| - name: Check if tag exists | |
| id: tagcheck | |
| if: steps.decide.outputs.release == 'true' | |
| run: | | |
| TAG="v${DATE}" | |
| if git rev-parse "$TAG" >/dev/null 2>&1; then | |
| echo "exists=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "exists=false" >> $GITHUB_OUTPUT | |
| fi | |
| # ------------------------------------------------- | |
| # 5. Build official Full Changelog URL | |
| # ------------------------------------------------- | |
| - name: Build changelog URL | |
| if: | | |
| steps.decide.outputs.release == 'true' && | |
| steps.tagcheck.outputs.exists == 'false' | |
| run: | | |
| REPO_URL="https://github.com/${{ github.repository }}" | |
| TODAY_TAG="v${DATE}" | |
| if [ -n "${{ steps.latest.outputs.tag }}" ]; then | |
| CHANGELOG_URL="$REPO_URL/compare/${{ steps.latest.outputs.tag }}...$TODAY_TAG" | |
| else | |
| CHANGELOG_URL="$REPO_URL/commits/main" | |
| fi | |
| echo "CHANGELOG_URL=$CHANGELOG_URL" >> $GITHUB_ENV | |
| # ------------------------------------------------- | |
| # 6. Prepare release package | |
| # ------------------------------------------------- | |
| - name: Prepare files | |
| if: | | |
| steps.decide.outputs.release == 'true' && | |
| steps.tagcheck.outputs.exists == 'false' | |
| run: | | |
| rm -rf release | |
| mkdir release | |
| rsync -a \ | |
| --exclude='.git' \ | |
| --exclude='.github' \ | |
| --exclude='.vscode' \ | |
| --exclude='.gitignore' \ | |
| --exclude='package.json' \ | |
| --exclude='Structure.md' \ | |
| ./ release/ | |
| # ------------------------------------------------- | |
| # 7. Zip package | |
| # ------------------------------------------------- | |
| - name: Create ZIP | |
| if: | | |
| steps.decide.outputs.release == 'true' && | |
| steps.tagcheck.outputs.exists == 'false' | |
| run: | | |
| ZIP="release_${DATE}.zip" | |
| zip -qr "$ZIP" release | |
| echo "ZIP=$ZIP" >> $GITHUB_ENV | |
| # ------------------------------------------------- | |
| # 8. Build final release notes | |
| # ------------------------------------------------- | |
| - name: Build release notes | |
| if: | | |
| steps.decide.outputs.release == 'true' && | |
| steps.tagcheck.outputs.exists == 'false' | |
| run: | | |
| cat <<EOF > notes.txt | |
| Release Release→${DATE} | |
| Author: M Ramzan Ch | |
| Company: MicroResearch Corporation | |
| Released By: MR Intelligence | |
| Published By: Pro Badney | |
| ──────────────────────── | |
| Full Changelog | |
| ──────────────────────── | |
| ${CHANGELOG_URL} | |
| EOF | |
| echo "NOTES<<EOF" >> $GITHUB_ENV | |
| cat notes.txt >> $GITHUB_ENV | |
| echo "EOF" >> $GITHUB_ENV | |
| # ------------------------------------------------- | |
| # 9. Publish GitHub release | |
| # ------------------------------------------------- | |
| - name: Publish release | |
| if: | | |
| steps.decide.outputs.release == 'true' && | |
| steps.tagcheck.outputs.exists == 'false' | |
| uses: ncipollo/release-action@v1 | |
| with: | |
| tag: v${{ env.DATE }} | |
| name: v${{ env.DATE }} | |
| body: ${{ env.NOTES }} | |
| files: ${{ env.ZIP }} | |
| draft: false | |
| prerelease: false |