Skip to content

Commit 3861f78

Browse files
authored
Create releaser.yml
1 parent e5ca21c commit 3861f78

File tree

1 file changed

+176
-0
lines changed

1 file changed

+176
-0
lines changed

.github/workflows/releaser.yml

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
name: Auto Releaser By MicroResearch Corporation
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: '0 0 * * *' # Daily at 00:00 UTC
7+
8+
permissions:
9+
contents: write
10+
11+
concurrency:
12+
group: auto-release
13+
cancel-in-progress: false
14+
15+
jobs:
16+
auto-release:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
# -------------------------------------------------
21+
# 1. Checkout repository (full history required)
22+
# -------------------------------------------------
23+
- name: Checkout repository
24+
uses: actions/checkout@v4
25+
with:
26+
fetch-depth: 0
27+
28+
# -------------------------------------------------
29+
# 2. Get latest release info safely
30+
# -------------------------------------------------
31+
- name: Get latest release
32+
id: latest
33+
uses: actions/github-script@v7
34+
with:
35+
script: |
36+
try {
37+
const r = await github.rest.repos.getLatestRelease({
38+
owner: context.repo.owner,
39+
repo: context.repo.repo
40+
});
41+
core.setOutput('tag', r.data.tag_name);
42+
core.setOutput('published_at', r.data.published_at);
43+
} catch {
44+
core.setOutput('tag', '');
45+
core.setOutput('published_at', '');
46+
}
47+
48+
# -------------------------------------------------
49+
# 3. Decide whether a release should run (daily)
50+
# -------------------------------------------------
51+
- name: Decide release
52+
id: decide
53+
run: |
54+
DATE=$(date -u +'%Y.%m.%d')
55+
echo "DATE=$DATE" >> $GITHUB_ENV
56+
57+
if [ -z "${{ steps.latest.outputs.published_at }}" ]; then
58+
echo "release=true" >> $GITHUB_OUTPUT
59+
exit 0
60+
fi
61+
62+
LAST=$(date -d "${{ steps.latest.outputs.published_at }}" +%s)
63+
NOW=$(date +%s)
64+
DAYS=$(( (NOW - LAST) / 86400 ))
65+
66+
if [ "$DAYS" -ge 1 ]; then
67+
echo "release=true" >> $GITHUB_OUTPUT
68+
else
69+
echo "release=false" >> $GITHUB_OUTPUT
70+
fi
71+
72+
# -------------------------------------------------
73+
# 4. Prevent duplicate tag creation
74+
# -------------------------------------------------
75+
- name: Check if tag exists
76+
id: tagcheck
77+
if: steps.decide.outputs.release == 'true'
78+
run: |
79+
TAG="v${DATE}"
80+
if git rev-parse "$TAG" >/dev/null 2>&1; then
81+
echo "exists=true" >> $GITHUB_OUTPUT
82+
else
83+
echo "exists=false" >> $GITHUB_OUTPUT
84+
fi
85+
86+
# -------------------------------------------------
87+
# 5. Build official Full Changelog URL
88+
# -------------------------------------------------
89+
- name: Build changelog URL
90+
if: |
91+
steps.decide.outputs.release == 'true' &&
92+
steps.tagcheck.outputs.exists == 'false'
93+
run: |
94+
REPO_URL="https://github.com/${{ github.repository }}"
95+
TODAY_TAG="v${DATE}"
96+
97+
if [ -n "${{ steps.latest.outputs.tag }}" ]; then
98+
CHANGELOG_URL="$REPO_URL/compare/${{ steps.latest.outputs.tag }}...$TODAY_TAG"
99+
else
100+
CHANGELOG_URL="$REPO_URL/commits/main"
101+
fi
102+
103+
echo "CHANGELOG_URL=$CHANGELOG_URL" >> $GITHUB_ENV
104+
105+
# -------------------------------------------------
106+
# 6. Prepare release package
107+
# -------------------------------------------------
108+
- name: Prepare files
109+
if: |
110+
steps.decide.outputs.release == 'true' &&
111+
steps.tagcheck.outputs.exists == 'false'
112+
run: |
113+
rm -rf release
114+
mkdir release
115+
rsync -a \
116+
--exclude='.git' \
117+
--exclude='.github' \
118+
--exclude='.vscode' \
119+
--exclude='.gitignore' \
120+
--exclude='package.json' \
121+
--exclude='Structure.md' \
122+
./ release/
123+
124+
# -------------------------------------------------
125+
# 7. Zip package
126+
# -------------------------------------------------
127+
- name: Create ZIP
128+
if: |
129+
steps.decide.outputs.release == 'true' &&
130+
steps.tagcheck.outputs.exists == 'false'
131+
run: |
132+
ZIP="release_${DATE}.zip"
133+
zip -qr "$ZIP" release
134+
echo "ZIP=$ZIP" >> $GITHUB_ENV
135+
136+
# -------------------------------------------------
137+
# 8. Build final release notes
138+
# -------------------------------------------------
139+
- name: Build release notes
140+
if: |
141+
steps.decide.outputs.release == 'true' &&
142+
steps.tagcheck.outputs.exists == 'false'
143+
run: |
144+
cat <<EOF > notes.txt
145+
Release v${DATE}
146+
147+
Author: M Ramzan Ch
148+
Company: MicroResearch Corporation
149+
Released By: MR Intelligence
150+
Published By: Pro Badney
151+
152+
────────────────────────
153+
Full Changelog
154+
────────────────────────
155+
${CHANGELOG_URL}
156+
EOF
157+
158+
echo "NOTES<<EOF" >> $GITHUB_ENV
159+
cat notes.txt >> $GITHUB_ENV
160+
echo "EOF" >> $GITHUB_ENV
161+
162+
# -------------------------------------------------
163+
# 9. Publish GitHub release
164+
# -------------------------------------------------
165+
- name: Publish release
166+
if: |
167+
steps.decide.outputs.release == 'true' &&
168+
steps.tagcheck.outputs.exists == 'false'
169+
uses: ncipollo/release-action@v1
170+
with:
171+
tag: v${{ env.DATE }}
172+
name: v${{ env.DATE }}
173+
body: ${{ env.NOTES }}
174+
files: ${{ env.ZIP }}
175+
draft: false
176+
prerelease: false

0 commit comments

Comments
 (0)