This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
- uses: actions/checkout@v3 | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} # checkout pull request HEAD commit instead of merge commit | |
fetch-depth: 0 # fetch all history for all branches and tags | |
- name: Set env variables | |
id: setup-vars | |
run: | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FILE_PATH=path/to/config/file.yaml | |
LINE_MARK="tag: " | |
line_number=$(awk "/$LINE_MARK/ {print FNR}" $FILE_PATH) | |
test $line_number # TODO: better error reporting | |
git log --oneline --decorate --pretty=format:"%cs [%h] by %aN%n" -u -L ${line_number},${line_number}:$FILE_PATH \ | |
| grep -v "diff --git\|---\|+++\|@@\|- \|^$" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[flake8] | |
max-line-length = 88 | |
extend-ignore = \ | |
E203, \ # whitespace before ':' | |
F841, \ # local variable name is assigned to but never used | |
E266, \ # too many leading '#' for block comment | |
per-file-ignores = | |
*/__init__.py: F401 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Transform input json, similar to jq | |
inputs: | |
input_json: {type: string, required: true} | |
transform: {type: string, required: true} | |
outputs: | |
result: | |
value: ${{ steps.parse.outputs.result }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Setup env variables | |
inputs: | |
vars_json: {type: string, default: "{}"} | |
# TODO: add argument "by_workflow_call: bool" to skip some steps | |
# env vars to override: | |
PAYLOAD: {type: string, default: ""} | |
TRAIN_IMAGE_TAG: {type: string, default: ""} | |
outputs: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
arr=() | |
arr+=( "FOO=foo" ) | |
arr+=( "BAR=bar" ) | |
for kv in ${arr[@]}; do | |
k=${kv%%=*}; v=${kv##*=} | |
echo "Debug: name=$k value=$v" | |
echo "::set-output name=$k::$v" | |
echo "$k=$v" >> $GITHUB_ENV | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# source: https://stackoverflow.com/a/64473987 | |
# Deletes ALL runs except those named "Dev", "Test" and "Prod". | |
user=GH_USERNAME repo=REPO_NAME | |
out=$(gh api repos/$user/$repo/actions/runs --paginate -q '.workflow_runs[] | select(.head_branch != "main")' ) | |
ids=$(echo $out | jq 'select(.name != "Dev" and .name != "Test" and .name != "Prod") | .id') | |
for id in $ids; do echo $id; gh api repos/$user/$repo/actions/runs/$id -X DELETE & sleep 0.1; done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
on: | |
pull_request: | |
types: [synchronize, labeled] | |
push: | |
branches: [main] | |
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def camel_to_snake(s): | |
# source: https://gist.github.com/jaytaylor/3660565 | |
import re | |
_underscorer1 = re.compile(r'(.)([A-Z][a-z]+)') | |
_underscorer2 = re.compile('([a-z0-9])([A-Z])') | |
subbed = _underscorer1.sub(r'\1_\2', s) | |
return _underscorer2.sub(r'\1_\2', subbed).lower() | |
def test_camel_to_snake(): | |
assert camel_to_snake('snakesOnAPlane') == 'snakes_on_a_plane' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env bash | |
set -euo pipefail | |
USAGE="[ERROR] Usage: '$0 QUERY_FILE_NAME key1=value2 key2=value2 ...'" | |
if [ "$#" -lt 1 ]; then | |
echo "[ERROR] Expect at least 1 argument, received: $#" >&2 | |
echo $USAGE >&2 | |
exit 1 | |
fi |