Message-ID: From: "vlsi (@vlsi)" To: "pgjdbc/pgjdbc" Date: Fri, 19 Sep 2025 07:48:21 +0000 Subject: [pgjdbc/pgjdbc] PR #3814: chore: attach release artifacts to GitHub Release when releasing a new version List-Id: X-GitHub-Additions: 50 X-GitHub-Author-Id: 213894 X-GitHub-Author-Login: vlsi X-GitHub-Base: master X-GitHub-Changed-Files: 2 X-GitHub-Commits: 1 X-GitHub-Deletions: 53 X-GitHub-Head-Branch: release_artifacts X-GitHub-Head-SHA: 0b68e2909c159ed4d63a3b2562ace32fbb830dc3 X-GitHub-Issue: 3814 X-GitHub-Labels: chore X-GitHub-Repo: pgjdbc/pgjdbc X-GitHub-State: open X-GitHub-Type: pull_request X-GitHub-Url: https://github.com/pgjdbc/pgjdbc/pull/3814 Content-Type: text/plain; charset=utf-8 Fixes https://github.com/pgjdbc/pgjdbc/issues/3812 diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index b97ea67f3f..f01e9e9722 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -20,9 +20,6 @@ jobs: permissions: # write permission is required to create a github release contents: write - env: - # Publish pre-release files to a draft release - PUBLISH_SNAPSHOT: true steps: # Drafts your next Release notes as Pull Requests are merged into "master" - name: Get the current version @@ -53,53 +50,3 @@ jobs: version: ${{ steps.current_version.outputs.result }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Checkout sources - if: ${{ env.PUBLISH_SNAPSHOT == 'true' }} - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - - name: Set up JDK 17 - if: ${{ env.PUBLISH_SNAPSHOT == 'true' }} - uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0 - with: - java-version: 17 - distribution: liberica - - name: Build - if: ${{ env.PUBLISH_SNAPSHOT == 'true' }} - uses: burrunan/gradle-cache-action@4b67497abd37a511d6c1dc6299bdd84ff39f7bf5 # v3.0.2 - with: - job-id: jdk17 - arguments: --scan --no-parallel --no-daemon :postgresql:osgiJar - - name: Attach files to release - if: ${{ env.PUBLISH_SNAPSHOT == 'true' }} - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9 - env: - # https://github.com/release-drafter/release-drafter#action-outputs - RELEASE_ID: ${{ steps.prepare_release.outputs.id }} - with: - # language=JavaScript - script: | - const fs = require('fs'); - const {RELEASE_ID} = process.env; - // remove old jar files from the release - const assets = await github.rest.repos.listReleaseAssets({ - owner: context.repo.owner, - repo: context.repo.repo, - release_id: RELEASE_ID - }); - for (const asset of assets.data) { - if (asset.name.endsWith('.jar')) { - await github.rest.repos.deleteReleaseAsset({ - owner: context.repo.owner, - repo: context.repo.repo, - asset_id: asset.id - }); - } - } - const globber = await glob.create('pgjdbc/build/libs/postgresql-*-osgi.jar'); - const files = await globber.glob(); - await github.rest.repos.uploadReleaseAsset({ - owner: context.repo.owner, - repo: context.repo.repo, - name: files[0].replace(/^(.*build\/libs\/postgresql-)/, "postgresql-").replace("-osgi", ""), - release_id: RELEASE_ID, - data: fs.readFileSync(files[0]) - }) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b5073effce..991209e134 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -130,6 +130,56 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Attach files to the release + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9 + env: + # https://github.com/release-drafter/release-drafter#action-outputs + RELEASE_ID: ${{ steps.publish_release.outputs.id }} + VERSION: ${{ steps.release_version.outputs.version }} + with: + # language=javascript + script: | + const fs = require('fs'); + const {RELEASE_ID, VERSION} = process.env; + const artifactName = `postgresql-${VERSION}.jar`; + const signatureName = `${artifactName}.asc`; + const globber = await glob.create(`pgjdbc/build/nmcp/m2/org/postgresql/postgresql/${VERSION}/${artifactName}`); + const files = await globber.glob(); + if (files.length !== 1) { + core.setFailed(`Expected exactly one release jar named ${artifactName}, found ${files.length}: ${files.join(', ')}`); + return; + } + const uploadFiles = [[artifactName, files[0]], [signatureName, `${files[0]}.asc`]]; + for (const [name, path] of uploadFiles) { + if (!fs.existsSync(path)) { + core.setFailed(`Release artifact ${name} does not exist at ${path}`); + return; + } + } + const assets = await github.rest.repos.listReleaseAssets({ + owner: context.repo.owner, + repo: context.repo.repo, + release_id: RELEASE_ID + }); + for (const asset of assets.data) { + if (asset.name.endsWith('.jar') || asset.name.endsWith('.jar.asc')) { + await github.rest.repos.deleteReleaseAsset({ + owner: context.repo.owner, + repo: context.repo.repo, + asset_id: asset.id + }); + } + } + for (const [name, path] of uploadFiles) { + await github.rest.repos.uploadReleaseAsset({ + owner: context.repo.owner, + repo: context.repo.repo, + name, + release_id: RELEASE_ID, + data: fs.readFileSync(path) + }); + } + - name: Compute the next patch version id: next_version env: