Skip to content

Commit d5c5b70

Browse files
- Refactored release_draft.yml file content. Improved tag control logic. (#84)
1 parent fc41801 commit d5c5b70

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

.github/workflows/release_draft.yml

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ on:
2323
required: true
2424

2525
jobs:
26-
tag:
26+
check-tag:
2727
runs-on: ubuntu-latest
2828
steps:
29-
- uses: actions/checkout@v4
29+
- uses: actions/checkout@v4.1.1
3030
with:
3131
fetch-depth: 0
3232

@@ -36,7 +36,7 @@ jobs:
3636
script: |
3737
const newTag = core.getInput('tag-name');
3838
const regex = /^v[0-9]+\.[0-9]+\.[0-9]+$/;
39-
39+
4040
if (!regex.test(newTag)) {
4141
core.setFailed('Tag does not match the required format "v[0-9]+.[0-9]+.[0-9]+"');
4242
return;
@@ -55,11 +55,14 @@ jobs:
5555
repo: context.repo.repo,
5656
ref: 'tags/'
5757
});
58-
console.log(`Existing tags: ${refs.map(ref => ref.ref.replace('refs/tags/', '')).join(', ')}`);
5958
60-
const latestTag = refs.sort((a, b) => new Date(b.object.date) - new Date(a.object.date))[0].ref.replace('refs/tags/', '');
61-
console.log(`Latest tag: ${latestTag}`);
59+
if (refs.length === 0) {
60+
// No existing tags, so any new tag is valid
61+
console.log('No existing tags found. Any new tag is considered valid.');
62+
return;
63+
}
6264
65+
const latestTag = refs.sort((a, b) => new Date(b.object.date) - new Date(a.object.date))[0].ref.replace('refs/tags/', '');
6366
const latestVersion = latestTag.replace('v', '').split('.').map(Number);
6467
const newVersion = newTag.replace('v', '').split('.').map(Number);
6568
@@ -75,35 +78,35 @@ jobs:
7578
7679
tag-name: ${{ github.event.inputs.tag-name }}
7780

78-
release:
79-
needs: tag
81+
generate-release-notes:
82+
needs: check-tag
8083
runs-on: ubuntu-latest
8184
steps:
82-
- uses: actions/checkout@v4
85+
- uses: actions/checkout@v4.1.1
8386
with:
8487
fetch-depth: 0
85-
ref: refs/tags/${{ github.event.inputs.tag-name }}
8688

8789
- uses: actions/setup-python@v5.1.1
8890
with:
8991
python-version: '3.11'
9092

91-
- name: Generate release notes
92-
id: release_notes_generator
93+
- name: Generate Release Notes
94+
id: generate_release_notes
9395
uses: AbsaOSS/generate-release-notes@master
9496
env:
9597
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9698
with:
9799
tag-name: ${{ github.event.inputs.tag-name }}
98-
chapters: |
99-
[
100-
{"title": "Breaking Changes 💥", "label": "breaking-change"},
101-
{"title": "New Features 🎉", "label": "feature"},
102-
{"title": "New Features 🎉", "label": "enhancement"},
103-
{"title": "Bugfixes 🛠", "label": "bug"}
104-
]
100+
chapters: '[
101+
{"title": "Breaking Changes 💥", "label": "breaking-change"},
102+
{"title": "New Features 🎉", "label": "enhancement"},
103+
{"title": "New Features 🎉", "label": "feature"},
104+
{"title": "Bugfixes 🛠", "label": "bug"}
105+
]'
106+
verbose: true
105107
warnings: true
106108

109+
107110
- name: Create and Push Tag
108111
uses: actions/github-script@v7
109112
with:
@@ -123,13 +126,13 @@ jobs:
123126
github-token: ${{ secrets.GITHUB_TOKEN }}
124127
tag-name: ${{ github.event.inputs.tag-name }}
125128

126-
- name: Create draft release
129+
- name: Create Draft Release
127130
uses: softprops/action-gh-release@v1
128131
env:
129132
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
130133
with:
131134
name: ${{ github.event.inputs.tag-name }}
132-
body: ${{ steps.release_notes_generator.outputs.release-notes }}
135+
body: ${{ steps.generate_release_notes.outputs.release-notes }}
133136
tag_name: ${{ github.event.inputs.tag-name }}
134137
draft: true
135138
prerelease: false

0 commit comments

Comments
 (0)