Skip to content

Commit c20d37f

Browse files
committed
update yaml
1 parent 378fa09 commit c20d37f

File tree

1 file changed

+43
-23
lines changed

1 file changed

+43
-23
lines changed

.github/workflows/automatic-github-release.yml

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,45 +13,65 @@ jobs:
1313
with:
1414
fetch-depth: 0 # Important to fetch all tags
1515

16-
- name: Get Latest Tag
17-
id: get_latest_tag
16+
- name: Get Version from mod.json
17+
id: get_version
1818
run: |
19-
LATEST_TAG=$(git describe --abbrev=0 --tags 2>/dev/null || echo "")
20-
if [[ -z "$LATEST_TAG" ]]; then
21-
echo "No tags found. This seems to be the first release."
22-
echo "PREVIOUS_VERSION=0.0.0" >> $GITHUB_OUTPUT # Set a default
23-
echo "IS_INITIAL_RELEASE=true" >> $GITHUB_OUTPUT
24-
else
25-
PREVIOUS_VERSION=$(echo $LATEST_TAG | sed 's/^v//')
26-
echo "PREVIOUS_VERSION=$PREVIOUS_VERSION" >> $GITHUB_OUTPUT
27-
echo "IS_INITIAL_RELEASE=false" >> $GITHUB_OUTPUT
28-
fi
19+
VERSION=$(jq -r .version mod.json)
20+
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
2921
30-
- name: Generate Release Notes
31-
id: generate_release_notes
22+
- name: Calculate Release Version and Tag
23+
id: calculate_release_version
3224
run: |
33-
PREVIOUS_TAG="v${{ steps.get_latest_tag.outputs.PREVIOUS_VERSION }}"
34-
IS_INITIAL_RELEASE="${{ steps.get_latest_tag.outputs.IS_INITIAL_RELEASE }}"
25+
VERSION="${{ steps.get_version.outputs.VERSION }}"
26+
27+
# Calculate the release version (one less than current version in mod.json)
28+
# This uses awk to handle decimal subtraction correctly
29+
RELEASE_VERSION=$(echo "$VERSION - 0.001" | awk '{printf "%.3f", $1}') # Adjust precision as needed
30+
RELEASE_TAG="v$RELEASE_VERSION"
31+
32+
echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_OUTPUT
33+
echo "RELEASE_TAG=$RELEASE_TAG" >> $GITHUB_OUTPUT
3534
36-
if [[ "$IS_INITIAL_RELEASE" == "true" ]]; then
37-
echo "No previous tag found. Creating initial release notes."
38-
RELEASE_NOTES="Initial release."
35+
- name: Check if Tag Exists
36+
id: check_tag_exists
37+
run: |
38+
RELEASE_TAG="${{ steps.calculate_release_version.outputs.RELEASE_TAG }}"
39+
git fetch --tags
40+
if git rev-parse --verify "refs/tags/$RELEASE_TAG" >/dev/null 2>&1; then
41+
echo "TAG_EXISTS=true" >> $GITHUB_OUTPUT
42+
echo "Tag $RELEASE_TAG already exists. Skipping release creation."
3943
else
40-
echo "Previous tag is $PREVIOUS_TAG"
41-
RELEASE_NOTES=$(git log $PREVIOUS_TAG..HEAD --pretty=format:"- %s")
44+
echo "TAG_EXISTS=false" >> $GITHUB_OUTPUT
45+
echo "Tag $RELEASE_TAG does not exist. Proceeding with release creation."
4246
fi
4347
48+
- name: Generate Release Notes
49+
id: generate_release_notes
50+
if: steps.check_tag_exists.outputs.TAG_EXISTS == 'false'
51+
run: |
52+
RELEASE_TAG="${{ steps.calculate_release_version.outputs.RELEASE_TAG }}"
53+
# Using git log to get commits since the calculated tag
54+
RELEASE_NOTES=$(git log $RELEASE_TAG..HEAD --pretty=format:"- %s")
4455
echo "RELEASE_NOTES<<EOF" >> $GITHUB_OUTPUT
4556
echo "$RELEASE_NOTES" >> $GITHUB_OUTPUT
4657
echo "EOF" >> $GITHUB_OUTPUT
4758
4859
- name: Create Release
4960
uses: actions/create-release@v1
61+
if: steps.check_tag_exists.outputs.TAG_EXISTS == 'false'
5062
env:
5163
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5264
with:
53-
tag_name: v${{ steps.get_latest_tag.outputs.PREVIOUS_VERSION }}
54-
release_name: Release v${{ steps.get_latest_tag.outputs.PREVIOUS_VERSION }}
65+
tag_name: ${{ steps.calculate_release_version.outputs.RELEASE_TAG }}
66+
release_name: Release ${{ steps.calculate_release_version.outputs.RELEASE_TAG }}
5567
body: ${{ steps.generate_release_notes.outputs.RELEASE_NOTES }}
5668
draft: false
5769
prerelease: false
70+
71+
- name: Create Tag (if it doesn't exist)
72+
if: steps.check_tag_exists.outputs.TAG_EXISTS == 'false'
73+
run: |
74+
RELEASE_TAG="${{ steps.calculate_release_version.outputs.RELEASE_TAG }}"
75+
git tag $RELEASE_TAG
76+
git push origin $RELEASE_TAG
77+
echo "Created tag $RELEASE_TAG"

0 commit comments

Comments
 (0)