From c479e81b23f7e864ee551e71e6d7e842e390ce3a Mon Sep 17 00:00:00 2001 From: miroslavpojer Date: Thu, 1 Aug 2024 11:01:12 +0200 Subject: [PATCH 1/2] - Improvement of release draft creation. --- .github/workflows/release_draft.yml | 72 ++++++++++++++++------------- 1 file changed, 39 insertions(+), 33 deletions(-) diff --git a/.github/workflows/release_draft.yml b/.github/workflows/release_draft.yml index a849ab4..fd53619 100644 --- a/.github/workflows/release_draft.yml +++ b/.github/workflows/release_draft.yml @@ -23,8 +23,9 @@ on: required: true jobs: - tag: + check-tag: runs-on: ubuntu-latest + name: Check tag steps: - uses: actions/checkout@v4 with: @@ -55,11 +56,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); @@ -75,33 +79,17 @@ jobs: tag-name: ${{ github.event.inputs.tagName }} - - name: Create and push tag - uses: actions/github-script@v7 - with: - script: | - const tag = core.getInput('tag-name') - const ref = `refs/tags/${tag}`; - const sha = context.sha; // The SHA of the commit to tag - - await github.rest.git.createRef({ - owner: context.repo.owner, - repo: context.repo.repo, - ref: ref, - sha: sha - }); - - console.log(`Tag created: ${tag}`); - github-token: ${{ secrets.GITHUB_TOKEN }} - tag-name: ${{ github.event.inputs.tagName }} - - release: - needs: tag + generate-release-notes: + needs: check-tag runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - ref: refs/tags/${{ github.event.inputs.tagName }} + + - uses: actions/setup-python@v5.1.1 + with: + python-version: '3.11' - name: Generate release notes id: generate_release_notes @@ -110,22 +98,40 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: tag-name: ${{ github.event.inputs.tagName }} - chapters: | - [ + chapters: '[ {"title": "Breaking Changes 💥", "label": "breaking-change"}, {"title": "New Features 🎉", "label": "feature"}, {"title": "New Features 🎉", "label": "enhancement"}, {"title": "Bugfixes 🛠", "label": "bug"} - ] + ]' warnings: true - - name: Create draft release + - name: Create and Push Tag + uses: actions/github-script@v7 + with: + script: | + const tag = core.getInput('tag-name') + const ref = `refs/tags/${tag}`; + const sha = context.sha; // The SHA of the commit to tag + + await github.rest.git.createRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: ref, + sha: sha + }); + + console.log(`Tag created: ${tag}`); + github-token: ${{ secrets.GITHUB_TOKEN }} + tag-name: ${{ github.event.inputs.tag-name }} + + - name: Create Draft Release uses: softprops/action-gh-release@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - name: ${{ github.event.inputs.tagName }} - body: ${{ steps.generate_release_notes.outputs.releaseNotes }} - tag_name: ${{ github.event.inputs.tagName }} + name: ${{ github.event.inputs.tag-name }} + body: ${{ steps.generate_release_notes.outputs.release-notes }} + tag_name: ${{ github.event.inputs.tag-name }} draft: true prerelease: false From efcfaca731f9f422b7fddc5f39ef2a953e6d3e3a Mon Sep 17 00:00:00 2001 From: miroslavpojer Date: Thu, 1 Aug 2024 13:16:18 +0200 Subject: [PATCH 2/2] - Debugging a source of problem. --- .github/workflows/release_draft.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/release_draft.yml b/.github/workflows/release_draft.yml index fd53619..75c295f 100644 --- a/.github/workflows/release_draft.yml +++ b/.github/workflows/release_draft.yml @@ -61,6 +61,8 @@ jobs: // No existing tags, so any new tag is valid console.log('No existing tags found. Any new tag is considered valid.'); return; + } else { + 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/', '');