Skip to content

Commit

Permalink
Publish release assets at the same time as publishing to repositories.
Browse files Browse the repository at this point in the history
  • Loading branch information
timbess committed Jul 6, 2023
1 parent 7bf871d commit e1b90be
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 46 deletions.
75 changes: 36 additions & 39 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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 }}

##########################################################################################################################
##########################################################################################################################

Expand Down Expand Up @@ -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 }}
66 changes: 59 additions & 7 deletions tools/perspective-scripts/publish.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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) => {
Expand All @@ -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)
);
}
})
);

Expand Down Expand Up @@ -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`,
Expand Down

0 comments on commit e1b90be

Please sign in to comment.