Skip to content

Commit 46bfaa2

Browse files
committed
Further addressing parsing errors
1 parent 457d6da commit 46bfaa2

File tree

3 files changed

+78
-42
lines changed

3 files changed

+78
-42
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,53 @@
11
#!/bin/bash
2-
# 70_publish_outcomes.sh
3-
# Post a completion comment to the Jira issue associated with this repository.
2+
# 70_publish_comment.sh
3+
# Post a status comment to the Jira issue associated with this repository.
44
# Ticket resolved in order: $jiraticket env var → config.yml → openICPSR directory detection.
55
#
6-
# Usage: 70_publish_outcomes.sh [pipeline-name]
6+
# Usage: 70_publish_comment.sh [pipeline-name] [status]
77
# pipeline-name Optional. Name of the Bitbucket custom pipeline (e.g., "1-populate-from-icpsr").
88
# No Bitbucket built-in variable exposes this; pass it explicitly from the pipeline.
9+
# status Optional. Status of the pipeline: "started" or "completed" (default: "completed").
910

1011
_pipeline="${1:-}"
12+
_status="${2:-completed}"
1113

1214
# Detect Python command
1315
if command -v python3.12 &>/dev/null; then
1416
PYTHON_CMD="python3.12"
1517
elif command -v python3 &>/dev/null; then
1618
PYTHON_CMD="python3"
1719
else
18-
echo "70_publish_outcomes: no Python 3 found, skipping Jira notification"
20+
echo "70_publish_comment: no Python 3 found, skipping Jira notification"
1921
exit 0
2022
fi
2123

24+
# Set emoji based on status
25+
case "$_status" in
26+
started)
27+
_emoji="🚀"
28+
_verb="started"
29+
;;
30+
completed)
31+
_emoji=""
32+
_verb="completed"
33+
;;
34+
*)
35+
_emoji="ℹ️"
36+
_verb="$_status"
37+
;;
38+
esac
39+
2240
_jira="${jiraticket:-}"
23-
echo "70_publish_outcomes: jiraticket from environment: '${_jira}'"
41+
echo "70_publish_comment: jiraticket from environment: '${_jira}'"
2442

2543
# Fall back to config.yml
2644
if [ -z "$_jira" ]; then
2745
if [ -f config.yml ] && [ -f tools/parse_yaml.sh ]; then
2846
. ./tools/parse_yaml.sh
2947
_jira=$(parse_yaml config.yml | grep '^jiraticket=' | sed 's/jiraticket=//;s/"//g')
30-
echo "70_publish_outcomes: jiraticket from config.yml: '${_jira}'"
48+
echo "70_publish_comment: jiraticket from config.yml: '${_jira}'"
3149
else
32-
echo "70_publish_outcomes: config.yml or parse_yaml.sh not found, skipping config.yml lookup"
50+
echo "70_publish_comment: config.yml or parse_yaml.sh not found, skipping config.yml lookup"
3351
fi
3452
fi
3553

@@ -38,21 +56,21 @@ if [ -z "$_jira" ]; then
3856
_icpsr=$(find . -maxdepth 1 -mindepth 1 -type d -name '[123][0-9][0-9][0-9][0-9][0-9]' 2>/dev/null \
3957
| head -1 | xargs -I{} basename {} 2>/dev/null || true)
4058
if [ -n "$_icpsr" ]; then
41-
echo "70_publish_outcomes: detected openICPSR directory '${_icpsr}', looking up Jira ticket"
59+
echo "70_publish_comment: detected openICPSR directory '${_icpsr}', looking up Jira ticket"
4260
_jira=$($PYTHON_CMD tools/jira_find_task_by_icpsr.py "$_icpsr" 2>&1) || true
43-
echo "70_publish_outcomes: jiraticket from lookup: '${_jira}'"
61+
echo "70_publish_comment: jiraticket from lookup: '${_jira}'"
4462
else
45-
echo "70_publish_outcomes: no openICPSR directory found"
63+
echo "70_publish_comment: no openICPSR directory found"
4664
fi
4765
fi
4866

4967
if [ -n "$_jira" ]; then
5068
_url="https://bitbucket.org/$BITBUCKET_WORKSPACE/$BITBUCKET_REPO_SLUG/pipelines/results/$BITBUCKET_BUILD_NUMBER"
51-
echo "70_publish_outcomes: posting completion comment to ${_jira}"
69+
echo "70_publish_comment: posting ${_verb} comment to ${_jira}"
5270
$PYTHON_CMD tools/jira_add_comment.py "$_jira" \
53-
"Bitbucket Pipeline ${_pipeline} completed. Build [#$BITBUCKET_BUILD_NUMBER|$_url]." || true
71+
"${_emoji} Bitbucket Pipeline ${_pipeline} ${_verb}. Build [#$BITBUCKET_BUILD_NUMBER|$_url]." || true
5472
else
55-
echo "70_publish_outcomes: no Jira ticket found, skipping comment"
73+
echo "70_publish_comment: no Jira ticket found, skipping comment"
5674
fi
5775

5876
exit 0

bitbucket-pipelines.yml

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ definitions:
2929
- ./automations/20_commit_code.sh config.yml
3030
- git status
3131
- git push
32-
- ./automations/70_publish_outcomes.sh z-run-stata
32+
- ./automations/70_publish_comment.sh z-run-stata completed
3333

3434
pipelines:
3535
custom:
@@ -88,6 +88,10 @@ pipelines:
8888
- if [ -z $ZenodoID ]; then ZenodoID=$zenodo; fi
8989
- projectID="${openICPSRID}"
9090
- projectID="${projectID:-zenodo-$ZenodoID}"
91+
- if [ -z "$jiraticket" ] && [ -n "${openICPSRID:-}" ]; then jiraticket=$(python3 tools/jira_find_task_by_icpsr.py "$openICPSRID" 2>/dev/null || true); else echo "Jira ticket not set"; fi
92+
- echo "Using Jira case $jiraticket"
93+
- ./tools/update_config.sh
94+
- ./automations/70_publish_comment.sh 1-populate-from-icpsr started
9195
- if [ -d $projectID ]; then \rm -rf $projectID; fi
9296
- if [ ! -z $openICPSRID ]; then python3 tools/download_openicpsr-private.py $openICPSRID; fi
9397
- if [ ! -z $ZenodoID ]; then python3 tools/download_zenodo_draft.py $ZenodoID; fi
@@ -239,12 +243,13 @@ pipelines:
239243
script:
240244
- . ./tools/parse_yaml.sh
241245
- eval $(parse_yaml config.yml)
242-
- if [ -z $openICPSRID ]; then openICPSRID=$openicpsr; fi
243-
- if [ -z $ZenodoID ]; then ZenodoID=$zenodo; fi
246+
- if [ -z $openICPSRID ]; then openICPSRID=$openicpsr; else echo "openICPSRID not set"; fi
247+
- if [ -z $ZenodoID ]; then ZenodoID=$zenodo; else echo "ZenodoID not set"; fi
244248
- projectID="${openICPSRID}"
245249
- projectID="${projectID:-zenodo-$ZenodoID}"
246250
- if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
247-
- if [ -z "$jiraticket" ] && [ -n "${openICPSRID:-}" ]; then jiraticket=$(python3 tools/jira_find_task_by_icpsr.py "$openICPSRID" 2>/dev/null || true); fi
251+
- if [ -z "$jiraticket" ] && [ -n "${openICPSRID:-}" ]; then jiraticket=$(python3 tools/jira_find_task_by_icpsr.py "$openICPSRID" 2>/dev/null || true); else echo "Jira ticket not set"; fi
252+
- echo "Using Jira case $jiraticket"
248253
- ./tools/update_config.sh
249254
- if [ -d cache ]; then ls -lR cache/*; fi
250255
- ls -l generated/*
@@ -261,7 +266,7 @@ pipelines:
261266
- ./automations/20_commit_code.sh config.yml notag
262267
- git status
263268
- git push && git push --tags
264-
- ./automations/70_publish_outcomes.sh 1-populate-from-icpsr
269+
- ./automations/70_publish_comment.sh 1-populate-from-icpsr completed
265270
2-merge-report: #name of this pipeline
266271
- variables: #list variable names under here
267272
- name: jiraticket
@@ -271,7 +276,9 @@ pipelines:
271276
- chmod a+rx automations/*.sh
272277
- ./automations/50_merge-parts.sh
273278
- git push
274-
- ./automations/70_publish_outcomes.sh 2-merge-report
279+
- . ./tools/parse_yaml.sh
280+
- eval $(parse_yaml config.yml)
281+
- ./automations/70_publish_comment.sh 2-merge-report completed
275282
3-split-report: #name of this pipeline
276283
- variables: #list variable names under here
277284
- name: jiraticket
@@ -281,7 +288,9 @@ pipelines:
281288
- chmod a+rx automations/*.sh
282289
- ./automations/51_split-parts.sh
283290
- git push
284-
- ./automations/70_publish_outcomes.sh 3-split-report
291+
- . ./tools/parse_yaml.sh
292+
- eval $(parse_yaml config.yml)
293+
- ./automations/70_publish_comment.sh 3-split-report completed
285294
4-refresh-tools: #name of this pipeline
286295
- step:
287296
name: Refresh the tools in this repository
@@ -290,7 +299,7 @@ pipelines:
290299
- chmod a+rx update_tools.sh
291300
- ./update_tools.sh
292301
- git push
293-
- ./automations/70_publish_outcomes.sh 4-refresh-tools
302+
- ./automations/70_publish_comment.sh 4-refresh-tools completed
294303
5-rename-directory: #name of this pipeline
295304
- variables: #list variable names under here
296305
- name: oldName
@@ -307,7 +316,7 @@ pipelines:
307316
- ./tools/update_config.sh
308317
- ./automations/20_commit_code.sh config.yml notag
309318
- git push
310-
- ./automations/70_publish_outcomes.sh 5-rename-directory
319+
- ./automations/70_publish_comment.sh 5-rename-directory completed
311320
6-convert-eps-pdf: # this can be run to convert EPS and PDF files to PNG
312321
- variables: #list variable names under here
313322
# These do not need to have a value, if "config.yml" is filled out.
@@ -333,11 +342,12 @@ pipelines:
333342
- . ./tools/parse_yaml.sh
334343
- eval $(parse_yaml config.yml)
335344
- chmod a+rx ./automations/*.sh
345+
- ./automations/70_publish_comment.sh 6-convert-eps-pdf started
336346
- docker run --rm -v $(pwd):/imgs --entrypoint=/bin/bash $DockerImg ./automations/52_convert_eps_pdf.sh -p "$path" -e $ProcessEPS -d $ProcessPDF
337347
- git add "$path"
338348
- git commit -m "[skip ci] Converted EPS and PDF to PNG"
339349
- git push
340-
- ./automations/70_publish_outcomes.sh 6-convert-eps-pdf
350+
- ./automations/70_publish_comment.sh 6-convert-eps-pdf completed
341351
7-download-box-manifest: #name of this pipeline
342352
- variables: #list variable names under here
343353
- name: repository_name
@@ -349,13 +359,17 @@ pipelines:
349359
script:
350360
- if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
351361
- chmod a+rx ./automations/*.sh
362+
- . ./tools/parse_yaml.sh
363+
- eval $(parse_yaml config.yml)
364+
- chmod a+rx ./automations/*.sh
365+
- ./automations/70_publish_comment.sh 7-download-box-manifest started
352366
- python3 ./tools/download_box_private.py $repository_name
353367
- ./automations/00_unpack_zip.sh restricted
354368
- ./automations/04_create_manifest.sh restricted restricted
355369
- git add -f generated/*
356370
- git commit -m "[skip ci] Downloaded Box files and created manifests"
357371
- git push
358-
- ./automations/70_publish_outcomes.sh 7-download-box-manifest
372+
- ./automations/70_publish_comment.sh 7-download-box-manifest completed
359373
8-download-sivacor: #name of this pipeline
360374
- variables: #list variable names under here
361375
- name: jiraticket
@@ -373,9 +387,10 @@ pipelines:
373387
- if [ -z "$jiraticket" ]; then jiraticket=$(basename $(pwd)); fi # Determine Jira case from variable, directory name, or config.yml
374388
- 'if [ -z "$jiraticket" ]; then echo "Error: Could not determine Jira case"; exit 1; fi'
375389
- 'echo "Using Jira case: $jiraticket"'
390+
- ./automations/70_publish_comment.sh 8-download-sivacor started
376391
- python3 tools/download_sivacor.py $jiraticket # Run the SIVACOR download script
377392
- git push -u origin HEAD # Push the created branch (do not merge to master)
378-
- ./automations/70_publish_outcomes.sh 8-download-sivacor
393+
- ./automations/70_publish_comment.sh 8-download-sivacor completed
379394
9-find-cran-date: #name of this pipeline
380395
- variables:
381396
- name: filename
@@ -395,11 +410,12 @@ pipelines:
395410
- found_file=$(find . -name "$filename" -not -path "./.git/*" | head -1)
396411
- if [ -z "$found_file" ]; then echo "File '$filename' not found in repository"; exit 1; fi
397412
- echo "Found $found_file"
413+
- ./automations/70_publish_comment.sh 9-find-cran-date started
398414
- python3 tools/find_cran_date.py "$found_file" --output generated/notes-for-r.md
399415
- git add generated/notes-for-r.md
400416
- git diff --cached --quiet || git commit -m "[skip ci] Added R environment notes"
401417
- git push
402-
- ./automations/70_publish_outcomes.sh 9-find-cran-date
418+
- ./automations/70_publish_comment.sh 9-find-cran-date completed
403419
w-big-populate-from-icpsr: #name of this pipeline
404420
- variables: #list variable names under here
405421
# These do not need to have a value, if "config.yml" is filled out.
@@ -423,6 +439,7 @@ pipelines:
423439
- projectID="${projectID:-zenodo-$ZenodoID}"
424440
- if [ -z "$jiraticket" ] && [ -n "${openICPSRID:-}" ]; then jiraticket=$(python3 tools/jira_find_task_by_icpsr.py "$openICPSRID" 2>/dev/null || true); fi
425441
- ./tools/update_config.sh
442+
- ./automations/70_publish_comment.sh w-big-populate-from-icpsr started
426443
- if [ -d $projectID ]; then \rm -rf $projectID; fi
427444
- if [ ! -z $openICPSRID ]; then python3 tools/download_openicpsr-private.py $openICPSRID; fi
428445
- if [ ! -z $ZenodoID ]; then python3 tools/download_zenodo_draft.py $ZenodoID; fi
@@ -447,7 +464,7 @@ pipelines:
447464
- git status
448465
- git push
449466
- git push --tags
450-
- ./automations/70_publish_outcomes.sh w-big-populate-from-icpsr
467+
- ./automations/70_publish_comment.sh w-big-populate-from-icpsr completed
451468

452469
x-run-python:
453470
- variables:
@@ -519,7 +536,7 @@ pipelines:
519536
- ./automations/20_commit_code.sh config.yml notag
520537
- git status
521538
- git push
522-
- ./automations/70_publish_outcomes.sh z-run-any-big
539+
- ./automations/70_publish_comment.sh z-run-any-big completed
523540

524541
# default:
525542
# - step:

tools/update_config.sh

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
#!/bin/bash
22
#set -ev
33

4+
configfile=config.yml
45
# Get some functions
56

67
. ./tools/parse_yaml.sh
78

89
# Check for config.yml
910

10-
if [ ! -f config.yml ]; then
11+
if [ ! -f $configfile ]; then
1112
# see if the template is there
12-
if [ -f template/new-config.yml ]; then
13-
cp template/new-config.yml config.yml
13+
if [ -f template/new-$configfile ]; then
14+
cp template/new-$configfile $configfile
1415
else
15-
echo "config.yml not found!"
16+
echo "$configfile not found!"
1617
exit 1
1718
fi
1819
fi
@@ -23,7 +24,7 @@ fi
2324
_env_jiraticket="${jiraticket:-}"
2425

2526
# read parameters
26-
eval $(parse_yaml config.yml)
27+
eval $(parse_yaml $configfile)
2728

2829
# from environment
2930
# - name: openICPSRID
@@ -45,15 +46,15 @@ MainFile="${MainFile:-$main}"
4546
jiraticket="${_env_jiraticket:-$jiraticket}"
4647
mcid="${mcid:-$mcid}"
4748

49+
4850
# write it back
49-
config=config.yml
5051

51-
sed -i "s/openicpsr: \(.*\)/openicpsr: $openICPSRID/" $config
52-
sed -i "s/osf: \(.*\)/osf: $OSFID/" $config
53-
sed -i "s/dataverse: \(.*\)/dataverse: $DataverseID/" $config
54-
sed -i "s/zenodo: \(.*\)/zenodo: $ZenodoID/" $config
55-
sed -i "s/main: \(.*\)/main: $MainFile/" $config
56-
sed -i "s/jiraticket: \(.*\)/jiraticket: $jiraticket/" $config
57-
sed -i "s/mcid: \(.*\)/mcid: $mcid/" $config
52+
sed -i "s/openicpsr:\(.*\)/openicpsr: $openICPSRID/" $configfile
53+
sed -i "s/osf:\(.*\)/osf: $OSFID/" $configfile
54+
sed -i "s/dataverse:\(.*\)/dataverse: $DataverseID/" $configfile
55+
sed -i "s/zenodo:\(.*\)/zenodo: $ZenodoID/" $configfile
56+
sed -i "s/main:\(.*\)/main: $MainFile/" $configfile
57+
sed -i "s/jiraticket:\(.*\)/jiraticket: $jiraticket/" $configfile
58+
sed -i "s/mcid:\(.*\)/mcid: $mcid/" $configfile
5859

59-
cat $config
60+
cat $configfile

0 commit comments

Comments
 (0)