Skip to content

Commit dfb8cde

Browse files
authored
Merge pull request #6 from NarrativeScience/W-11900045/python-3.10-poetry-update
@W-11900045: Python 3.8+
2 parents bddd6b8 + a94afb0 commit dfb8cde

33 files changed

+1134
-341
lines changed

.circleci/@config.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: 2.1
2+
3+
orbs:
4+
aws-cli: circleci/[email protected]
5+
circleci-cli: circleci/[email protected]
6+
ghpr: narrativescience/[email protected]
7+
github-cli: circleci/[email protected]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
description: Bump package version via a git commit
2+
steps:
3+
- run:
4+
name: Bump package version
5+
command: .circleci/scripts/bump-version.sh "$GITHUB_PR_BASE_BRANCH" "$CIRCLE_BRANCH"

.circleci/commands/cancel-job.yaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
description: Cancel the current job based on an environment variable
2+
parameters:
3+
method:
4+
description: |
5+
Method of cancellation; Either cancel the job or just halt the step so the job
6+
still succeeds
7+
type: enum
8+
enum:
9+
- cancel
10+
- halt
11+
default: cancel
12+
steps:
13+
- run:
14+
name: Cancel the job
15+
command: |
16+
echo "CANCEL_JOB=$CANCEL_JOB"
17+
[[ -z "$CANCEL_JOB" ]] && exit 0
18+
set -e
19+
if [[ "<< parameters.method >>" == "cancel" ]]; then
20+
OUTPUT=$(
21+
curl \
22+
--user "${CIRCLE_API_USER_TOKEN}:" \
23+
-X POST \
24+
--max-time 60 \
25+
--connect-timeout 60 \
26+
"https://circleci.com/api/v1.1/project/github/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/${CIRCLE_BUILD_NUM}/cancel")
27+
echo "$OUTPUT"
28+
STATUS="$(echo "$OUTPUT" | jq -r .status -)"
29+
if [[ "$STATUS" == 'canceled' ]]; then
30+
# This means the job was cancelled but for some reason the current script is
31+
# still running. Wait a few seconds to let it catch up then fail the job to
32+
# prevent downstream jobs from running unintentionally.
33+
sleep 10
34+
exit 1
35+
fi
36+
echo "Failed to cancel job"
37+
exit 1
38+
elif [[ "<< parameters.method >>" == "halt" ]]; then
39+
# Halt the job and mark it as successful
40+
circleci step halt
41+
else
42+
echo "Unknown cancel method: << parameters.method >>"
43+
exit 1
44+
fi
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
description: Cancel the current job based on various conditions
2+
parameters:
3+
run_if_tag_in_commit:
4+
description: Cancel the job if this tag is not in the current commit message
5+
type: string
6+
default: ""
7+
cancel_if_tag_in_commit:
8+
description: Cancel the job if this tag is in the current commit message
9+
type: string
10+
default: ""
11+
cancel_if_tag_in_pr_title:
12+
description: Cancel the job if this tag is in the pull request title
13+
type: string
14+
default: ""
15+
run_if_paths_changed:
16+
description: Cancel the job if these file paths did not change (space-separated list)
17+
type: string
18+
default: ""
19+
run_only_if_all_paths_changed_match_pattern:
20+
description: Cancel the job if any files changed besides the ones matched by this pattern (grep regex)
21+
type: string
22+
default: ""
23+
cancel_if_paths_changed:
24+
description: Cancel the job if these file paths did change (space-separated list)
25+
type: string
26+
default: ""
27+
cancel_only_if_all_paths_changed_match_pattern:
28+
description: Cancel the job if the only files changed match this pattern (grep regex)
29+
type: string
30+
default: ""
31+
gitref:
32+
default: $CIRCLE_BRANCH
33+
type: string
34+
method:
35+
description: |
36+
Method of cancellation; Either cancel the job or just halt the step so the job
37+
still succeeds
38+
type: enum
39+
enum:
40+
- cancel
41+
- halt
42+
default: cancel
43+
steps:
44+
- run:
45+
name: Set git diff commit range
46+
command: |
47+
COMMIT_RANGE="origin/master..origin/<< parameters.gitref >>"
48+
echo "export COMMIT_RANGE=\"$COMMIT_RANGE\"" >> $BASH_ENV
49+
echo $COMMIT_RANGE
50+
- when:
51+
condition: << parameters.run_if_tag_in_commit >>
52+
steps:
53+
- run:
54+
name: |
55+
Cancel the job if << parameters.run_if_tag_in_commit >> is not in the current
56+
commit message (case insensitive)
57+
command: |
58+
shopt -s nocasematch
59+
MESSAGE="$(git log -1 --pretty=%B)"
60+
if [[ "$MESSAGE" != *'<< parameters.run_if_tag_in_commit >>'* ]]; then
61+
echo 'export CANCEL_JOB=1' >> $BASH_ENV
62+
fi
63+
shopt -u nocasematch
64+
- when:
65+
condition: << parameters.cancel_if_tag_in_commit >>
66+
steps:
67+
- run:
68+
name: |
69+
Cancel the job if << parameters.cancel_if_tag_in_commit >> is in the current
70+
commit message (case insensitive)
71+
command: |
72+
shopt -s nocasematch
73+
MESSAGE="$(git log -1 --pretty=%B)"
74+
if [[ "$MESSAGE" == *'<< parameters.cancel_if_tag_in_commit >>'* ]]; then
75+
echo 'export CANCEL_JOB=1' >> $BASH_ENV
76+
fi
77+
shopt -u nocasematch
78+
- when:
79+
condition: << parameters.cancel_if_tag_in_pr_title >>
80+
steps:
81+
- run:
82+
name: |
83+
Cancel the job if << parameters.cancel_if_tag_in_pr_title >> is in the pull request
84+
title (case insensitive)
85+
command: |
86+
shopt -s nocasematch
87+
PR_NUMBER="$(echo "$CIRCLE_PULL_REQUEST" | sed 's/.*\/pull\///')"
88+
URL="https://api.github.com/repos/NarrativeScience/talos/pulls/$PR_NUMBER"
89+
PR_TITLE="$(curl --user "$GITHUB_USERNAME:$GITHUB_PASSWORD" "$URL" | jq '.title')"
90+
if [[ "$PR_TITLE" == *'<< parameters.cancel_if_tag_in_pr_title >>'* ]]; then
91+
echo 'export CANCEL_JOB=1' >> $BASH_ENV
92+
fi
93+
shopt -u nocasematch
94+
- when:
95+
condition: << parameters.run_if_paths_changed >>
96+
steps:
97+
- run:
98+
name: Cancel the job if << parameters.run_if_paths_changed >> did not change
99+
command: |
100+
FILES="$(git diff --name-only $COMMIT_RANGE << parameters.run_if_paths_changed >>)"
101+
if [[ ${#FILES} -eq 0 ]]; then
102+
echo 'export CANCEL_JOB=1' >> $BASH_ENV
103+
fi
104+
- when:
105+
condition: << parameters.run_only_if_all_paths_changed_match_pattern >>
106+
steps:
107+
- run:
108+
name: Cancel the job if any files beside << parameters.run_only_if_all_paths_changed_match_pattern >> changed
109+
command: |
110+
GREP_PATTERN="<< parameters.run_only_if_all_paths_changed_match_pattern >>"
111+
FILES="$(git --no-pager diff --name-only $COMMIT_RANGE)"
112+
if [[ ${#FILES} -gt 0 ]]; then
113+
FILTERED_FILES=$(echo "$FILES" | grep "$GREP_PATTERN") || true
114+
if [[ "$FILES" != "$FILTERED_FILES" ]]; then
115+
echo 'export CANCEL_JOB=1' >> $BASH_ENV
116+
fi
117+
fi
118+
- when:
119+
condition: << parameters.cancel_if_paths_changed >>
120+
steps:
121+
- run:
122+
name: Cancel the job if << parameters.cancel_if_paths_changed >> did change
123+
command: |
124+
FILES="$(git diff --name-only $COMMIT_RANGE << parameters.cancel_if_paths_changed >>)"
125+
if [[ ${#FILES} -gt 0 ]]; then
126+
echo 'export CANCEL_JOB=1' >> $BASH_ENV
127+
fi
128+
- when:
129+
condition: << parameters.cancel_only_if_all_paths_changed_match_pattern >>
130+
steps:
131+
- run:
132+
name: Cancel the job if the only files changed match << parameters.cancel_only_if_all_paths_changed_match_pattern >>
133+
command: |
134+
GREP_PATTERN="<< parameters.cancel_only_if_all_paths_changed_match_pattern >>"
135+
FILES="$(git --no-pager diff --name-only $COMMIT_RANGE)"
136+
if [[ ${#FILES} -gt 0 ]]; then
137+
FILTERED_FILES=$(echo "$FILES" | grep -E "$GREP_PATTERN") || true
138+
if [[ "$FILES" == "$FILTERED_FILES" ]]; then
139+
echo 'export CANCEL_JOB=1' >> $BASH_ENV
140+
fi
141+
fi
142+
- cancel-job:
143+
method: << parameters.method >>

.circleci/commands/github-release.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
description: Create a github release via the github CLI
2+
steps:
3+
- github-cli/setup
4+
- run:
5+
name: Create GitHub Release
6+
command: |
7+
version="$(poetry version -s)"
8+
notes="$(git show -s --format=%B HEAD)"
9+
gh release create "v${version}" --title "Version ${version}" --notes "$notes"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
description: Configure Poetry
2+
steps:
3+
- run:
4+
name: Configure Poetry
5+
command: |
6+
pip install -U pip setuptools
7+
pip install poetry
8+
poetry config pypi-token.pypi "$POETRY_PYPI_TOKEN_PYPI"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
description: Restores the build-test cache for pyenv, poetry, and pre-commit
2+
steps:
3+
- restore_cache:
4+
keys:
5+
- v1-pyenv-{{ arch }}-fluxio-parser-{{ checksum "poetry.lock" }}
6+
- restore_cache:
7+
keys:
8+
- v1-poetry-{{ arch }}-fluxio-parser-{{ checksum "poetry.lock" }}
9+
- restore_cache:
10+
keys:
11+
- v1-precommit-{{ arch }}-fluxio-parser-{{ checksum ".pre-commit-config.yaml" }}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
description: Stores the build-test cache for pyenv, poetry, and pre-commit
2+
steps:
3+
- save_cache:
4+
key: v1-pyenv-{{ arch }}-fluxio-parser-{{ checksum "poetry.lock" }}
5+
paths:
6+
- "~/.pyenv"
7+
- save_cache:
8+
key: v1-poetry-{{ arch }}-fluxio-parser-{{ checksum "poetry.lock" }}
9+
paths:
10+
- "~/.cache/pypoetry"
11+
- save_cache:
12+
key: v1-precommit-{{ arch }}-fluxio-parser-{{ checksum ".pre-commit-config.yaml" }}
13+
paths:
14+
- "~/.cache/pre-commit"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
description: Store test artifacts in CCI workflow run
2+
parameters:
3+
artifacts_path:
4+
description: The absolute path to the artifacts stored as an env var
5+
type: string
6+
artifacts_storage_dir:
7+
description: The directory in /tmp where we want to store the artifacts
8+
type: string
9+
default: << parameters.artifacts_path >>
10+
export_test_results:
11+
description: Whether or not to upload the artifacts as Test Summary metadata
12+
type: boolean
13+
default: false
14+
steps:
15+
- store_artifacts:
16+
path: << parameters.artifacts_path >>
17+
destination: << parameters.artifacts_storage_dir >>
18+
- when:
19+
condition: << parameters.export_test_results >>
20+
steps:
21+
- store_test_results:
22+
path: << parameters.artifacts_path >>

0 commit comments

Comments
 (0)