Skip to content

Commit 68be0b2

Browse files
committed
add release from issue
1 parent a425c93 commit 68be0b2

2 files changed

Lines changed: 93 additions & 1 deletion

File tree

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: Release from Issue
2+
3+
on:
4+
issues:
5+
types: [opened]
6+
7+
jobs:
8+
validate:
9+
if: startsWith(github.event.issue.title, 'release ') || startsWith(github.event.issue.title, 'Release ')
10+
runs-on: ubuntu-latest
11+
outputs:
12+
version: ${{ steps.extract.outputs.VERSION }}
13+
should_proceed: ${{ steps.validate.outputs.should_proceed }}
14+
steps:
15+
- name: Extract version
16+
id: extract
17+
run: |
18+
TITLE="${{ github.event.issue.title }}"
19+
VERSION=$(echo "$TITLE" | grep -oP '(?<=[Rr]elease )v?\K\d+\.\d+\.\d+')
20+
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
21+
22+
- name: Validate version
23+
id: validate
24+
run: |
25+
VERSION="${{ steps.extract.outputs.VERSION }}"
26+
27+
if git ls-remote --tags origin | grep -q "refs/tags/v$VERSION"; then
28+
echo "Tag v$VERSION already exists!"
29+
echo "should_proceed=false" >> $GITHUB_OUTPUT
30+
exit 0
31+
fi
32+
33+
LATEST=$(git ls-remote --tags origin | grep -oP 'refs/tags/v\K\d+\.\d+\.\d+$' | sort -V | tail -1)
34+
if [ -n "$LATEST" ] && [ "$(printf '%s\n%s' "$LATEST" "$VERSION" | sort -V | tail -1)" != "$VERSION" ]; then
35+
echo "Version v$VERSION is not newer than latest v$LATEST!"
36+
echo "should_proceed=false" >> $GITHUB_OUTPUT
37+
exit 0
38+
fi
39+
40+
echo "should_proceed=true" >> $GITHUB_OUTPUT
41+
continue-on-error: true
42+
43+
release:
44+
needs: validate
45+
if: needs.validate.outputs.should_proceed == 'true'
46+
runs-on: ubuntu-latest
47+
permissions:
48+
contents: write
49+
issues: write
50+
51+
steps:
52+
- uses: actions/checkout@v4
53+
54+
- name: Update version in README
55+
run: |
56+
VERSION="${{ needs.validate.outputs.version }}"
57+
sed -i "/Latest version:/s/\[[0-9.]\+\]/[${VERSION}]/" README.md
58+
59+
- name: Commit and push
60+
run: |
61+
git config user.name "github-actions[bot]"
62+
git config user.email "github-actions[bot]@users.noreply.github.com"
63+
git add .
64+
git commit -m "Release v${{ needs.validate.outputs.version }}"
65+
git push
66+
67+
- name: Create tag
68+
run: |
69+
git tag v${{ needs.validate.outputs.version }}
70+
git push origin v${{ needs.validate.outputs.version }}
71+
72+
- name: Success comment
73+
uses: actions/github-script@v7
74+
with:
75+
script: |
76+
const version = '${{ needs.validate.outputs.version }}';
77+
const releaseUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/releases/tag/v${version}`;
78+
79+
await github.rest.issues.createComment({
80+
owner: context.repo.owner,
81+
repo: context.repo.repo,
82+
issue_number: context.issue.number,
83+
body: `✅ **Release v${version} completed!**\n\n- 📝 Version bumped in README\n- 🏷️ Tag \`v${version}\` created\n- 🚀 Release: ${releaseUrl}`
84+
});
85+
86+
await github.rest.issues.update({
87+
owner: context.repo.owner,
88+
repo: context.repo.repo,
89+
issue_number: context.issue.number,
90+
state: 'closed'
91+
});

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
Attila Szabo & Neil Ostlund *Modern Quantum Chemistry: Introduction to Advanced Electronic Structure Theory* 中文翻译。重新绘制了所有插图。
44

5-
pdf请到Release下载,最新版本:[0.2.9](https://github.com/Mulliken/szaboqc/releases/download/v0.2.9/szabo_zh-v0.2.9.pdf)
5+
pdf请到Release下载。
6+
Latest version: [0.2.9](https://github.com/Mulliken/szaboqc/releases/latest)
67

78
## 手动编译
89

0 commit comments

Comments
 (0)