Skip to content

Commit e9be72b

Browse files
authored
Merge branch 'master' into no-envars
2 parents a8cc364 + c9ecc0c commit e9be72b

32 files changed

+546
-475
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: CodeQL
2+
3+
on:
4+
pull_request:
5+
paths-ignore:
6+
- '**.md'
7+
- assets/**
8+
schedule:
9+
- cron: '0 0 * * *' # everyday @ 0000 UTC
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref_name }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
analyze:
17+
name: Analyze
18+
runs-on: ubuntu-latest
19+
permissions:
20+
actions: read
21+
contents: read
22+
security-events: write
23+
steps:
24+
- uses: actions/checkout@v3
25+
- uses: github/codeql-action/init@v2
26+
with:
27+
languages: javascript
28+
- uses: github/codeql-action/autobuild@v2
29+
- uses: github/codeql-action/analyze@v2

.github/workflows/gitlab.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ jobs:
66
services:
77
gitlab:
88
image: docker://gitlab/gitlab-ce
9-
ports:
10-
- 8000:8000
9+
ports: ['8000:8000']
1110
env:
1211
GITLAB_OMNIBUS_CONFIG: |
1312
external_url 'http://localhost:8000/gitlab'
@@ -21,8 +20,7 @@ jobs:
2120
}
2221
'
2322
steps:
24-
- name: Checkout repository
25-
uses: actions/checkout@v2
23+
- uses: actions/checkout@v3
2624
- name: Configure credentials
2725
run: |
2826
docker exec ${{ job.services.gitlab.id }} bin/gitlab-rails runner "
@@ -60,8 +58,7 @@ jobs:
6058
--request GET \
6159
| jq -r .id \
6260
| xargs -0 printf "::set-output name=hash::%s"
63-
- name: Install dependencies
64-
run: npm ci
61+
- run: npm ci
6562
- name: Run cml-send-comment
6663
run: |
6764
node bin/cml.js send-comment \

.github/workflows/images.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
on:
22
workflow_call:
33
inputs:
4-
test:
5-
required: false
4+
release:
5+
required: true
66
type: boolean
77
jobs:
88
images:
@@ -27,7 +27,7 @@ jobs:
2727
base: 1
2828
dvc: 2
2929
steps:
30-
- uses: actions/checkout@v2
30+
- uses: actions/checkout@v3
3131
with:
3232
ref: ${{ github.event.pull_request.head.sha || github.ref }}
3333
fetch-depth: 0
@@ -73,7 +73,7 @@ jobs:
7373
)"
7474
echo ::set-output name=tags::"${TAGS//$'\n'/'%0A'}"
7575
- uses: docker/setup-buildx-action@v1
76-
- uses: actions/cache@v2
76+
- uses: actions/cache@v3
7777
with:
7878
path: /tmp/.buildx-cache
7979
key:
@@ -94,7 +94,7 @@ jobs:
9494
- uses: docker/build-push-action@v2
9595
with:
9696
push:
97-
${{ github.event_name == 'push' || github.event_name == 'schedule'
97+
${{ inputs.release || github.event_name == 'push' || github.event_name == 'schedule'
9898
|| github.event_name == 'workflow_dispatch' }}
9999
context: ./
100100
file: ./Dockerfile

.github/workflows/release.yml

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,32 @@ jobs:
1515
if: github.event_name == 'workflow_dispatch'
1616
runs-on: ubuntu-latest
1717
steps:
18-
- uses: actions/checkout@v2
18+
- uses: actions/checkout@v3
1919
- run: |
2020
git config --global user.name Olivaw[bot]
2121
git config --global user.email 64868532+iterative-olivaw@users.noreply.github.com
2222
git checkout -b bump/$(npm version ${{ github.event.inputs.bump }})
23-
git push --set-upstream origin --follow-tags HEAD
23+
git push --set-upstream origin HEAD
2424
gh pr create --title "Bump version to $(git describe --tags)" --body "Approve me 🤖"
25-
gh pr merge --squash --auto
25+
gh pr merge --auto --squash
2626
env:
2727
GITHUB_TOKEN: ${{ secrets.ADMIN_GITHUB_TOKEN }}
2828
release:
2929
if: github.event.pull_request.merged && startsWith(github.head_ref, 'bump/')
3030
runs-on: ubuntu-latest
3131
steps:
32-
- uses: actions/checkout@v2
33-
- run:
34-
gh release create --generate-notes {--title=CML\ ,}$(basename ${{
35-
github.head_ref }})
32+
- uses: actions/checkout@v3
33+
- run: >
34+
gh release create
35+
--target ${{ github.event.pull_request.merge_commit_sha }}
36+
{--title=CML\ ,}$(basename ${{ github.head_ref }})
37+
--generate-notes
38+
--draft
3639
env:
3740
GITHUB_TOKEN: ${{ secrets.ADMIN_GITHUB_TOKEN }}
41+
package:
42+
needs: release
43+
secrets: inherit
44+
uses: ./.github/workflows/test-deploy.yml
45+
with:
46+
release: true

.github/workflows/test-deploy.yml

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
name: Test & Deploy
22
on:
3-
schedule:
4-
- cron: '0 8 * * 1' # M H d m w (Mondays at 8:00)
5-
release:
6-
types: [created]
73
pull_request_target:
84
workflow_dispatch:
5+
workflow_call:
6+
inputs:
7+
release:
8+
required: true
9+
type: boolean
10+
schedule:
11+
- cron: '0 8 * * 1' # M H d m w (Mondays at 8:00)
912
jobs:
1013
authorize:
1114
environment:
@@ -22,13 +25,13 @@ jobs:
2225
- uses: actions/checkout@v3
2326
with:
2427
ref: ${{ github.event.pull_request.head.sha || github.ref }}
25-
- name: check that npm lock file is on version 2
28+
- name: npm lock file is v2
2629
run: jq --exit-status .lockfileVersion==2 < package-lock.json
2730
lint:
2831
needs: authorize
2932
runs-on: ubuntu-latest
3033
steps:
31-
- uses: actions/checkout@v2
34+
- uses: actions/checkout@v3
3235
with:
3336
ref: ${{ github.event.pull_request.head.sha || github.ref }}
3437
- uses: actions/setup-node@v2
@@ -38,7 +41,7 @@ jobs:
3841
needs: authorize
3942
runs-on: ubuntu-latest
4043
steps:
41-
- uses: actions/checkout@v2
44+
- uses: actions/checkout@v3
4245
with:
4346
ref: ${{ github.event.pull_request.head.sha || github.ref }}
4447
- uses: actions/setup-node@v2
@@ -69,7 +72,7 @@ jobs:
6972
system: [ubuntu, macos, windows]
7073
runs-on: ${{ matrix.system }}-latest
7174
steps:
72-
- uses: actions/checkout@v2
75+
- uses: actions/checkout@v3
7376
with:
7477
ref: ${{ github.event.pull_request.head.sha || github.ref }}
7578
- if: matrix.system == 'windows'
@@ -91,54 +94,35 @@ jobs:
9194
needs: [lint, test, test-os]
9295
runs-on: ubuntu-latest
9396
steps:
94-
- uses: actions/checkout@v2
97+
- uses: actions/checkout@v3
9598
with:
9699
ref: ${{ github.event.pull_request.head.sha || github.ref }}
97100
- uses: actions/setup-node@v2
98101
with:
99102
registry-url: https://registry.npmjs.org
100103
- run: npm install
101-
- run:
102-
npm ${{ github.event_name == 'release' && 'publish' || 'publish
103-
--dry-run' }}
104+
- run: npm ${{ inputs.release && 'publish' || 'publish --dry-run' }}
104105
env:
105106
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
106-
- name: install ldid
107-
run: |
107+
- run: |
108108
sudo apt install --yes libplist-dev
109-
git clone --branch v2.1.5 git://git.saurik.com/ldid.git
109+
git clone --branch v2.1.5 git://git.saurik.com/ldid.git
110110
sudo g++ -pipe -o /usr/bin/ldid ldid/ldid.cpp -I. -x c ldid/{lookup2.c,sha1.h} -lplist -lcrypto
111-
- id: build
112-
name: build
113-
run: |
114-
echo ::set-output name=tag::${GITHUB_REF#refs/tags/}
111+
- run: |
115112
cp node_modules/@npcz/magic/dist/magic.mgc assets/magic.mgc
116113
npx --yes pkg --no-bytecode --public-packages "*" --public package.json
117-
rm assets/magic.mgc
118-
for cmd in '' runner publish pr; do
119-
build/cml-linux-x64 $cmd --version
120-
done
114+
for cmd in '' runner publish pr; do build/cml-linux-x64 $cmd --version; done
121115
cp build/cml-linux{-x64,}
122116
cp build/cml-macos{-x64,}
123-
- uses: softprops/action-gh-release@v1
124-
if: github.event_name == 'release'
125-
with:
126-
files: |
127-
build/cml-alpine-arm64
128-
build/cml-alpine-x64
129-
build/cml-linux-arm64
130-
build/cml-linuxstatic-arm64
131-
build/cml-linuxstatic-x64
132-
build/cml-linux-x64
133-
build/cml-linux
134-
build/cml-macos-arm64
135-
build/cml-macos-x64
136-
build/cml-macos
137-
build/cml-win-arm64.exe
138-
build/cml-win-x64.exe
117+
- if: inputs.release
118+
run:
119+
find build -type f | xargs gh release upload $(basename ${{
120+
github.head_ref }})
139121
env:
140122
GITHUB_TOKEN: ${{ secrets.TEST_GITHUB_TOKEN }}
141123
images:
142124
needs: packages
143125
secrets: inherit
144126
uses: ./.github/workflows/images.yml
127+
with:
128+
release: ${{ inputs.release || false }}

.github/workflows/trigger-external.yml

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,20 @@ on:
77
type: string
88
required: true
99
release:
10-
types:
11-
- published
10+
types: [published]
1211
pull_request:
13-
branches:
14-
- master
12+
branches: [master]
1513
jobs:
1614
pr:
1715
if: ${{ github.event_name == 'pull_request' }}
1816
runs-on: ubuntu-latest
1917
strategy:
2018
matrix:
21-
repos:
22-
- cml-playground
19+
repos: [cml-playground]
2320
steps:
2421
- name: Trigger external actions
2522
run: |
26-
curl --silent --show-error \
27-
--request POST \
23+
curl --silent --show-error --request POST \
2824
--header "Authorization: token ${{ secrets.TEST_GITHUB_TOKEN }}" \
2925
--header "Accept: application/vnd.github.v3+json" \
3026
--url "https://api.github.com/repos/iterative/${{ matrix.repos }}/dispatches" \
@@ -36,13 +32,11 @@ jobs:
3632
runs-on: ubuntu-latest
3733
strategy:
3834
matrix:
39-
repos:
40-
- cml-playground
35+
repos: [cml-playground]
4136
steps:
4237
- name: Trigger external actions
4338
run: |
44-
curl --silent --show-error \
45-
--request POST \
39+
curl --silent --show-error --request POST \
4640
--header "Authorization: token ${{ secrets.TEST_GITHUB_TOKEN }}" \
4741
--header "Accept: application/vnd.github.v3+json" \
4842
--url "https://api.github.com/repos/iterative/${{ matrix.repos }}/dispatches" \

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ terraform.*
99
!terraform.test.js
1010
crash.log
1111
/build
12+
/coverage

bin/cml.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ const handleError = (message, error) => {
157157
const event = { ...telemetryEvent, error: err.message };
158158
await send({ event });
159159
}
160-
winston.error({ err });
160+
winston.error(err);
161161
process.exit(1);
162162
}
163163
})();

bin/cml/asset/publish.e2e.test.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
const fs = require('fs');
2+
const { exec } = require('../../../src/utils');
3+
4+
describe('CML e2e', () => {
5+
test('cml publish assets/logo.png --md', async () => {
6+
const output = await exec(`node ./bin/cml.js publish assets/logo.png --md`);
7+
8+
expect(output.startsWith('![](')).toBe(true);
9+
});
10+
11+
test('cml publish assets/logo.png', async () => {
12+
const output = await exec(`node ./bin/cml.js publish assets/logo.png`);
13+
14+
expect(output.startsWith('https://')).toBe(true);
15+
});
16+
17+
test('cml publish assets/logo.pdf --md', async () => {
18+
const title = 'this is awesome';
19+
const output = await exec(
20+
`node ./bin/cml.js publish assets/logo.pdf --md --title '${title}'`
21+
);
22+
23+
expect(output.startsWith(`[${title}](`)).toBe(true);
24+
});
25+
26+
test('cml publish assets/logo.pdf', async () => {
27+
const output = await exec(`node ./bin/cml.js publish assets/logo.pdf`);
28+
29+
expect(output.startsWith('https://')).toBe(true);
30+
});
31+
32+
test('cml publish assets/test.svg --md', async () => {
33+
const title = 'this is awesome';
34+
const output = await exec(
35+
`node ./bin/cml.js publish assets/test.svg --md --title '${title}'`
36+
);
37+
38+
expect(output.startsWith('![](') && output.endsWith(`${title}")`)).toBe(
39+
true
40+
);
41+
});
42+
43+
test('cml publish assets/test.svg', async () => {
44+
const output = await exec(`node ./bin/cml.js publish assets/test.svg`);
45+
46+
expect(output.startsWith('https://')).toBe(true);
47+
});
48+
49+
test('cml publish assets/logo.pdf to file', async () => {
50+
const file = `cml-publish-test.md`;
51+
52+
await exec(`node ./bin/cml.js publish assets/logo.pdf --file ${file}`);
53+
54+
expect(fs.existsSync(file)).toBe(true);
55+
await fs.promises.unlink(file);
56+
});
57+
58+
test('cml publish assets/vega-lite.json', async () => {
59+
const output = await exec(
60+
`node ./bin/cml.js publish --mime-type=application/json assets/vega-lite.json`
61+
);
62+
63+
expect(output.startsWith('https://')).toBe(true);
64+
expect(output.includes('cml=json')).toBe(true);
65+
});
66+
67+
test('cml publish assets/test.svg in Gitlab storage', async () => {
68+
const { TEST_GITLAB_REPO: repo, TEST_GITLAB_TOKEN: token } = process.env;
69+
70+
const output = await exec(
71+
`node ./bin/cml.js publish --repo=${repo} --token=${token} --gitlab-uploads assets/test.svg`
72+
);
73+
74+
expect(output.startsWith('https://')).toBe(true);
75+
});
76+
77+
test('cml publish /nonexistent produces file error', async () => {
78+
await expect(
79+
exec('node ./bin/cml.js publish /nonexistent')
80+
).rejects.toThrowError('ENOENT');
81+
});
82+
});

0 commit comments

Comments
 (0)