Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use CLI via standalone binary package #1879

Merged
merged 14 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 134 additions & 2 deletions .github/workflows/cd-source.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,106 @@ on:
types: [closed]

jobs:
Build-Binaries:
name: Build binaries
if: |
github.event.pull_request.user.login == 'polywrap-build-bot' &&
github.event.pull_request.merged == true
runs-on: ubuntu-latest
strategy:
matrix:
arch:
- x64
- arm64
node-version:
- node18
os:
- linux
- macos
- win
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.base.ref }}

- name: Read VERSION into env.RELEASE_VERSION
run: echo RELEASE_VERSION=$(cat VERSION) >> $GITHUB_ENV

- name: Is Pre-Release
run: |
STR="${RELEASE_VERSION}"
SUB='pre.'
if [[ "$STR" == *"$SUB"* ]]; then
echo PRE_RELEASE=true >> $GITHUB_ENV
else
echo PRE_RELEASE=false >> $GITHUB_ENV
fi

- name: Check If Tag Exists
id: tag_check
shell: bash -ex {0}
run: |
GET_API_URL="https://api.github.com/repos/${{github.repository}}/git/ref/tags/${{env.RELEASE_VERSION}}"
http_status_code=$(curl -LI $GET_API_URL -o /dev/null -w '%{http_code}\n' -s \
-H "Authorization: token ${GITHUB_TOKEN}")
if [ "$http_status_code" -ne "404" ] ; then
echo TAG_EXISTS=true >> $GITHUB_ENV
else
echo TAG_EXISTS=false >> $GITHUB_ENV
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Read .nvmrc into env.NVMRC
if: env.TAG_EXISTS == 'false'
run: echo NVMRC=$(cat .nvmrc) >> $GITHUB_ENV

- name: Setup Node.js
if: env.TAG_EXISTS == 'false'
uses: actions/setup-node@v1
with:
node-version: '${{env.NVMRC}}'

- name: Install Rust
if: env.TAG_EXISTS == 'false'
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true

- name: Build CLI
if: env.TAG_EXISTS == 'false'
run: |
yarn install
yarn build

- name: Package into node binary
if: env.TAG_EXISTS == 'false'
uses: lando/pkg-action@v2
with:
entrypoint: ./packages/cli/bin/polywrap
config: ./packages/cli/package.json
options: --output ./packages/cli/standalone-binaries/${{ matrix.os }}-${{ matrix.arch }}/polywrap --compress Brotli
pkg: 5.8.1
upload: false
arch: ${{ matrix.arch }}
node-version: ${{ matrix.node-version }}
os: ${{ matrix.os }}

- name: Upload Artifacts
if: env.TAG_EXISTS == 'false'
uses: actions/upload-artifact@v3
with:
name: cli-binary-${{ matrix.os }}-${{ matrix.arch }}
path: ${{ steps.pkg-action.outputs.file }}

Publish-GitHub:
name: Publish source to github.com
if: |
github.event.pull_request.user.login == 'polywrap-build-bot' &&
github.event.pull_request.merged == true
needs: Build-Binaries
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down Expand Up @@ -62,20 +157,57 @@ jobs:
github_repo: ${{ github.repository }}
git_commit_sha: ${{ github.event.pull_request.merge_commit_sha }}

- name: Download Artifacts linux-x64
uses: actions/download-artifact@v3
with:
name: cli-binary-linux-x64
path: ./bin/linux-x64/

- name: Download Artifacts linux-arm64
uses: actions/download-artifact@v3
with:
name: cli-binary-linux-arm64
path: ./bin/linux-arm64/

- name: Download Artifacts macos-x64
uses: actions/download-artifact@v3
with:
name: cli-binary-macos-x64
path: ./bin/macos-x64/

- name: Download Artifacts macos-arm64
uses: actions/download-artifact@v3
with:
name: cli-binary-macos-arm64
path: ./bin/macos-arm64/

- name: Download Artifacts win-x64
uses: actions/download-artifact@v3
with:
name: cli-binary-win-x64
path: ./bin/win-x64/

- name: Download Artifacts win-arm64
uses: actions/download-artifact@v3
with:
name: cli-binary-win-arm64
path: ./bin/win-arm64/

- name: Create Release
id: create_release
if: env.PRE_RELEASE == 'false' && env.TAG_EXISTS == 'false' && github.event.pull_request.merged == true
uses: actions/create-release@v1
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.RELEASE_VERSION }}
# Copy Pull Request's tile and body to Release Note
release_name: ${{ github.event.pull_request.title }}
name: ${{ github.event.pull_request.title }}
body: |
${{ github.event.pull_request.body }}
draft: false
prerelease: false
files: ./bin

- uses: actions/[email protected]
if: env.TAG_EXISTS == 'false'
Expand Down
66 changes: 66 additions & 0 deletions .github/workflows/ci-javascript.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,69 @@ jobs:
- name: Test CLI JS
run: yarn test
working-directory: ./packages/js/cli

Test-Cli-Standalone-Package:
runs-on: ubuntu-latest
needs: CI-WRAP-Test-Harness
if: ${{ always() }}
timeout-minutes: 60
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Read .nvmrc
run: echo ::set-output name=NVMRC::$(cat .nvmrc)
id: nvm

- name: Setup Node.js
uses: actions/setup-node@master
with:
node-version: '${{ steps.nvm.outputs.NVMRC }}'

- uses: actions/setup-go@v3
with:
go-version: '^1.13.1'

- name: Install cue lang
run: go install cuelang.org/go/cmd/cue@latest

- name: Check if cue is installed
run: cue version

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- uses: actions/cache@v2
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-

- name: Install dependencies
run: yarn install --nonInteractive --frozen-lockfile --prefer-offline

- name: Build
run: yarn build

- name: Get updated wrappers
if: ${{ needs.CI-WRAP-Test-Harness.outputs.rebuild_required == 'true' }}
uses: actions/download-artifact@v3
id: get-wrappers
with:
name: rebuilt-wrappers
path: ./wrappers

- if: ${{ needs.CI-WRAP-Test-Harness.outputs.rebuild_required == 'true' }}
run: |
rm -rf packages/test-cases/cases/wrappers
mv wrappers packages/test-cases/cases

- name: Build CLI standalone package for testing
run: yarn pkg:dev
working-directory: ./packages/cli

- name: Test CLI standalone package
run: yarn test:pkg
working-directory: ./packages/cli
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"build:core": "lerna run build --no-private --ignore polywrap --ignore @polywrap/cli-js",
"build:cli": "lerna run build --scope polywrap && lerna run build --scope @polywrap/cli-js",
"build:docs": "lerna run build:docs",
"pkg": "lerna run pkg:prod --scope polywrap",
"lint": "lerna run lint",
"lint:fix": "lerna run lint -- --fix",
"lint:ci": "yarn lint",
Expand Down
1 change: 1 addition & 0 deletions packages/cli/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
compiled-lang/*.json
src/lib/intl/types.ts
standalone-binaries
3 changes: 1 addition & 2 deletions packages/cli/bin/polywrap
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ if (['v', 'version', '-v', '--v', '-version', '--version'].includes(process.argv
process.exit(0)
}

var sourceDir = __dirname + '/../build'
require(sourceDir + '/cli').run(process.argv)
require("../build/cli").run(process.argv)
16 changes: 14 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@
"test:e2e:p2": "yarn test:cmd -- ./src/__tests__/e2e/p2/*.spec.ts",
"test:rust": "yarn test:cmd -- --config ./jest.rs.config.js",
"test:golang": "yarn test:cmd -- --config ./jest.go.config.js",
"test:watch": "yarn test -- --watch"
"test:watch": "yarn test -- --watch",
"test:pkg": "PKG_CLI=true yarn test:e2e:p1 && yarn test:e2e:p2",
"pkg:prod": "ts-node ./scripts/buildStandaloneBinaries.ts --prod",
"pkg:dev": "ts-node ./scripts/buildStandaloneBinaries.ts"
},
"resolutions": {
"colors": "1.4.0"
Expand Down Expand Up @@ -96,10 +99,19 @@
"jest": "26.6.3",
"ts-jest": "26.5.4",
"ts-morph": "10.0.1",
"ts-node": "10.9.1"
"ts-node": "10.9.1",
"pkg": "5.8.1"
},
"gitHead": "7346adaf5adb7e6bbb70d9247583e995650d390a",
"publishConfig": {
"access": "public"
},
"pkg": {
"assets": [
"lang/**/*",
"build/lib/defaults/build-strategies/**/*",
"build/lib/defaults/deploy-modules/**/*",
"build/lib/defaults/infra-modules/**/*"
]
}
}
80 changes: 80 additions & 0 deletions packages/cli/scripts/buildStandaloneBinaries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { exec } from "pkg";
import path from "path";
import os from "os";

const cliRoot = path.resolve(__dirname + "/..");
const binPath = path.join(cliRoot, "standalone-binaries");
const isProd = process.argv.includes("--prod");
const targets = [
"macos-arm64",
"macos-x64",
"linux-arm64",
"linux-x64",
"win-arm64",
"win-x64",
];

async function main() {
const compression = isProd ? "Brotli" : "GZip";

if (isProd) {
for (const target of targets) {
await compileTarget(target, cliRoot, binPath, compression);
}
} else {
const target = getPlatformAndArch();
await compileTarget(target, cliRoot, binPath, compression);
}
}

async function compileTarget(
target: string,
cliRoot: string,
binPath: string,
compression: string
) {
const targetPath = path.join(binPath, target, "polywrap");
await exec([
cliRoot,
"-t",
`node18-${target}`,
"--output",
targetPath,
"--compress",
compression,
]);
}

const getPlatformAndArch = (): string => {
const supportedPlatforms: Record<string, string> = {
darwin: "macos",
win32: "win",
linux: "linux",
};
const supportedArchitectures: Record<string, string> = {
x64: "x64",
arm64: "arm64",
};

const platform = supportedPlatforms[os.platform()];
const arch = supportedArchitectures[os.arch()];

if (!platform || !arch) {
throw new Error(`Unsupported platform or architecture.
Supported platforms: ${Object.keys(supportedPlatforms).toString()}.
Supported architectures: ${Object.keys(supportedArchitectures).toString()}`);
}

if (platform === "win") {
return `${platform}-${arch}.exe`;
}
return `${platform}-${arch}`;
};

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
Loading
Loading