Skip to content

Commit

Permalink
TESTING PUBLISH
Browse files Browse the repository at this point in the history
  • Loading branch information
Exidex committed Jan 27, 2024
1 parent bbca2df commit 21bf78b
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 43 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: publish

on: workflow_dispatch

jobs:
publish:
runs-on: ubuntu-latest
steps:
- run: sudo apt-get install -y protobuf-compiler # deno_kv needs this

- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
registry-url: "https://registry.npmjs.org"
scope: '@project-gauntlet'
- uses: dtolnay/rust-toolchain@stable

- uses: Swatinem/rust-cache@v2
with:
save-if: ${{ github.ref == 'refs/heads/main' }}

- run: npm ci

- run: npm run build --workspace @project-gauntlet/api
- run: npm run build --workspace @project-gauntlet/deno
- run: npm run build --workspace @project-gauntlet/react

- run: npm run build --workspace @project-gauntlet/react-renderer
- run: npm run build --workspace @project-gauntlet/core

# TODO
# - run: cargo build --release

- run: npm run release --workspace @project-gauntlet/release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}


8 changes: 8 additions & 0 deletions js/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
"import": "./gendist/components.js"
}
},
"repository": {
"type": "git",
"url": "https://github.com/project-gauntlet/gauntlet.git",
"directory": "js/api"
},
"files": [
"gendist",
"gentypes"
Expand All @@ -22,5 +27,8 @@
"@types/node": "^18.17.1",
"@project-gauntlet/typings": "*",
"typescript": "^5.2.2"
},
"publishConfig": {
"access": "public"
}
}
8 changes: 8 additions & 0 deletions js/deno/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
"types": "./dist/lib.deno.d.ts"
}
},
"repository": {
"type": "git",
"url": "https://github.com/project-gauntlet/gauntlet.git",
"directory": "js/deno"
},
"files": [
"dist"
],
Expand All @@ -16,5 +21,8 @@
"devDependencies": {
"@types/node": "^18.17.1",
"typescript": "^5.2.2"
},
"publishConfig": {
"access": "public"
}
}
3 changes: 1 addition & 2 deletions js/release/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"name": "@project-gauntlet/release",
"version": "0.1.0",
"scripts": {
"build:release": "tsc --noEmit && rollup --config rollup.config.ts --configPlugin typescript",
"release": "node dist/main.js just-do-it"
"release": "tsc --noEmit && rollup --config rollup.config.ts --configPlugin typescript && node dist/main.js just-do-it"
},
"type": "module",
"dependencies": {
Expand Down
83 changes: 42 additions & 41 deletions js/release/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { EOL } from "node:os";
import { Octokit } from 'octokit';
import { execSync } from "node:child_process";
import { createReadStream } from "node:fs";
import path from "node:path";

const program = new Command();

Expand All @@ -24,10 +25,10 @@ async function doRelease() {
const projectRoot = process.cwd();
const git = simpleGit(projectRoot);

const versionFilePath = `${projectRoot}/VERSION`;
const changelogFilePath = `${projectRoot}/CHANGELOG.md`;
const denoProjectPath = `${projectRoot}/js/deno`;
const apiProjectPath = `${projectRoot}/js/api`;
const versionFilePath = path.join(projectRoot, "VERSION");
const changelogFilePath = path.join(projectRoot, "CHANGELOG.md");
const denoProjectPath = path.join(projectRoot, "js", "deno");
const apiProjectPath = path.join(projectRoot, "js", "api");

const versionRaw = await readFile(versionFilePath, { encoding: "utf-8" });
const version = Number(versionRaw.trim());
Expand Down Expand Up @@ -87,46 +88,46 @@ async function doRelease() {
execSync(`npm version 0.${version}.0`, { stdio: "inherit", cwd: packageDir })
}

const archTarget = execSync("rustc -vV", { cwd: projectRoot, encoding: "utf-8" })
.match(/^host: (.*)$/m)!![0]

bumpNpmPackage(denoProjectPath)
bumpNpmPackage(apiProjectPath)

await git.commit(`Release v${version}`, [versionFilePath, changelogFilePath]);

execSync("npm publish", { cwd: apiProjectPath })
execSync("npm publish", { cwd: denoProjectPath })

const executablePath = `${projectRoot}/target/release/gauntlet`;
const executableStats = await stat(executablePath);

const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN
})

const repo = { owner: 'project-gauntlet', repo: 'gauntlet' };

const response = await octokit.request('POST /repos/{owner}/{repo}/releases', {
...repo,
tag_name: `v${version}`,
target_commitish: 'main',
name: `v${version}`,
body: notesForCurrentRelease.join('\n'),
});

await octokit.request('POST /repos/{owner}/{repo}/releases/{release_id}/assets', {
...repo,
release_id: response.data.id,
name: `gauntlet-${archTarget}`,
label: "gauntlet-test-label",
headers: {
"Content-Type": "application/octet-stream",
"Content-Length": executableStats.size,
},
data: createReadStream(executablePath)
})

await git.push();
await git.push()
await git.pushTags();

execSync('npm publish', { stdio: "inherit", cwd: denoProjectPath })
execSync('npm publish', { stdio: "inherit", cwd: apiProjectPath })

// TODO:
// const executableFilePath = path.join(projectRoot, 'target', 'release', 'gauntlet');
// const executableFileStats = await stat(executableFilePath);
// const executableFileSize = executableFileStats.size;
//
// const rustVv = execSync('rustc -Vv', { encoding: "utf-8" });
// const archTarget = rustVv.match(/^host: (.+)$/)!![0]
//
// const octokit = new Octokit({
// auth: process.env.GITHUB_TOKEN
// })
//
// const repo = { owner: 'project-gauntlet', repo: 'gauntlet' };
//
// const response = await octokit.request('POST /repos/{owner}/{repo}/releases', {
// ...repo,
// tag_name: `v${version}`,
// target_commitish: 'main',
// name: `v${version}`,
// body: notesForCurrentRelease.join('\n'),
// });
//
// await octokit.request('POST /repos/{owner}/{repo}/releases/{release_id}/assets', {
// ...repo,
// release_id: response.data.id,
// name: `gauntlet-${archTarget}`,
// headers: {
// "Content-Type": "application/octet-stream",
// "Content-Length": executableFileSize,
// },
// data: createReadStream(executableFilePath)
// })
}

0 comments on commit 21bf78b

Please sign in to comment.