Skip to content

Commit a3e5742

Browse files
committed
update yaml
1 parent c20d37f commit a3e5742

File tree

2 files changed

+62
-27
lines changed

2 files changed

+62
-27
lines changed

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,22 @@ jobs:
2424
run: |
2525
VERSION="${{ steps.get_version.outputs.VERSION }}"
2626
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
27+
# Extract the parts of the version number
28+
MAJOR=$(echo "$VERSION" | cut -d'.' -f1)
29+
MINOR=$(echo "$VERSION" | cut -d'.' -f2)
30+
PATCH=$(echo "$VERSION" | cut -d'.' -f3)
31+
32+
# Calculate the RELEASE version (one less than current version in mod.json)
33+
if [[ "$PATCH" -gt 0 ]]; then
34+
RELEASE_VERSION="$MAJOR.$MINOR.$((PATCH - 1))"
35+
elif [[ "$MINOR" -gt 0 ]]; then
36+
RELEASE_VERSION="$MAJOR.$((MINOR - 1)).99" # Assuming 99 is the last patch version
37+
elif [[ "$MAJOR" -gt 0 ]]; then
38+
RELEASE_VERSION="$((MAJOR - 1)).99.99" # Assuming 99 is the last minor version
39+
else
40+
RELEASE_VERSION="0.0.0" # Or whatever makes sense for your project
41+
fi
42+
3043
RELEASE_TAG="v$RELEASE_VERSION"
3144
3245
echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_OUTPUT
@@ -49,9 +62,10 @@ jobs:
4962
id: generate_release_notes
5063
if: steps.check_tag_exists.outputs.TAG_EXISTS == 'false'
5164
run: |
65+
VERSION="${{ steps.get_version.outputs.VERSION }}"
5266
RELEASE_TAG="${{ steps.calculate_release_version.outputs.RELEASE_TAG }}"
5367
# Using git log to get commits since the calculated tag
54-
RELEASE_NOTES=$(git log $RELEASE_TAG..HEAD --pretty=format:"- %s")
68+
RELEASE_NOTES=$(git log --pretty=format:"- %s" $(git describe --abbrev=0 --tags || echo HEAD) ..HEAD)
5569
echo "RELEASE_NOTES<<EOF" >> $GITHUB_OUTPUT
5670
echo "$RELEASE_NOTES" >> $GITHUB_OUTPUT
5771
echo "EOF" >> $GITHUB_OUTPUT
@@ -71,6 +85,7 @@ jobs:
7185
- name: Create Tag (if it doesn't exist)
7286
if: steps.check_tag_exists.outputs.TAG_EXISTS == 'false'
7387
run: |
88+
VERSION="${{ steps.get_version.outputs.VERSION }}"
7489
RELEASE_TAG="${{ steps.calculate_release_version.outputs.RELEASE_TAG }}"
7590
git tag $RELEASE_TAG
7691
git push origin $RELEASE_TAG

.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)