Skip to content

Commit

Permalink
tidy: Add codegen input option
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Feb 1, 2025
1 parent c712b5e commit ca53660
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/msrv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ jobs:
timeout-minutes: 30
steps:
- uses: taiki-e/checkout-action@v1
- id: prepare
- name: Prepare
id: prepare
run: |
trap -- 's=$?; printf >&2 "%s\n" "${0##*/}:${LINENO}: \`${BASH_COMMAND}\` exit with ${s}"; exit ${s}' ERR
IFS=$'\n\t'
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/release-dry-run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ jobs:
timeout-minutes: 30
steps:
- uses: taiki-e/checkout-action@v1
- run: pip3 install yq
- id: prepare
- name: Prepare
id: prepare
run: |
trap -- 's=$?; printf >&2 "%s\n" "${0##*/}:${LINENO}: \`${BASH_COMMAND}\` exit with ${s}"; exit ${s}' ERR
IFS=$'\n\t'
pip3 install yq
job=$(yq -c ".jobs.\"${{ inputs.job }}\"" "${{ inputs.workflow }}")
matrix=$(jq -c '.strategy.matrix' <<<"${job}")
if [[ "${matrix}" == "null" ]]; then
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ jobs:
timeout-minutes: 30
steps:
- uses: taiki-e/checkout-action@v1
- id: prepare
- name: Prepare
id: prepare
run: |
trap -- 's=$?; printf >&2 "%s\n" "${0##*/}:${LINENO}: \`${BASH_COMMAND}\` exit with ${s}"; exit ${s}' ERR
IFS=$'\n\t'
Expand All @@ -114,8 +115,10 @@ jobs:
timeout-minutes: 60
steps:
- uses: taiki-e/checkout-action@v1
- id: prepare
- name: Prepare
id: prepare
run: |
trap -- 's=$?; printf >&2 "%s\n" "${0##*/}:${LINENO}: \`${BASH_COMMAND}\` exit with ${s}"; exit ${s}' ERR
IFS=$'\n\t'
metadata=$(cargo metadata --format-version=1 --no-deps)
# Publishing is unrestricted if null, and forbidden if an empty array.
Expand Down
78 changes: 77 additions & 1 deletion .github/workflows/tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,26 @@ on:
docs-args:
required: false
type: string
codegen:
required: false
type: boolean
default: true
codegen-workflow:
required: false
type: string
default: .github/workflows/ci.yml
codegen-job:
required: false
type: string
default: codegen
codegen-script:
required: false
type: string
default: tools/gen.sh
codegen-commit-script:
required: false
type: string
default: tools/ci/gen.sh

env:
CARGO_INCREMENTAL: 0
Expand Down Expand Up @@ -69,8 +89,14 @@ jobs:
timeout-minutes: 30
steps:
- uses: taiki-e/checkout-action@v1
- id: prepare
- name: Prepare
id: prepare
run: |
trap -- 's=$?; printf >&2 "%s\n" "${0##*/}:${LINENO}: \`${BASH_COMMAND}\` exit with ${s}"; exit ${s}' ERR
IFS=$'\n\t'
printf 'github.event_name=%s\n' "${{ github.event_name }}"
printf 'github.ref=%s\n' "${{ github.ref }}"
printf 'github.repository_owner=%s\n' "${{ github.repository_owner }}"
if [[ -n "$(git ls-files '*.rs')" ]]; then
printf 'rust=true\n' >>"${GITHUB_OUTPUT}"
metadata=$(cargo metadata --format-version=1 --no-deps)
Expand All @@ -85,11 +111,26 @@ jobs:
fi
fi
fi
if [[ -e "${{ inputs.codegen-script }}" ]]; then
pip3 install yq
job=$(yq -c ".jobs.\"${{ inputs.codegen-job }}\"" "${{ inputs.codegen-workflow }}")
if [[ "${job}" == "null" ]]; then
printf 'codegen=true\n' >>"${GITHUB_OUTPUT}"
if [[ -e "${{ inputs.codegen-commit-script }}" ]]; then
printf 'codegen-commit=true\n' >>"${GITHUB_OUTPUT}"
fi
fi
elif [[ -e "${{ inputs.codegen-commit-script }}" ]]; then
printf '%s\n' "::error::'${{ inputs.codegen-commit-script }}' is available but ${{ inputs.codegen-script }} is not available"
exit 1
fi
outputs:
rust: ${{ steps.prepare.outputs.rust }}
rust-pub: ${{ steps.prepare.outputs.rust-pub }}
rust-pub-lib: ${{ steps.prepare.outputs.rust-pub-lib }}
rust-pub-proc-macro: ${{ steps.prepare.outputs.rust-pub-proc-macro }}
codegen: ${{ steps.prepare.outputs.codegen }}
codegen-commit: ${{ steps.prepare.outputs.codegen-commit }}

tidy:
needs: prepare
Expand Down Expand Up @@ -251,3 +292,38 @@ jobs:
rust: ${{ inputs.rust }}
target: ${{ inputs.docs-target }}
args: ${{ inputs.docs-args }}

codegen:
needs: prepare
if: inputs.codegen && needs.prepare.outputs.codegen == 'true'
runs-on: ubuntu-latest
timeout-minutes: 60
permissions:
contents: read
pull-requests: write # for gh pr edit --add-assignee
repository-projects: read # for gh pr edit --add-assignee
steps:
- uses: taiki-e/checkout-action@v1
- uses: taiki-e/github-actions/install-rust@nightly
if: needs.prepare.outputs.rust == 'true'
- run: tools/gen.sh
- name: Handle diff
id: diff
run: tools/ci/gen.sh
if: needs.prepare.outputs.codegen-commit == 'true' && github.repository_owner == 'taiki-e' && (github.event_name == 'schedule' || github.event_name == 'push' && github.ref == 'refs/heads/main')
- run: git add -N . && git diff --exit-code
- id: create-pull-request
uses: peter-evans/create-pull-request@v7
with:
title: Update generated code
body: |
Auto-generated by CI using [create-pull-request](https://github.com/peter-evans/create-pull-request).
branch: update-generated-code
token: ${{ secrets.CREATE_PR_TOKEN }}
if: needs.prepare.outputs.codegen-commit == 'true' && github.repository_owner == 'taiki-e' && (github.event_name == 'schedule' || github.event_name == 'push' && github.ref == 'refs/heads/main') && steps.diff.outputs.success == 'false'
- name: Notify PR author by assigning PR
run: gh pr edit --add-assignee taiki-e "${PR_NUMBER:?}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ steps.create-pull-request.outputs.pull-request-number }}
if: needs.prepare.outputs.codegen-commit == 'true' && github.repository_owner == 'taiki-e' && (github.event_name == 'schedule' || github.event_name == 'push' && github.ref == 'refs/heads/main') && steps.diff.outputs.success == 'false'

0 comments on commit ca53660

Please sign in to comment.