From e1b90beaab082d0eeec68be15ffe4191f04dc637 Mon Sep 17 00:00:00 2001 From: Timothy Bess Date: Thu, 6 Jul 2023 11:13:26 -0400 Subject: [PATCH] Publish release assets at the same time as publishing to repositories. --- .github/workflows/build.yml | 75 +++++++++++++-------------- tools/perspective-scripts/publish.mjs | 66 ++++++++++++++++++++--- 2 files changed, 95 insertions(+), 46 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9929b6a86e..8279898e8d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1033,37 +1033,6 @@ jobs: path: python/perspective/dist/*.tar.gz if: ${{ matrix.os == 'macos-11' }} - ############################### - # Upload artifacts to release # - ############################### - - - name: Upload dist artifact for Windows - if: ${{ runner.os == 'Windows' }} - uses: softprops/action-gh-release@v1 - with: - files: | - python/perspective/dist/*.whl - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Upload wheelhouse artifact for non-Windows - if: ${{ runner.os != 'Windows' }} - uses: softprops/action-gh-release@v1 - with: - files: | - python/perspective/wheelhouse/*.whl - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Upload sdist artifact for MacOS - if: ${{ matrix.os == 'macos-11' }} - uses: softprops/action-gh-release@v1 - with: - files: | - python/perspective/dist/*.tar.gz - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - build_pyodide: runs-on: ubuntu-22.04 needs: [initialize] @@ -1114,14 +1083,6 @@ jobs: name: perspective-python-dist-pyodide path: dist/*.whl - - name: Upload pyodide wheel to release - uses: softprops/action-gh-release@v1 - with: - files: | - dist/*.whl - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - ########################################################################################################################## ########################################################################################################################## @@ -1613,3 +1574,39 @@ jobs: ########################################################################################################################## ########################################################################################################################## + + ########################################## + #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~# + #~~~~~~~~~~~~~~~/#########\~~~~~~~~~~~~~~# + #~~~~~~~~~~~~~~|##|~~~~~|##|~~~~~~~~~~~~~# + #~~~~~~~~~~~~~~|##|~~~~~|##|~~~~~~~~~~~~~# + #~~~~~~~~~~~~~~|###########|~~~~~~~~~~~~~# + #~~~~~~~~~~~~~~|##|~~~~~|##|~~~~~~~~~~~~~# + #~~~~~~~~~~~~~~|##|~~~~~|##|~~~~~~~~~~~~~# + #~~~~~~~~~~~~~~~\#########/~~~~~~~~~~~~~~# + #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~# + # Stage Eight - Publish Artifacts # + #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~# + + publish: + needs: [test_js_and_python, test_python, test_python_sdist] + if: startsWith(github.ref, 'refs/tags/v') + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v2 + + - name: Install yarn + run: npm install -g yarn + + - name: Install js dependencies + run: yarn --frozen-lockfile + env: + PSP_SKIP_EMSDK_INSTALL: 1 + + - name: Run publish script + run: node tools/perspective-scripts/publish.mjs + env: + CI: true + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_WORKFLOW_ID: ${{ github.run_id }} + COMMIT: ${{ github.sha }} diff --git a/tools/perspective-scripts/publish.mjs b/tools/perspective-scripts/publish.mjs index 0da3296155..ae581c9056 100644 --- a/tools/perspective-scripts/publish.mjs +++ b/tools/perspective-scripts/publish.mjs @@ -17,6 +17,10 @@ import { promises as fs } from "fs"; import { Octokit } from "octokit"; import readline from "readline"; +const CURRENT_TAG = execSync("git describe --exact-match --tags") + .toString() + .trim(); + // Artifacts Docs: // https://docs.github.com/en/rest/actions/artifacts // Example run: @@ -57,6 +61,7 @@ const gh_js_dist_folders = Object.keys(gh_js_dist_aliases); // Folders for artifacts on GitHub Actions const gh_python_dist_folders = [ // // https://github.com/actions/virtual-environments + "perspective-python-dist-pyodide", // Mac 11 // https://github.com/actions/setup-python/issues/682 @@ -90,6 +95,7 @@ const gh_python_dist_folders = [ // Artifacts inside those folders const wheels = [ + "cp311-cp311-emscripten_3_1_32_wasm32", // Mac 11 "cp37-cp37-macosx_11_0_x86_64", "cp38-cp38-macosx_11_0_x86_64", @@ -116,7 +122,10 @@ const octokit = new Octokit({ }); // Helper function to prompt for user input -function askQuestion(query) { +function askQuestion(query, ciDecision = "y") { + if (process.env.CI) { + return Promise.resolve("y"); + } // https://stackoverflow.com/questions/18193953/waiting-for-user-to-enter-input-in-node-js const rl = readline.createInterface({ input: process.stdin, @@ -184,7 +193,7 @@ if ( js_dist_folders.length !== gh_js_dist_folders.length ) { proceed = "n"; - proceed = await askQuestion("Proceed? (y/N)"); + proceed = await askQuestion("Proceed? (y/N)", "n"); } // If everything good, or they say they want to proceed, @@ -207,6 +216,23 @@ if (proceed.toLowerCase() === "y") { recursive: true, }); + const release = await octokit.request( + "POST /repos/{owner}/{repo}/releases", + { + owner: "finos", + repo: "perspective", + tag_name: CURRENT_TAG, + name: CURRENT_TAG, + body: "Release of perspective", + draft: false, + prerelease: false, + generate_release_notes: false, + headers: { + "X-GitHub-Api-Version": "2022-11-28", + }, + } + ); + // Download the artifact folders await Promise.all( python_dist_folders.map(async (artifact) => { @@ -221,11 +247,25 @@ if (proceed.toLowerCase() === "y") { } ); - // Write out the zip file - await fs.appendFile( - `${dist_folder}/${artifact.name}.zip`, - Buffer.from(download.data) - ); + await octokit.request({ + method: "POST", + url: release.data.upload_url, + owner: "finos", + repo: "perspective", + data: download.data, + name: `${artifact.name}.zip`, + headers: { + "X-GitHub-Api-Version": "2022-11-28", + }, + }); + + if (!artifact.name.includes("pyodide")) { + // Write out the zip file + await fs.appendFile( + `${dist_folder}/${artifact.name}.zip`, + Buffer.from(download.data) + ); + } }) ); @@ -286,6 +326,18 @@ if (proceed.toLowerCase() === "y") { } ); + await octokit.request({ + method: "POST", + url: release.data.upload_url, + owner: "finos", + repo: "perspective", + data: download.data, + name: `${artifact.name}.zip`, + headers: { + "X-GitHub-Api-Version": "2022-11-28", + }, + }); + // Write out the zip file await fs.appendFile( `${js_dist_folder}/${artifact.name}.zip`,