Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an artifact as destination option for using in subsequent jobs #72

Merged
merged 19 commits into from
Feb 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions .github/workflows/draw-zmk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,26 @@ on:
default: ''
required: false
type: string
destination:
description: 'Add the output files to a commit, as artifacts or both, values: `commit`, `artifact`, `both`'
default: 'commit'
required: false
type: string
artifact_name:
description: 'Name of the produced artifact containing SVG and YAML outputs. Ignored if `destination` is `commit`.'
default: 'drawings'
required: false
type: string
outputs:
drawings:
description: 'Archive with keymap in YAML and drawing in SVG formats'
value: ${{ jobs.draw.outputs.drawings }}

jobs:
draw:
runs-on: ubuntu-latest

outputs:
drawings: ${{ steps.artifact-upload-step.outputs.artifact-id }}
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -75,6 +90,7 @@ jobs:
run: python3 -m pip install "git+https://github.com/caksoylar/keymap-drawer.git@${{ inputs.install_branch }}"

- name: Draw keymaps
id: draw
run: |
get_args() {
local keyboard=$2
Expand All @@ -89,6 +105,7 @@ jobs:
done
}

declare -a DRAWINGS
mkdir -p "${{ inputs.output_folder }}"

config_path="${{ inputs.config_path }}"
Expand All @@ -111,15 +128,20 @@ jobs:
keymap "${config_arg[@]}" parse -z "$keymap_file" $parse_args >"${{ inputs.output_folder }}/$keyboard.yaml" \
&& keymap "${config_arg[@]}" draw "${{ inputs.output_folder }}/$keyboard.yaml" $draw_args >"${{ inputs.output_folder }}/$keyboard.svg" \
|| echo "ERROR: parsing or drawing failed for $keyboard!"
DRAWINGS+=(\"${{ inputs.output_folder }}/$keyboard.yaml\" \"${{ inputs.output_folder }}/$keyboard.svg\")
done

IFS=','
echo "DRAWINGS=[${DRAWINGS[*]}]" >> $GITHUB_OUTPUT
unset IFS

- name: Get last commit message
id: last_commit_message
if: inputs.amend_commit == true
if: inputs.amend_commit == true && (inputs.destination == 'commit' || inputs.destination == 'both')
run: |
echo "msg=$(git log -1 --pretty=%s)" >> $GITHUB_OUTPUT

- name: Commit updated images
if: ( inputs.destination == 'commit' || inputs.destination == 'both' )
uses: stefanzweifel/git-auto-commit-action@v5
with:
file_pattern: '${{ inputs.output_folder }}/*.svg ${{ inputs.output_folder }}/*.yaml'
Expand All @@ -132,3 +154,13 @@ jobs:
commit_options: "${{ (inputs.amend_commit == true && '--amend --no-edit') || '' }}"
push_options: "${{ (inputs.amend_commit == true && '--force-with-lease') || '' }}"
skip_fetch: ${{ inputs.amend_commit == true }}

- name: Artifact upload
id: artifact-upload-step
if: ( inputs.destination == 'artifact' || inputs.destination == 'both' )
uses: actions/upload-artifact@v4
michaelrommel marked this conversation as resolved.
Show resolved Hide resolved
with:
name: '${{ inputs.artifact_name }}'
path: |
${{ join(fromJSON(steps.draw.outputs.DRAWINGS), '
') }}