Created
April 20, 2022 20:32
-
-
Save Robpol86/c9babd15bd5142f0fbe971c55d920513 to your computer and use it in GitHub Desktop.
fromJson trick for GitHub Actions
This file contains 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: Parallel Poetry Discovery | |
on: | |
push: {branches-ignore: ["**"]} | |
env: | |
COMMENT_PFX: "# RPOOLEY " | |
jobs: | |
matrix: | |
name: Generate Matrix | |
runs-on: "ubuntu-latest" | |
steps: | |
- {uses: actions/checkout@v2} | |
- {run: 'grep -oP "^$COMMENT_PFX\K[\w-]+" pyproject.toml |tee matches.txt'} | |
- {run: "jq -cMRn '[inputs|select(length>0)]' matches.txt |tee array.json"} | |
- {run: "echo ::set-output name=out::$(cat array.json)", id: array} | |
outputs: {array: "${{steps.array.outputs.out}}"} | |
test: | |
name: Test | |
needs: "matrix" | |
strategy: | |
fail-fast: false | |
matrix: {name: "${{fromJson(needs.matrix.outputs.array)}}"} | |
runs-on: "ubuntu-latest" | |
steps: | |
- {name: Check out repository code, uses: actions/checkout@v2} | |
- {name: Install Python, uses: actions/setup-python@v3, with: {python-version: "3.10"}} | |
- {name: Install Poetry, uses: abatilo/[email protected]} | |
- name: Uncomment | |
env: | |
PATTERN: "^${{env.COMMENT_PFX}}${{matrix.name}} " | |
SCRIPT: "$0~PATTERN{$0 = substr($0, length(COMMENT_PFX)+1)} {print}" | |
run: | | |
awk -v COMMENT_PFX="$COMMENT_PFX" -v PATTERN="$PATTERN" "$SCRIPT" pyproject.toml > pyproject.toml.new | |
mv pyproject.toml.new pyproject.toml && git diff --color=always "$_" | |
- {name: Poetry Lock, run: rm -f poetry.lock && poetry lock} | |
- {name: Store, uses: actions/upload-artifact@v2, with: {name: poetry_lock, path: "p*o*e*t*.?o??"}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment