Skip to content

Commit 95e82e8

Browse files
Merge pull request #75 from JarvusInnovations/develop
Release: v0.21.0
2 parents ede50c6 + 2ae9aaa commit 95e82e8

File tree

12 files changed

+8872
-37
lines changed

12 files changed

+8872
-37
lines changed

.github/workflows/publish-npm.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Publish npm package
2+
3+
on:
4+
push:
5+
tags: [ 'v*' ]
6+
7+
8+
jobs:
9+
publish-npm:
10+
runs-on: ubuntu-latest
11+
steps:
12+
13+
- uses: actions/checkout@v2
14+
15+
- name: Place tag in environment
16+
run: |
17+
echo "SOURCE_TAG=${GITHUB_REF:10}" >> $GITHUB_ENV
18+
19+
- name: Setting package.json version
20+
run: npm version --no-git-tag-version "${SOURCE_TAG#v}"
21+
22+
- uses: actions/setup-node@v1
23+
with:
24+
node-version: '14.x'
25+
registry-url: 'https://registry.npmjs.org'
26+
27+
- run: cd backend && npm install
28+
29+
- run: cd backend && npm publish
30+
env:
31+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/docs-site.yml renamed to .github/workflows/publish-website.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
name: Docs Site
1+
name: Publish Website
22

33
on:
44
push:
55
branches: [ master ]
66

7+
78
jobs:
8-
docs-projection:
9+
publish-website:
910
runs-on: ubuntu-latest
1011
steps:
1112
- name: 'Projecting docs-site holobranch onto gh-pages'
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: 'Release: Deploy PR'
2+
3+
on:
4+
pull_request:
5+
branches: [ master ]
6+
types: [ closed ]
7+
8+
env:
9+
GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}
10+
11+
jobs:
12+
release-deploy:
13+
14+
if: github.event.pull_request.merged == true # only run on PR merge
15+
runs-on: ubuntu-latest
16+
steps:
17+
18+
- name: Grab PR Title
19+
run: |
20+
set -e
21+
22+
PR_TITLE=$(jq -r ".pull_request.title" $GITHUB_EVENT_PATH)
23+
PR_BODY=$(jq -r ".pull_request.body" $GITHUB_EVENT_PATH)
24+
RELEASE_TAG=$(echo "${PR_TITLE}" | grep -oP "(?<=^Release: )v\d+\.\d+\.\d+(-rc\.\d+)?$")
25+
26+
if [[ "${RELEASE_TAG}" =~ -rc\.[0-9]+$ ]]; then
27+
RELEASE_PRERELEASE=true
28+
else
29+
RELEASE_PRERELEASE=false
30+
fi
31+
32+
echo "PR_TITLE=${PR_TITLE}" >> $GITHUB_ENV
33+
echo "RELEASE_TAG=${RELEASE_TAG}" >> $GITHUB_ENV
34+
echo "RELEASE_PRERELEASE=${RELEASE_PRERELEASE}" >> $GITHUB_ENV
35+
36+
echo 'PR_BODY<<END_OF_PR_BODY' >> $GITHUB_ENV
37+
echo "${PR_BODY}" >> $GITHUB_ENV
38+
echo 'END_OF_PR_BODY' >> $GITHUB_ENV
39+
40+
- name: Create Release
41+
id: create_release
42+
uses: actions/create-release@v1
43+
with:
44+
tag_name: '${{ env.RELEASE_TAG }}'
45+
release_name: '${{ env.RELEASE_TAG }}'
46+
body: '${{ env.PR_BODY }}'
47+
draft: false
48+
prerelease: ${{ env.RELEASE_PRERELEASE }}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
name: 'Release: Prepare PR'
2+
3+
on:
4+
push:
5+
branches: [ develop ]
6+
7+
env:
8+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9+
RELEASE_BRANCH: master
10+
11+
jobs:
12+
release-prepare:
13+
14+
runs-on: ubuntu-latest
15+
steps:
16+
17+
- uses: actions/checkout@v2
18+
with:
19+
fetch-depth: 0
20+
21+
# - uses: mxschmitt/action-tmate@v3
22+
23+
- name: Create/update pull request
24+
run: |
25+
# get latest release tag
26+
latest_release=$(git describe --tags --abbrev=0 origin/${{ env.RELEASE_BRANCH }})
27+
latest_release_bumped=$(echo $latest_release | awk -F. -v OFS=. '{$NF++;print}')
28+
29+
30+
# create or update PR
31+
pr_body="$(cat <<EOF
32+
Release: ${latest_release_bumped}
33+
34+
## Improvements
35+
36+
## Technical
37+
38+
EOF
39+
)"
40+
41+
pr_number=$(hub pr list -h develop -f '%I')
42+
43+
if [ -n "${pr_number}" ]; then
44+
echo "Updating PR #${pr_number}"
45+
existing_comment_id=$(hub api "/repos/${GITHUB_REPOSITORY}/issues/${pr_number}/comments" | jq '.[] | select(.user.login=="github-actions[bot]") | .id')
46+
else
47+
echo "Opening PR"
48+
hub pull-request -b "${RELEASE_BRANCH}" -h develop -F <(echo "${pr_body}") > /tmp/pr.json
49+
pr_number=$(hub pr list -h develop -f '%I')
50+
echo "Opened PR #${pr_number}"
51+
fi
52+
53+
54+
# build changelog
55+
commits=$(
56+
git log \
57+
--first-parent \
58+
--reverse \
59+
--format="%H" \
60+
"origin/${RELEASE_BRANCH}..develop"
61+
)
62+
63+
changelog=()
64+
65+
while read -r commit; do
66+
subject="$(git show -s --format=%s "${commit}")"
67+
line=""
68+
69+
if [[ "${subject}" =~ Merge\ pull\ request\ \#([0-9]+) ]]; then
70+
line="$(hub pr show -f '%t [%i] @%au' "${BASH_REMATCH[1]}" || true)"
71+
fi
72+
73+
if [ -z "${line}" ]; then
74+
author="$(hub api "/repos/${GITHUB_REPOSITORY}/commits/${commit}" -H Accept:application/vnd.github.v3+json | jq -r '.author.login')"
75+
if [ -n "${author}" ]; then
76+
author="@${author}"
77+
else
78+
author="$(git show -s --format=%ae "${commit}")"
79+
fi
80+
81+
line="${subject} ${author}"
82+
fi
83+
84+
# move ticket number prefix into to existing square brackets at end
85+
line="$(echo "${line}" | perl -pe 's/^([A-Z]+-[0-9]+):?\s*(.*?)\s*\[([^]]+)\]\s*(\S+)$/\2 [\3, \1] \4/')"
86+
87+
# move ticket number prefix into to new square brackets at end
88+
line="$(echo "${line}" | perl -pe 's/^([A-Z]+-[0-9]+):?\s*(.*?)\s*(\S+)$/\2 [\1] \3/')"
89+
90+
# combine doubled square brackets at the end
91+
line="$(echo "${line}" | perl -pe 's/^\s*(.*?)\s*\[([A-Z]+-[0-9]+)\]\s*\[([^]]+)\]\s*(\S+)$/\1 [\3, \2] \4/')"
92+
93+
changelog+=("- ${line}")
94+
done <<< "${commits}"
95+
96+
97+
# create or update comment
98+
comment_body="$(cat <<EOF
99+
## Changelog
100+
101+
\`\`\`markdown
102+
$(IFS=$'\n'; echo "${changelog[*]}")
103+
\`\`\`
104+
EOF
105+
)"
106+
107+
if [ -n "${existing_comment_id}" ]; then
108+
echo "Updating comment #${existing_comment_id}"
109+
hub api "/repos/${GITHUB_REPOSITORY}/issues/comments/${existing_comment_id}" -f body="${comment_body}"
110+
else
111+
echo "Creating comment"
112+
hub api "/repos/${GITHUB_REPOSITORY}/issues/${pr_number}/comments" -f body="${comment_body}"
113+
fi
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: 'Release: Validate PR'
2+
3+
on:
4+
pull_request:
5+
branches: [ master ]
6+
types: [ opened, edited, reopened, synchronize ]
7+
8+
env:
9+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
10+
11+
jobs:
12+
release-validate:
13+
14+
runs-on: ubuntu-latest
15+
steps:
16+
17+
- name: Grab PR Title
18+
run: |
19+
set -e
20+
21+
PR_TITLE=$(jq -r ".pull_request.title" $GITHUB_EVENT_PATH)
22+
23+
# check title format and extract tag
24+
if [[ "${PR_TITLE}" =~ ^Release:\ v[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$ ]]; then
25+
RELEASE_TAG="${PR_TITLE:9}"
26+
echo "RELEASE_TAG=${RELEASE_TAG}" >> $GITHUB_ENV
27+
else
28+
echo 'PR title must match format "Release: vX.Y.Z(-rc.#)?"'
29+
exit 1
30+
fi
31+
32+
# check that tag doesn't exist
33+
if git ls-remote --exit-code origin "refs/tags/${RELEASE_TAG}"; then
34+
echo "The PR title's version exists already"
35+
exit 1
36+
fi

backend/commands/upsert.js

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const fs = require('fs');
22
const TOML = require('@iarna/toml');
33
const { parse: csvParse } = require('fast-csv');
4+
const deepmerge = require('deepmerge');
45

56
const inputFormats = {
67
json: readJsonFile,
@@ -46,6 +47,11 @@ exports.builder = {
4647
type: 'boolean',
4748
default: false,
4849
},
50+
'patch-existing': {
51+
describe: 'For existing records, patch in provided values so that additional properties not included in the input are preserved',
52+
type: 'boolean',
53+
default: false,
54+
},
4955
};
5056

5157
exports.handler = async function upsert({
@@ -57,6 +63,7 @@ exports.handler = async function upsert({
5763
encoding,
5864
attachments = null,
5965
deleteMissing,
66+
patchExisting,
6067
...argv
6168
}) {
6269
const logger = require('../lib/logger.js');
@@ -96,7 +103,13 @@ exports.handler = async function upsert({
96103

97104

98105
// clear sheet
106+
let inputSheet = sheet;
107+
99108
if (deleteMissing) {
109+
// re-open input sheet
110+
inputSheet = await sheet.clone();
111+
112+
// clear target sheet
100113
await sheet.clear();
101114
}
102115

@@ -113,8 +126,28 @@ exports.handler = async function upsert({
113126

114127

115128
// upsert record(s) into sheet
116-
for await (const inputRecord of inputRecords) {
117-
const { blob: outputBlob, path: outputPath } = await sheet.upsert(inputRecord);
129+
for await (let inputRecord of inputRecords) {
130+
131+
if (patchExisting) {
132+
// TODO: move more of this logic inside Sheet class
133+
134+
// fetch existing record from inputSheet
135+
const inputRecordPath = await inputSheet.pathForRecord(await inputSheet.normalizeRecord(inputRecord));
136+
137+
if (inputRecordPath) {
138+
const { root: inputSheetRoot } = await inputSheet.getCachedConfig();
139+
140+
// existing record find, merge
141+
const existingBlob = await inputSheet.dataTree.getChild(`${path.join(inputSheetRoot, inputRecordPath)}.toml`);
142+
143+
if (existingBlob) {
144+
const existingRecord = await inputSheet.readRecord(existingBlob);
145+
inputRecord = deepmerge(inputRecord, existingRecord);
146+
}
147+
}
148+
}
149+
150+
const { blob: outputBlob, path: outputPath } = await sheet.upsert(inputRecord, { patchExisting });
118151
console.log(`${outputBlob.hash}\t${outputPath}`);
119152

120153
if (attachments) {

backend/lib/Sheet.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,15 @@ class Sheet extends Configurable
277277
return this.dataTree.writeChild(root, this.dataTree.repo.createTree());
278278
}
279279

280+
async clone () {
281+
return new Sheet({
282+
workspace: this.workspace,
283+
name: this.name,
284+
dataTree: await this.dataTree.clone(),
285+
configPath: this.configPath,
286+
});
287+
}
288+
280289
async upsert (record) {
281290
const {
282291
root: sheetRoot,

0 commit comments

Comments
 (0)