From 52c16efed4f42cf4b03b2689b0ce18bac5d1896e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Mon, 23 Sep 2024 12:18:05 +0200 Subject: [PATCH] Fix release publishing Use `release_id` instead of `upload_url`. Use `data` instead of `file`. Use a loop. --- .github/workflows/main.yaml | 74 ++++++++++--------------------------- 1 file changed, 19 insertions(+), 55 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 16a64ba1b..f207c29f0 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -187,61 +187,25 @@ jobs: 'X-GitHub-Api-Version': '2022-11-28' } }); - await github.rest.repos.uploadReleaseAsset({ - owner: context.repo.owner, - repo: context.repo.repo, - url: release.data.upload_url, - name: "print-servlet-${{ steps.version.outputs.version }}.war", - file: fs.readFileSync("./core/build/libs/print-servlet-${{ steps.version.outputs.version }}.war"), - headers: { - 'X-GitHub-Api-Version': '2022-11-28', - 'content-type': 'application/java-archive' - }, - }); - await github.rest.repos.uploadReleaseAsset({ - owner: context.repo.owner, - repo: context.repo.repo, - url: release.data.upload_url, - name: "print-cli-${{ steps.version.outputs.version }}.zip", - file: fs.readFileSync("./core/build/distributions/core-${{ steps.version.outputs.version }}.zip"), - headers: { - 'X-GitHub-Api-Version': '2022-11-28', - 'content-type': 'application/zip' - }, - }); - await github.rest.repos.uploadReleaseAsset({ - owner: context.repo.owner, - repo: context.repo.repo, - url: release.data.upload_url, - name: "print-lib-${{ steps.version.outputs.version }}.jar", - file: fs.readFileSync("./core/build/libs/print-lib-${{ steps.version.outputs.version }}.jar"), - headers: { - 'X-GitHub-Api-Version': '2022-11-28', - 'content-type': 'application/java-archive' - }, - }); - await github.rest.repos.uploadReleaseAsset({ - owner: context.repo.owner, - repo: context.repo.repo, - url: release.data.upload_url, - name: "print-lib-${{ steps.version.outputs.version }}-sources.jar", - file: fs.readFileSync("./core/build/libs/print-lib-${{ steps.version.outputs.version }}-sources.jar"), - headers: { - 'X-GitHub-Api-Version': '2022-11-28', - 'content-type': 'application/java-archive' - }, - }); - await github.rest.repos.uploadReleaseAsset({ - owner: context.repo.owner, - repo: context.repo.repo, - url: release.data.upload_url, - name: "print-lib-${{ steps.version.outputs.version }}-javadoc.jar", - file: fs.readFileSync("./core/build/libs/print-lib-${{ steps.version.outputs.version }}-javadoc.jar"), - headers: { - 'X-GitHub-Api-Version': '2022-11-28', - 'content-type': 'application/java-archive' - }, - }); + for (const archive of [ + {prefix: 'print-servlet-', suffix: '.war', filePrefix: './core/build/libs/print-servlet-', 'mime-type': 'application/java-archive'}, + {prefix: 'print-cli-', suffix: '.zip', filePrefix: './core/build/distributions/core-', 'mime-type': 'application/zip'}, + {prefix: 'print-lib-', suffix: '.jar', filePrefix: './core/build/libs/print-lib-', 'mime-type': 'application/java-archive'}, + {prefix: 'print-lib-', suffix: '-sources.jar', filePrefix: './core/build/libs/print-lib-', 'mime-type': 'application/java-archive'}, + {prefix: 'print-lib-', suffix: '-javadoc.jar', filePrefix: './core/build/libs/print-lib-', 'mime-type': 'application/java-archive'}, + ]) { + await github.rest.repos.uploadReleaseAsset({ + owner: context.repo.owner, + repo: context.repo.repo, + release_id: release.data.id, + name: archive.prefix + '${{ steps.version.outputs.version }}' + archive.suffix, + data: fs.readFileSync(archive.filePrefix + '${{ steps.version.outputs.version }}' + archive.suffix), + headers: { + 'X-GitHub-Api-Version': '2022-11-28', + 'content-type': archive['mime-type'] + }, + }); + } if: startsWith(github.ref, 'refs/tags/') && env.HAS_SECRETS == 'HAS_SECRETS' # Update the documentation