Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into enrich-analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
0x2b3bfa0 authored Oct 11, 2022
2 parents 5abcd7b + c1ec211 commit 16cf7e5
Show file tree
Hide file tree
Showing 30 changed files with 472 additions and 417 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
12 changes: 9 additions & 3 deletions .github/workflows/images.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
on: workflow_call
on:
workflow_call:
inputs:
release:
required: true
type: boolean
jobs:
images:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -89,8 +94,9 @@ jobs:
- uses: docker/build-push-action@v2
with:
push:
${{ github.event_name == 'push' || github.event_name == 'schedule'
|| github.event_name == 'workflow_dispatch' }}
${{ inputs.release || github.event_name == 'push' ||
github.event_name == 'schedule' || github.event_name ==
'workflow_dispatch' }}
context: ./
file: ./Dockerfile
tags: |
Expand Down
11 changes: 7 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
git config --global user.name Olivaw[bot]
git config --global user.email [email protected]
git checkout -b bump/$(npm version ${{ github.event.inputs.bump }})
git push --set-upstream origin --follow-tags HEAD
git push --set-upstream origin HEAD
gh pr create --title "Bump version to $(git describe --tags)" --body "Approve me 🤖"
gh pr merge --auto --squash
env:
Expand All @@ -30,12 +30,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run:
gh release create --draft --generate-notes {--title=CML\ ,}$(basename
${{ github.head_ref }})
- run: >
gh release create --target ${{
github.event.pull_request.merge_commit_sha }} {--title=CML\
,}$(basename ${{ github.head_ref }}) --generate-notes --draft
env:
GITHUB_TOKEN: ${{ secrets.ADMIN_GITHUB_TOKEN }}
package:
needs: release
secrets: inherit
uses: ./.github/workflows/test-deploy.yml
with:
release: true
43 changes: 14 additions & 29 deletions .github/workflows/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ on:
pull_request_target:
workflow_dispatch:
workflow_call:
inputs:
release:
required: true
type: boolean
schedule:
- cron: '0 8 * * 1' # M H d m w (Mondays at 8:00)
jobs:
Expand Down Expand Up @@ -97,47 +101,28 @@ jobs:
with:
registry-url: https://registry.npmjs.org
- run: npm install
- run:
npm ${{ github.event_name == 'workflow_call' && 'publish' || 'publish
--dry-run' }}
- run: npm ${{ inputs.release && 'publish' || 'publish --dry-run' }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: install ldid
run: |
- 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/}
- 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: github.event_name == 'workflow_call'
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 || false }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ terraform.*
!terraform.test.js
crash.log
/build
/coverage
82 changes: 82 additions & 0 deletions bin/cml/asset/publish.e2e.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
const fs = require('fs');
const { exec } = require('../../../src/utils');

describe('CML e2e', () => {
test('cml publish assets/logo.png --md', async () => {
const output = await exec(`node ./bin/cml.js publish assets/logo.png --md`);

expect(output.startsWith('![](')).toBe(true);
});

test('cml publish assets/logo.png', async () => {
const output = await exec(`node ./bin/cml.js publish assets/logo.png`);

expect(output.startsWith('https://')).toBe(true);
});

test('cml publish assets/logo.pdf --md', async () => {
const title = 'this is awesome';
const output = await exec(
`node ./bin/cml.js publish assets/logo.pdf --md --title '${title}'`
);

expect(output.startsWith(`[${title}](`)).toBe(true);
});

test('cml publish assets/logo.pdf', async () => {
const output = await exec(`node ./bin/cml.js publish assets/logo.pdf`);

expect(output.startsWith('https://')).toBe(true);
});

test('cml publish assets/test.svg --md', async () => {
const title = 'this is awesome';
const output = await exec(
`node ./bin/cml.js publish assets/test.svg --md --title '${title}'`
);

expect(output.startsWith('![](') && output.endsWith(`${title}")`)).toBe(
true
);
});

test('cml publish assets/test.svg', async () => {
const output = await exec(`node ./bin/cml.js publish assets/test.svg`);

expect(output.startsWith('https://')).toBe(true);
});

test('cml publish assets/logo.pdf to file', async () => {
const file = `cml-publish-test.md`;

await exec(`node ./bin/cml.js publish assets/logo.pdf --file ${file}`);

expect(fs.existsSync(file)).toBe(true);
await fs.promises.unlink(file);
});

test('cml publish assets/vega-lite.json', async () => {
const output = await exec(
`node ./bin/cml.js publish --mime-type=application/json assets/vega-lite.json`
);

expect(output.startsWith('https://')).toBe(true);
expect(output.includes('cml=json')).toBe(true);
});

test('cml publish assets/test.svg in Gitlab storage', async () => {
const { TEST_GITLAB_REPO: repo, TEST_GITLAB_TOKEN: token } = process.env;

const output = await exec(
`node ./bin/cml.js publish --repo=${repo} --token=${token} --gitlab-uploads assets/test.svg`
);

expect(output.startsWith('https://')).toBe(true);
});

test('cml publish /nonexistent produces file error', async () => {
await expect(
exec('node ./bin/cml.js publish /nonexistent')
).rejects.toThrowError('ENOENT');
});
});
4 changes: 2 additions & 2 deletions bin/cml/asset/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ 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);
Expand Down
81 changes: 1 addition & 80 deletions bin/cml/asset/publish.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const fs = require('fs');
const { exec } = require('../../../src/utils');

describe('CML e2e', () => {
describe('CML cli test', () => {
test('cml publish --help', async () => {
const output = await exec(`node ./bin/cml.js publish --help`);

Expand Down Expand Up @@ -29,82 +28,4 @@ describe('CML e2e', () => {
--mime-type MIME type [string] [default: infer from the file contents]"
`);
});

test('cml publish assets/logo.png --md', async () => {
const output = await exec(`node ./bin/cml.js publish assets/logo.png --md`);

expect(output.startsWith('![](')).toBe(true);
});

test('cml publish assets/logo.png', async () => {
const output = await exec(`node ./bin/cml.js publish assets/logo.png`);

expect(output.startsWith('https://')).toBe(true);
});

test('cml publish assets/logo.pdf --md', async () => {
const title = 'this is awesome';
const output = await exec(
`node ./bin/cml.js publish assets/logo.pdf --md --title '${title}'`
);

expect(output.startsWith(`[${title}](`)).toBe(true);
});

test('cml publish assets/logo.pdf', async () => {
const output = await exec(`node ./bin/cml.js publish assets/logo.pdf`);

expect(output.startsWith('https://')).toBe(true);
});

test('cml publish assets/test.svg --md', async () => {
const title = 'this is awesome';
const output = await exec(
`node ./bin/cml.js publish assets/test.svg --md --title '${title}'`
);

expect(output.startsWith('![](') && output.endsWith(`${title}")`)).toBe(
true
);
});

test('cml publish assets/test.svg', async () => {
const output = await exec(`node ./bin/cml.js publish assets/test.svg`);

expect(output.startsWith('https://')).toBe(true);
});

test('cml publish assets/logo.pdf to file', async () => {
const file = `cml-publish-test.md`;

await exec(`node ./bin/cml.js publish assets/logo.pdf --file ${file}`);

expect(fs.existsSync(file)).toBe(true);
await fs.promises.unlink(file);
});

test('cml publish assets/vega-lite.json', async () => {
const output = await exec(
`node ./bin/cml.js publish --mime-type=application/json assets/vega-lite.json`
);

expect(output.startsWith('https://')).toBe(true);
expect(output.includes('cml=json')).toBe(true);
});

test('cml publish assets/test.svg in Gitlab storage', async () => {
const { TEST_GITLAB_REPO: repo, TEST_GITLAB_TOKEN: token } = process.env;

const output = await exec(
`node ./bin/cml.js publish --repo=${repo} --token=${token} --gitlab-uploads assets/test.svg`
);

expect(output.startsWith('https://')).toBe(true);
});

test('cml publish /nonexistent produces file error', async () => {
await expect(
exec('node ./bin/cml.js publish /nonexistent')
).rejects.toThrowError('ENOENT');
});
});
32 changes: 32 additions & 0 deletions bin/cml/check/create.e2e.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const { exec } = require('../../../src/utils');
const fs = require('fs').promises;

describe('CML e2e', () => {
const path = 'check.md';

afterEach(async () => {
try {
await fs.unlink(path);
} catch (err) {}
});

test('cml send-github-check', async () => {
const report = `## Test Check Report`;

await fs.writeFile(path, report);
process.env.GITHUB_ACTIONS &&
(await exec(`node ./bin/cml.js send-github-check ${path}`));
});

test('cml send-github-check failure with tile "CML neutral test"', async () => {
const report = `## Hi this check should be neutral`;
const title = 'CML neutral test';
const conclusion = 'neutral';

await fs.writeFile(path, report);
process.env.GITHUB_ACTIONS &&
(await exec(
`node ./bin/cml.js send-github-check ${path} --title "${title}" --conclusion "${conclusion}"`
));
});
});
Loading

4 comments on commit 16cf7e5

@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

@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.