convert string value to float or int #4109
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
| # USAGE: | |
| # After reviewing the code, core team members may comment on a PR with `!build` followed by optional `<target>` and `<profile>` arguments. | |
| # This matches the syntax of the `cargo run build` CLI command, but allows platforms to be specified. | |
| # | |
| # `<target>`: `web` (default), `desktop` (all platforms), or `desktop:<platforms>` (subset of `windows+mac+linux`) | |
| # `<profile>`: `release` (default) or `debug` | |
| # | |
| # Examples: | |
| # - !build | |
| # - !build debug | |
| # - !build desktop | |
| # - !build desktop:windows+mac | |
| # - !build desktop:linux debug | |
| name: "!build PR Command" | |
| on: | |
| issue_comment: | |
| types: | |
| - created | |
| jobs: | |
| setup: | |
| # Command should be limited to core team members (those in the organization) for security. | |
| # From the GitHub Actions docs: | |
| # author_association = 'MEMBER': Author is a member of the organization that owns the repository. | |
| if: > | |
| github.event.issue.pull_request && | |
| github.event.comment.author_association == 'MEMBER' && | |
| startsWith(github.event.comment.body, '!build') | |
| runs-on: ubuntu-latest | |
| permissions: | |
| pull-requests: write | |
| outputs: | |
| repo: ${{ steps.pr_info.outputs.repo }} | |
| ref: ${{ steps.pr_info.outputs.ref }} | |
| web: ${{ steps.pr_info.outputs.web }} | |
| windows: ${{ steps.pr_info.outputs.windows }} | |
| mac: ${{ steps.pr_info.outputs.mac }} | |
| linux: ${{ steps.pr_info.outputs.linux }} | |
| debug: ${{ steps.pr_info.outputs.debug }} | |
| steps: | |
| - name: 🔎 Parse command, find branch, and set build flags | |
| id: pr_info | |
| run: | | |
| COMMENT="${{ github.event.comment.body }}" | |
| # Split into space-separated words | |
| read -ra WORDS <<< "$COMMENT" | |
| # First word must be "!build" | |
| if [[ "${WORDS[0]}" != "!build" ]]; then | |
| echo "::error::Expected comment to start with !build" | |
| exit 1 | |
| fi | |
| # Initialize build flags (web defaults to true, matching the CLI default target) | |
| WEB="true" | |
| WINDOWS="false" | |
| MAC="false" | |
| LINUX="false" | |
| DEBUG="false" | |
| # Parse target (optional, defaults to `web` if omitted) | |
| IDX=1 | |
| case "${WORDS[$IDX]:-}" in | |
| # Target: `web` enables just the web build (already the default, but accepted explicitly) | |
| "web") | |
| ((IDX++)) ;; | |
| # Target: `desktop` enables all three desktop platforms | |
| "desktop") | |
| WEB="false"; WINDOWS="true"; MAC="true"; LINUX="true"; ((IDX++)) ;; | |
| # Target: `desktop:<platforms>` enables a subset of desktop platforms, split by `+` | |
| desktop:*) | |
| WEB="false" | |
| PLATFORMS="${WORDS[$IDX]#desktop:}" | |
| IFS='+' read -ra PARTS <<< "$PLATFORMS" | |
| for PART in "${PARTS[@]}"; do | |
| case "$PART" in | |
| "windows") WINDOWS="true" ;; | |
| "mac") MAC="true" ;; | |
| "linux") LINUX="true" ;; | |
| *) echo "::error::Unrecognized platform: $PART"; exit 1 ;; | |
| esac | |
| done | |
| ((IDX++)) | |
| ;; | |
| esac | |
| # Parse profile (optional, defaults to `release` if omitted) | |
| case "${WORDS[$IDX]:-}" in | |
| "debug") DEBUG="true"; ((IDX++)) ;; | |
| "release") ((IDX++)) ;; | |
| esac | |
| # Reject any unexpected trailing words | |
| if [[ $IDX -lt ${#WORDS[@]} ]]; then | |
| echo "::error::Unexpected argument: ${WORDS[$IDX]}" | |
| exit 1 | |
| fi | |
| # Write parsed build flags to job outputs | |
| echo "web=$WEB" >> $GITHUB_OUTPUT | |
| echo "windows=$WINDOWS" >> $GITHUB_OUTPUT | |
| echo "mac=$MAC" >> $GITHUB_OUTPUT | |
| echo "linux=$LINUX" >> $GITHUB_OUTPUT | |
| echo "debug=$DEBUG" >> $GITHUB_OUTPUT | |
| # Fetch the PR's head branch and repo (needed for forked PRs where the code lives in another repo) | |
| RESPONSE=$(curl -L -H 'Accept: application/vnd.github+json' -H 'X-GitHub-Api-Version: 2022-11-28' https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.issue.number }}) | |
| echo "repo=$(echo $RESPONSE | jq -r '.head.repo.full_name')" >> $GITHUB_OUTPUT | |
| echo "ref=$(echo $RESPONSE | jq -r '.head.ref')" >> $GITHUB_OUTPUT | |
| - name: 💬 Edit comment with workflow run link | |
| uses: actions/github-script@v8 | |
| with: | |
| script: | | |
| github.rest.issues.updateComment({ | |
| comment_id: ${{ github.event.comment.id }}, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: '${{ github.event.comment.body }} ([Run ID ' + context.runId + '](https://github.com/GraphiteEditor/Graphite/actions/runs/' + context.runId + '))' | |
| }); | |
| invoke-build: | |
| needs: setup | |
| uses: ./.github/workflows/build.yml | |
| secrets: inherit | |
| with: | |
| web: ${{ needs.setup.outputs.web == 'true' }} | |
| windows: ${{ needs.setup.outputs.windows == 'true' }} | |
| mac: ${{ needs.setup.outputs.mac == 'true' }} | |
| linux: ${{ needs.setup.outputs.linux == 'true' }} | |
| debug: ${{ needs.setup.outputs.debug == 'true' }} | |
| checkout_repo: ${{ needs.setup.outputs.repo }} | |
| checkout_ref: ${{ needs.setup.outputs.ref }} | |
| pr_number: ${{ github.event.issue.number }} |