From 24c9753b716e9c6c5c07972e30894471e7557512 Mon Sep 17 00:00:00 2001 From: Efra Espada Date: Sat, 30 Nov 2024 08:01:34 +0100 Subject: [PATCH 1/2] feature: test workflows --- .github/workflows/publish_release.yml | 57 +------------------- .github/workflows/tag_release.yml | 78 +++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 55 deletions(-) create mode 100644 .github/workflows/tag_release.yml diff --git a/.github/workflows/publish_release.yml b/.github/workflows/publish_release.yml index 85d0310d8..7cd7266a1 100644 --- a/.github/workflows/publish_release.yml +++ b/.github/workflows/publish_release.yml @@ -2,7 +2,7 @@ name: Publish Release on: workflow_run: - workflows: ["Prepare Release"] + workflows: ["Tag Release"] types: - completed @@ -14,7 +14,7 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Read and increment version with TypeScript + - name: Read version id: increment_version uses: actions/github-script@v7 with: @@ -24,59 +24,6 @@ jobs: const version = packageJson.version; core.exportVariable('VERSION', version) - - name: Create tag - id: create_tag - run: | - # Check if the tag already exists in the remote repository - if git rev-parse "v${{ env.VERSION }}" >/dev/null 2>&1; then - echo "Tag v${{ env.VERSION }} already exists." - else - # Create and push the new tag - git tag "v${{ env.VERSION }}" - git push origin "v${{ env.VERSION }}" - fi - - - name: Create a release - id: create_release - uses: actions/github-script@v7 - with: - script: | - const version = "${{ env.VERSION }}"; - - // Fetch the pull requests merged into the base branch (master) - const { data: pulls } = await github.rest.pulls.list({ - owner: context.repo.owner, - repo: context.repo.repo, - state: 'closed', - sort: 'updated', - direction: 'desc', - per_page: 1, - base: 'master', - }); - - if (pulls.length === 0) { - throw new Error('No pull requests merged into master were found.'); - } - - const lastPr = pulls[0]; - console.log(`Last PR found: ${lastPr.title} (#${lastPr.number})`); - - // Use the PR description for the release notes - const releaseBody = lastPr.body || 'No description provided for the last merged PR.'; - - // Create the release - const { data: release } = await github.rest.repos.createRelease({ - owner: context.repo.owner, - repo: context.repo.repo, - tag_name: `v${version}`, - name: `v${version} - ${lastPr.title}`, - body: releaseBody, - draft: false, - prerelease: false, - }); - - console.log(`Release created: ${release.html_url}`); - - name: Publish to GitHub Marketplace uses: actions/github-script@v7 with: diff --git a/.github/workflows/tag_release.yml b/.github/workflows/tag_release.yml new file mode 100644 index 000000000..03f6a6373 --- /dev/null +++ b/.github/workflows/tag_release.yml @@ -0,0 +1,78 @@ +name: Publish Release + +on: + workflow_run: + workflows: ["Prepare Release"] + types: + - completed + +jobs: + publish: + if: ${{ github.event.workflow_run.conclusion == 'success' }} + name: Publish version + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Read version + id: increment_version + uses: actions/github-script@v7 + with: + script: | + const fs = require('fs'); + const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8')); + const version = packageJson.version; + core.exportVariable('VERSION', version) + + - name: Create tag + id: create_tag + run: | + # Check if the tag already exists in the remote repository + if git rev-parse "v${{ env.VERSION }}" >/dev/null 2>&1; then + echo "Tag v${{ env.VERSION }} already exists." + else + # Create and push the new tag + git tag "v${{ env.VERSION }}" + git push origin "v${{ env.VERSION }}" + fi + + - name: Create a release + id: create_release + uses: actions/github-script@v7 + with: + script: | + const version = "${{ env.VERSION }}"; + + // Fetch the pull requests merged into the base branch (master) + const { data: pulls } = await github.rest.pulls.list({ + owner: context.repo.owner, + repo: context.repo.repo, + state: 'closed', + sort: 'updated', + direction: 'desc', + per_page: 1, + base: 'master', + }); + + if (pulls.length === 0) { + throw new Error('No pull requests merged into master were found.'); + } + + const lastPr = pulls[0]; + console.log(`Last PR found: ${lastPr.title} (#${lastPr.number})`); + + // Use the PR description for the release notes + const releaseBody = lastPr.body || 'No description provided for the last merged PR.'; + + // Create the release + const { data: release } = await github.rest.repos.createRelease({ + owner: context.repo.owner, + repo: context.repo.repo, + tag_name: `v${version}`, + name: `v${version} - ${lastPr.title}`, + body: releaseBody, + draft: false, + prerelease: false, + }); + + console.log(`Release created: ${release.html_url}`); From 061b3bdf147e7ea3484a5d4ecfca5131c53512d4 Mon Sep 17 00:00:00 2001 From: Efra Espada Date: Sat, 30 Nov 2024 08:02:50 +0100 Subject: [PATCH 2/2] feature: test workflows --- .github/workflows/tag_release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tag_release.yml b/.github/workflows/tag_release.yml index 03f6a6373..a8bdc4f07 100644 --- a/.github/workflows/tag_release.yml +++ b/.github/workflows/tag_release.yml @@ -1,4 +1,4 @@ -name: Publish Release +name: Tag Release on: workflow_run: