Skip to content
Open
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
8 changes: 4 additions & 4 deletions .github/workflows/build-toolchain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ on:

jobs:
build:
name: ${{ inputs.preset }}${{ inputs.tools && '+t' || '' }}${{ inputs.extras && '+e' || '' }}
name: ${{ inputs.preset }}${{ inputs.tools && '+t' || '' }}${{ inputs.extras && '+e' || '' }}${{ inputs.ffmpeg && '+ffmpeg' || '' }}
runs-on: windows-2022
timeout-minutes: 30

Expand Down Expand Up @@ -156,12 +156,12 @@ jobs:
Write-Host "Build flags: $($buildFlags -join ' | ')"
cmake --preset ${{ inputs.preset }} $buildFlags

- name: Build ${{ inputs.game }} with CMake Using ${{ inputs.preset }}${{ inputs.tools && '+t' || '' }}${{ inputs.extras && '+e' || '' }} Preset
- name: Build ${{ inputs.game }} with CMake Using ${{ inputs.preset }}${{ inputs.tools && '+t' || '' }}${{ inputs.extras && '+e' || '' }}${{ inputs.ffmpeg && '+ffmpeg' || '' }} Preset

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of duplicating this mega long string concat, can we do it once higher up and then cache it and reuse it under a new name? That then also carries less risk of breaking again in the future when adding another new substring to it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how to do that

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chat Gippy says:

Yes. In GitHub Actions, you can concatenate strings and store the result in a local variable, but the exact syntax depends on where you want the variable to exist.

Within a shell step

This is usually the simplest:

- name: Build string
  run: |
    PREFIX="hello"
    SUFFIX="world"
    RESULT="${PREFIX}-${SUFFIX}"

    echo "$RESULT"

Persist it for later steps

If you want the variable available in subsequent steps, write it to $GITHUB_ENV:

- name: Build string
  run: |
    PREFIX="hello"
    SUFFIX="world"
    echo "RESULT=${PREFIX}-${SUFFIX}" >> "$GITHUB_ENV"

- name: Use string
  run: |
    echo "$RESULT"

Using GitHub Actions expressions

You can also concatenate values directly in expressions using format():

env:
  RESULT: ${{ format('{0}-{1}', 'hello', 'world') }}

Or, for example:

env:
  IMAGE_TAG: ${{ format('{0}:{1}', github.repository, github.sha) }}

One important distinction: GitHub Actions expressions don't have general-purpose local variable assignment like let x = .... For temporary variables, use the shell; for values needed by later steps, use $GITHUB_ENV; for job/workflow configuration, use env:.

If you show me the specific string you're trying to construct, I can give you the cleanest syntax for your workflow.

shell: pwsh
run: |
cmake --build --preset ${{ inputs.preset }}

- name: Collect ${{ inputs.game }} ${{ inputs.preset }}${{ inputs.tools && '+t' || '' }}${{ inputs.extras && '+e' || '' }} Artifact
- name: Collect ${{ inputs.game }} ${{ inputs.preset }}${{ inputs.tools && '+t' || '' }}${{ inputs.extras && '+e' || '' }}${{ inputs.ffmpeg && '+ffmpeg' || '' }} Artifact
shell: pwsh
run: |
$buildDir = "build\${{ inputs.preset }}"
Expand All @@ -178,7 +178,7 @@ jobs:

$files | Move-Item -Destination $artifactsDir -Verbose -Force

- name: Upload ${{ inputs.game }} ${{ inputs.preset }}${{ inputs.tools && '+t' || '' }}${{ inputs.extras && '+e' || '' }} Artifact
- name: Upload ${{ inputs.game }} ${{ inputs.preset }}${{ inputs.tools && '+t' || '' }}${{ inputs.extras && '+e' || '' }}${{ inputs.ffmpeg && '+ffmpeg' || '' }} Artifact
Comment thread
tsunamistate marked this conversation as resolved.
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: ${{ inputs.game }}-${{ inputs.preset }}${{ inputs.tools && '+t' || '' }}${{ inputs.extras && '+e' || '' }}
Expand Down
Loading