-
Notifications
You must be signed in to change notification settings - Fork 0
99 lines (84 loc) · 2.97 KB
/
version-check-release.yml
File metadata and controls
99 lines (84 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
name: Version Check and Release
on:
push:
branches:
- main
paths:
- 'setup.py'
jobs:
check-version-and-release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Extract version from setup.py
id: extract_version
run: |
VERSION=$(grep -oP "version=[\"']\K[^\"']+" setup.py)
echo "Current version: $VERSION"
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Get latest release
id: latest_release
uses: pozetroninc/github-action-get-latest-release@master
with:
repository: ${{ github.repository }}
excludes: prerelease, draft
continue-on-error: true
- name: Compare versions
id: compare_versions
run: |
LATEST_VERSION="${{ steps.latest_release.outputs.release }}"
LATEST_VERSION=${LATEST_VERSION#v}
echo "Latest released version: $LATEST_VERSION"
echo "Current setup.py version: $VERSION"
if [ -z "$LATEST_VERSION" ] || [ "$LATEST_VERSION" != "$VERSION" ]; then
echo "NEW_RELEASE=true" >> $GITHUB_ENV
else
echo "NEW_RELEASE=false" >> $GITHUB_ENV
fi
- name: Generate release notes
if: env.NEW_RELEASE == 'true'
id: generate_notes
uses: actions/github-script@v6
with:
script: |
const { data: commits } = await github.rest.repos.listCommits({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 10
});
let releaseNotes = "## What's Changed\n\n";
commits.forEach(commit => {
releaseNotes += `* ${commit.commit.message} by @${commit.author ? commit.author.login : 'unknown'}\n`;
});
return releaseNotes;
- name: Configure Git
if: env.NEW_RELEASE == 'true'
run: |
git config user.name "GitHub Actions Bot"
git config user.email "actions@github.com"
- name: Create and push tag
if: env.NEW_RELEASE == 'true'
run: |
TAG_NAME="v${{ env.VERSION }}"
echo "Creating new tag: $TAG_NAME"
git tag $TAG_NAME
git push https://${{ secrets.PAT_GITHUB }}@github.com/${{ github.repository }} $TAG_NAME
- name: Create Release
if: env.NEW_RELEASE == 'true'
uses: ncipollo/release-action@v1
with:
tag: v${{ env.VERSION }}
name: Release v${{ env.VERSION }}
body: ${{ steps.generate_notes.outputs.result }}
draft: false
prerelease: false
token: ${{ secrets.GITHUB_TOKEN }}