Skip to content

Commit

Permalink
Merge branch 'master' into cli-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
0x2b3bfa0 committed Oct 11, 2022
2 parents ec4204e + 926f62c commit 3c34b28
Show file tree
Hide file tree
Showing 22 changed files with 181 additions and 87 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: CodeQL

on:
pull_request:
paths-ignore:
- '**.md'
- assets/**
schedule:
- cron: '0 0 * * *' # everyday @ 0000 UTC

concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: true

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
steps:
- uses: actions/checkout@v3
- uses: github/codeql-action/init@v2
with:
languages: javascript
- uses: github/codeql-action/autobuild@v2
- uses: github/codeql-action/analyze@v2
43 changes: 11 additions & 32 deletions .github/workflows/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,48 +101,27 @@ jobs:
with:
registry-url: https://registry.npmjs.org
- run: npm install
- run:
npm ${{ inputs.release && 'publish' || 'publish --dry-run' }}
- run: npm ${{ inputs.release && 'publish' || 'publish --dry-run' }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: install ldid
run: |
sudo apt install --yes libplist-dev
git clone --branch v2.1.5 git://git.saurik.com/ldid.git
sudo g++ -pipe -o /usr/bin/ldid ldid/ldid.cpp -I. -x c ldid/{lookup2.c,sha1.h} -lplist -lcrypto
- id: build
name: build
run: |
echo ::set-output name=tag::${GITHUB_REF#refs/tags/}
# Step required "thanks" to https://github.com/actions/runner-images/issues/6283
- uses: Homebrew/actions/setup-homebrew@29b2973f18e5aca5443f4b3d87f68eda7a27b22b
- run: brew install ldid
- run: |
cp node_modules/@npcz/magic/dist/magic.mgc assets/magic.mgc
npx --yes pkg --no-bytecode --public-packages "*" --public package.json
rm assets/magic.mgc
for cmd in '' runner publish pr; do
build/cml-linux-x64 $cmd --version
done
for cmd in '' runner publish pr; do build/cml-linux-x64 $cmd --version; done
cp build/cml-linux{-x64,}
cp build/cml-macos{-x64,}
- uses: softprops/action-gh-release@v1
if: inputs.release
with:
files: |
build/cml-alpine-arm64
build/cml-alpine-x64
build/cml-linux-arm64
build/cml-linuxstatic-arm64
build/cml-linuxstatic-x64
build/cml-linux-x64
build/cml-linux
build/cml-macos-arm64
build/cml-macos-x64
build/cml-macos
build/cml-win-arm64.exe
build/cml-win-x64.exe
- if: inputs.release
run:
find build -type f | xargs gh release upload $(basename ${{
github.head_ref }})
env:
GITHUB_TOKEN: ${{ secrets.TEST_GITHUB_TOKEN }}
images:
needs: packages
secrets: inherit
uses: ./.github/workflows/images.yml
with:
release: ${{ inputs.release }}
release: ${{ inputs.release || false }}
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ WORKDIR ${CML_RUNNER_PATH}
# SET SPECIFIC ENVIRONMENT VARIABLES
ENV IN_DOCKER=1
ENV RUNNER_ALLOW_RUNASROOT=1
# Environment variable used by cml to detect it's been installed using the docker image.
ENV _CML_CONTAINER_IMAGE=true

# DEFINE ENTRY POINT AND COMMAND
# Smart entrypoint understands commands like `bash` or `/bin/sh` but defaults to `cml`;
Expand Down
28 changes: 24 additions & 4 deletions bin/cml.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ const setupOpts = (opts) => {

const { markdownfile } = opts;
opts.markdownFile = markdownfile;
opts.cmlCommand = opts._[0];
opts.cml = new CML(opts);
};

Expand Down Expand Up @@ -76,9 +75,29 @@ const setupLogger = (opts) => {
});
};

const setupTelemetry = async (opts) => {
const { cml, cmlCommand: action } = opts;
opts.telemetryEvent = await jitsuEventPayload({ action, cml });
const setupTelemetry = async (opts, yargs) => {
const { cml, _: command } = opts;

const options = {};
for (const [name, option] of Object.entries(opts.options)) {
// Skip options with default values (i.e. not explicitly set by users)
if (opts[name] && !yargs.parsed.defaulted[name]) {
switch (option.telemetryData) {
case 'name':
options[name] = null;
break;
case 'full':
options[name] = opts[name];
break;
}
}
}

opts.telemetryEvent = await jitsuEventPayload({
action: command.join(':'),
extra: { options },
cml
});
};

const runPlugin = async ({ $0: executable, command }) => {
Expand All @@ -99,6 +118,7 @@ const handleError = (message, error) => {

(async () => {
setupLogger({ log: 'debug' });

try {
await yargs
.env('CML')
Expand Down
13 changes: 9 additions & 4 deletions bin/cml/asset/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@ exports.handler = async (opts) => {
opts.native = true;
}

const { file, repo, native, asset: path } = opts;
const cml = new CML({ ...opts, repo: native ? repo : 'cml' });
const { file, asset: path } = opts;
const cml = new CML({ ...opts });
const output = await cml.publish({ ...opts, path });

if (!file) console.log(output);
else await fs.writeFile(file, output);
};

exports.builder = (yargs) => yargs.env('CML_ASSET').options(exports.options);
exports.builder = (yargs) =>
yargs
.env('CML_ASSET')
.option('options', { default: exports.options, hidden: true })
.options(exports.options);

exports.options = kebabcaseKeys({
url: {
Expand Down Expand Up @@ -51,7 +55,8 @@ exports.options = kebabcaseKeys({
},
rmWatermark: {
type: 'boolean',
description: 'Avoid CML watermark.'
description: 'Avoid CML watermark.',
telemetryData: 'name'
},
mimeType: {
type: 'string',
Expand Down
6 changes: 5 additions & 1 deletion bin/cml/check/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ exports.handler = async (opts) => {
await cml.checkCreate({ ...opts, report });
};

exports.builder = (yargs) => yargs.env('CML_CHECK').options(exports.options);
exports.builder = (yargs) =>
yargs
.env('CML_CHECK')
.option('options', { default: exports.options, hidden: true })
.options(exports.options);

exports.options = kebabcaseKeys({
token: {
Expand Down
16 changes: 12 additions & 4 deletions bin/cml/comment/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ exports.handler = async (opts) => {
console.log(await cml.commentCreate(opts));
};

exports.builder = (yargs) => yargs.env('CML_COMMENT').options(exports.options);
exports.builder = (yargs) =>
yargs
.env('CML_COMMENT')
.option('options', { default: exports.options, hidden: true })
.options(exports.options);

exports.options = kebabcaseKeys({
pr: {
Expand All @@ -33,18 +37,21 @@ exports.options = kebabcaseKeys({
},
publish: {
type: 'boolean',
default: true,
description: 'Upload any local images found in the Markdown report'
},
publishUrl: {
type: 'string',
default: 'https://asset.cml.dev',
description: 'Self-hosted image server URL'
description: 'Self-hosted image server URL',
telemetryData: 'name'
},
publishNative: {
type: 'boolean',
alias: 'native',
description:
"Uses driver's native capabilities to upload assets instead of CML's storage; not available on GitHub"
"Uses driver's native capabilities to upload assets instead of CML's storage; not available on GitHub",
telemetryData: 'name'
},
update: {
type: 'boolean',
Expand All @@ -55,6 +62,7 @@ exports.options = kebabcaseKeys({
rmWatermark: {
type: 'boolean',
description:
'Avoid watermark; CML needs a watermark to be able to distinguish CML comments from others'
'Avoid watermark; CML needs a watermark to be able to distinguish CML comments from others',
telemetryData: 'name'
}
});
2 changes: 1 addition & 1 deletion bin/cml/comment/create.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('Comment integration tests', () => {
--commit-sha, --head-sha Commit SHA linked to this comment
[string] [default: \\"HEAD\\"]
--publish Upload any local images found in the Markdown
report [boolean]
report [boolean] [default: true]
--publish-url Self-hosted image server URL
[string] [default: \\"https://asset.cml.dev\\"]
--publish-native, --native Uses driver's native capabilities to upload assets
Expand Down
1 change: 1 addition & 0 deletions bin/cml/pr.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ exports.builder = (yargs) =>
])
)
)
.option('options', { default: options, hidden: true })
.check(({ globpath }) => globpath)
.strict();
6 changes: 5 additions & 1 deletion bin/cml/pr/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ exports.handler = async (opts) => {
console.log(link);
};

exports.builder = (yargs) => yargs.env('CML_PR').options(exports.options);
exports.builder = (yargs) =>
yargs
.env('CML_PR')
.option('options', { default: exports.options, hidden: true })
.options(exports.options);

exports.options = kebabcaseKeys({
md: {
Expand Down
6 changes: 5 additions & 1 deletion bin/cml/repo/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ exports.handler = async (opts) => {
await cml.ci(opts);
};

exports.builder = (yargs) => yargs.env('CML_REPO').options(exports.options);
exports.builder = (yargs) =>
yargs
.env('CML_REPO')
.option('options', { default: exports.options, hidden: true })
.options(exports.options);

exports.options = kebabcaseKeys({
unshallow: {
Expand Down
1 change: 1 addition & 0 deletions bin/cml/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ exports.builder = (yargs) =>
])
)
)
.option('options', { default: options, hidden: true })
.check(() => process.argv.some((arg) => arg.startsWith('-')))
.strict();
37 changes: 19 additions & 18 deletions bin/cml/runner/launch.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,16 +338,8 @@ const run = async (opts) => {
process.on(signal, () => shutdown({ ...opts, reason: signal }));
});

const {
driver,
workdir,
cloud,
labels,
name,
reuse,
reuseIdle,
dockerVolumes
} = opts;
const { workdir, cloud, labels, name, reuse, reuseIdle, dockerVolumes } =
opts;

await cml.repoTokenCheck();

Expand Down Expand Up @@ -375,7 +367,7 @@ const run = async (opts) => {
}

if (reuseIdle) {
if (driver === 'bitbucket') {
if (cml.driver === 'bitbucket') {
throw new Error(
'cml runner flag --reuse-idle is unsupported by bitbucket'
);
Expand All @@ -396,7 +388,7 @@ const run = async (opts) => {
if (dockerVolumes.length && cml.driver !== 'gitlab')
winston.warn('Parameters --docker-volumes is only supported in gitlab');

if (driver === 'github')
if (cml.driver === 'github')
winston.warn(
'Github Actions timeout has been updated from 72h to 35 days. Update your workflow accordingly to be able to restart it automatically.'
);
Expand Down Expand Up @@ -426,7 +418,11 @@ exports.handler = async (opts) => {
}
};

exports.builder = (yargs) => yargs.env('CML_RUNNER').options(exports.options);
exports.builder = (yargs) =>
yargs
.env('CML_RUNNER')
.option('options', { default: exports.options, hidden: true })
.options(exports.options);

exports.options = kebabcaseKeys({
labels: {
Expand Down Expand Up @@ -462,13 +458,15 @@ exports.options = kebabcaseKeys({
type: 'boolean',
conflicts: ['single', 'reuseIdle'],
description:
"Don't launch a new runner if an existing one has the same name or overlapping labels"
"Don't launch a new runner if an existing one has the same name or overlapping labels",
telemetryData: 'name'
},
reuseIdle: {
type: 'boolean',
conflicts: ['reuse', 'single'],
description:
"Creates a new runner only if the matching labels don't exist or are already busy"
"Creates a new runner only if the matching labels don't exist or are already busy",
telemetryData: 'name'
},
workdir: {
type: 'string',
Expand All @@ -484,7 +482,8 @@ exports.options = kebabcaseKeys({
cloud: {
type: 'string',
choices: ['aws', 'azure', 'gcp', 'kubernetes'],
description: 'Cloud to deploy the runner'
description: 'Cloud to deploy the runner',
telemetryData: 'full'
},
cloudRegion: {
type: 'string',
Expand Down Expand Up @@ -537,12 +536,14 @@ exports.options = kebabcaseKeys({
type: 'number',
default: -1,
description:
'Maximum spot instance bidding price in USD. Defaults to the current spot bidding price'
'Maximum spot instance bidding price in USD. Defaults to the current spot bidding price',
telemetryData: 'name'
},
cloudStartupScript: {
type: 'string',
description:
'Run the provided Base64-encoded Linux shell script during the instance initialization'
'Run the provided Base64-encoded Linux shell script during the instance initialization',
telemetryData: 'name'
},
cloudAwsSecurityGroup: {
type: 'string',
Expand Down
2 changes: 1 addition & 1 deletion bin/cml/tensorboard/connect.e2e.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('tbLink', () => {
error = err;
}

expect(error.message).toBe(`Tensorboard took too long. ${message}`);
expect(error.message).toBe(`Tensorboard took too long`);
});

test('valid url is returned', async () => {
Expand Down
Loading

2 comments on commit 3c34b28

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Comment

CML watermark

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Comment

CML watermark

Please sign in to comment.