Skip to content

Commit

Permalink
- Refactored release_draft.yml file content. Improved tag control log…
Browse files Browse the repository at this point in the history
…ic. (#84)
  • Loading branch information
miroslavpojer authored Oct 9, 2024
1 parent fc41801 commit d5c5b70
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions .github/workflows/release_draft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ on:
required: true

jobs:
tag:
check-tag:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4.1.1
with:
fetch-depth: 0

Expand All @@ -36,7 +36,7 @@ jobs:
script: |
const newTag = core.getInput('tag-name');
const regex = /^v[0-9]+\.[0-9]+\.[0-9]+$/;
if (!regex.test(newTag)) {
core.setFailed('Tag does not match the required format "v[0-9]+.[0-9]+.[0-9]+"');
return;
Expand All @@ -55,11 +55,14 @@ jobs:
repo: context.repo.repo,
ref: 'tags/'
});
console.log(`Existing tags: ${refs.map(ref => ref.ref.replace('refs/tags/', '')).join(', ')}`);
const latestTag = refs.sort((a, b) => new Date(b.object.date) - new Date(a.object.date))[0].ref.replace('refs/tags/', '');
console.log(`Latest tag: ${latestTag}`);
if (refs.length === 0) {
// No existing tags, so any new tag is valid
console.log('No existing tags found. Any new tag is considered valid.');
return;
}
const latestTag = refs.sort((a, b) => new Date(b.object.date) - new Date(a.object.date))[0].ref.replace('refs/tags/', '');
const latestVersion = latestTag.replace('v', '').split('.').map(Number);
const newVersion = newTag.replace('v', '').split('.').map(Number);
Expand All @@ -75,35 +78,35 @@ jobs:
tag-name: ${{ github.event.inputs.tag-name }}

release:
needs: tag
generate-release-notes:
needs: check-tag
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4.1.1
with:
fetch-depth: 0
ref: refs/tags/${{ github.event.inputs.tag-name }}

- uses: actions/[email protected]
with:
python-version: '3.11'

- name: Generate release notes
id: release_notes_generator
- name: Generate Release Notes
id: generate_release_notes
uses: AbsaOSS/generate-release-notes@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag-name: ${{ github.event.inputs.tag-name }}
chapters: |
[
{"title": "Breaking Changes 💥", "label": "breaking-change"},
{"title": "New Features 🎉", "label": "feature"},
{"title": "New Features 🎉", "label": "enhancement"},
{"title": "Bugfixes 🛠", "label": "bug"}
]
chapters: '[
{"title": "Breaking Changes 💥", "label": "breaking-change"},
{"title": "New Features 🎉", "label": "enhancement"},
{"title": "New Features 🎉", "label": "feature"},
{"title": "Bugfixes 🛠", "label": "bug"}
]'
verbose: true
warnings: true


- name: Create and Push Tag
uses: actions/github-script@v7
with:
Expand All @@ -123,13 +126,13 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
tag-name: ${{ github.event.inputs.tag-name }}

- name: Create draft release
- name: Create Draft Release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
name: ${{ github.event.inputs.tag-name }}
body: ${{ steps.release_notes_generator.outputs.release-notes }}
body: ${{ steps.generate_release_notes.outputs.release-notes }}
tag_name: ${{ github.event.inputs.tag-name }}
draft: true
prerelease: false

0 comments on commit d5c5b70

Please sign in to comment.