-
Notifications
You must be signed in to change notification settings - Fork 138
69 lines (61 loc) · 2.23 KB
/
publish-github-release.yml
File metadata and controls
69 lines (61 loc) · 2.23 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
name: Publish GitHub Release
on:
workflow_call:
inputs:
tag_name:
required: true
type: string
workflow_dispatch:
inputs:
tag_name:
description: 'Tag name for the release (e.g. v1.2.3)'
required: true
type: string
jobs:
publish-release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout Repo
uses: actions/checkout@v4
# Get the date of the latest GitHub release
- name: Get previous release tag
id: previous_release
run: |
PREV_TAG=$(gh release list --limit 1 --json tagName --jq '.[0].tagName')
if [ -z "$PREV_TAG" ]; then
echo "No previous GitHub release found. Cannot generate release notes."
exit 1
fi
echo "tag=$PREV_TAG" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install github-activity
run: pip install github-activity
# Generate release notes since the last release
- name: Generate release notes with github-activity
env:
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
github-activity "$GITHUB_REPOSITORY" --since "${{ steps.previous_release.outputs.tag }}" > release-notes.md
# Remove the title from the release notes
tail -n +2 release-notes.md > release-notes-temp.md && mv release-notes-temp.md release-notes.md
# Create GitHub Release with gh
- name: Create GitHub Release with gh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
TAG="${{ github.event.inputs.tag_name || inputs.tag_name }}"
# Check if the tag already exists
if git ls-remote --tags origin "$TAG" | grep -q "$TAG"; then
echo "Tag $TAG already exists, creating release for existing tag"
gh release create "$TAG" --title "$TAG" --notes-file release-notes.md --verify-tag
else
echo "Error: Tag $TAG does not exist. Please create the tag first before running this workflow."
exit 1
fi