Skip to content

Commit bfe435d

Browse files
committed
workflow adjusted
1 parent 4414c85 commit bfe435d

File tree

1 file changed

+39
-92
lines changed

1 file changed

+39
-92
lines changed

.github/workflows/deploy.yml

Lines changed: 39 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,48 @@
1-
name: Deploy to GitHub
1+
name: Create Release
22

33
on:
44
push:
5-
branches:
6-
- master
75
tags:
8-
- "*"
6+
- '*.*.*' # Triggers on tags like 1.0.0
7+
branches:
8+
- master # Ensures it only runs on the master branch
99

1010
jobs:
11-
tag:
12-
name: Prepare Release
11+
create_release:
1312
runs-on: ubuntu-latest
14-
if: github.event_name == 'push'
1513

1614
steps:
17-
- uses: actions/checkout@v3
18-
with:
19-
fetch-depth: 0
20-
21-
- name: Get latest commit SHA
22-
id: sha
23-
if: github.ref == 'refs/heads/master'
24-
run: echo "::set-output name=sha::$(git rev-parse HEAD)"
25-
26-
- name: Create Tag (if needed)
27-
id: create_tag
28-
if: github.ref == 'refs/heads/master' && !startsWith(github.event.head_commit.message, 'Merge pull request')
29-
run: |
30-
TAG_NAME="v$(date +%Y%m%d%H%M%S)-${{ steps.sha.outputs.sha }}"
31-
git config --global user.name 'GitHub Actions'
32-
git config --global user.email '[email protected]'
33-
git tag -a "$TAG_NAME" -m "Release from master ${{ steps.sha.outputs.sha }}"
34-
git push origin --tags
35-
echo "::set-output name=tag::$TAG_NAME"
36-
37-
- name: Extract Release Notes
38-
id: release_notes
39-
if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/'))
40-
run: |
41-
changelog_section_start="== Changelog =="
42-
current_tag="${{ steps.create_tag.outputs.tag || github.ref_name }}"
43-
readme_file="readme.txt" # Directly set the filename
44-
45-
if [ ! -f "$readme_file" ]; then # Check if the file exists
46-
echo "::error::Readme file not found: $readme_file"
47-
exit 1
48-
fi
49-
echo "Readme file: $readme_file"
50-
51-
version=${current_tag#refs/tags/}
52-
53-
in_changelog=0
54-
capturing_version=0
55-
release_notes=""
56-
57-
while IFS= read -r line; do
58-
if [[ "$line" == "$changelog_section_start" ]]; then
59-
in_changelog=1
60-
continue
61-
fi
62-
63-
if [[ $in_changelog -eq 0 ]]; then
64-
continue
65-
fi
66-
67-
if [[ "$line" =~ ^[0-9]+\.[0-9]+\.[0-9]+ ]]; then
68-
capturing_version=1
69-
if [[ "$line" == "$version" ]]; then
70-
release_notes+="$line\n"
71-
fi
72-
continue
73-
fi
74-
75-
if [[ $capturing_version -eq 1 && "$line" =~ ^[0-9]+\.[0-9]+\.[0-9]+ ]]; then
76-
break
77-
fi
78-
79-
if [[ $capturing_version -eq 1 ]]; then
80-
release_notes+="$line\n"
81-
fi
82-
done < "$readme_file"
83-
84-
if [[ -z "$release_notes" ]]; then
85-
echo "::error::Failed to extract release notes for version $version."
86-
exit 1
87-
fi
88-
89-
echo "Extracted release notes for version $version:"
90-
printf "%b" "$release_notes"
91-
echo "::set-output name=notes::$(printf "%b" "$release_notes")"
92-
93-
- name: Create GitHub Release
94-
uses: softprops/action-gh-release@v2
95-
if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/'))
96-
with:
97-
tag_name: ${{ steps.create_tag.outputs.tag || github.ref_name }}
98-
body: ${{ steps.release_notes.outputs.notes }}
99-
files: ${{github.workspace}}/${{ github.event.repository.name }}.zip
100-
env:
101-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
15+
- name: Checkout repository
16+
uses: actions/checkout@v2
17+
18+
- name: Read version from readme.txt
19+
id: read_version
20+
run: |
21+
VERSION=$(grep -Eo 'Stable tag: [0-9]+\.[0-9]+\.[0-9]+' readme.txt | awk '{print $3}')
22+
echo "plugin_version=$VERSION" >> $GITHUB_ENV
23+
24+
- name: Get latest tag
25+
id: get_latest_tag
26+
run: |
27+
LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1`)
28+
echo "latest_tag=$LATEST_TAG" >> $GITHUB_ENV
29+
30+
- name: Extract Changelog
31+
id: extract_changelog
32+
run: |
33+
START_LINE=$(grep -n "== Changelog ==" readme.txt | cut -d : -f 1)
34+
END_LINE=$(grep -n "= ${{ env.plugin_version }} =" readme.txt | cut -d : -f 1)
35+
sed -n "${START_LINE},${END_LINE}p" readme.txt | sed '1d;$d' > CHANGELOG.txt
36+
echo "changelog=$(cat CHANGELOG.txt)" >> $GITHUB_ENV
37+
38+
- name: Create Release
39+
id: create_release
40+
uses: actions/create-release@v1
41+
env:
42+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43+
with:
44+
tag_name: ${{ env.latest_tag }}
45+
release_name: "Release ${{ env.plugin_version }}"
46+
body: ${{ env.changelog }}
47+
draft: false
48+
prerelease: false

0 commit comments

Comments
 (0)