# https://docs.github.com/en/actions/learn-github-actions/contexts name: Example Env (Scratch File) ## Expression # https://docs.github.com/en/github-ae@latest/actions/learn-github-actions/expressions ## Error: .github/workflows/example-env-github.yml (Line: 53, Col: 26): A mapping was not expected ## Means that the expression syntax ${{ }} is not supported on: # Manually running a workflow from the UI # https://docs.github.com/en/actions/using-workflows/triggering-a-workflow#defining-inputs-for-manually-triggered-workflows # https://docs.github.com/en/actions/managing-workflow-runs/manually-running-a-workflow#configuring-a-workflow-to-run-manually # https://docs.github.com/en/actions/learn-github-actions/contexts#inputs-context workflow_dispatch: inputs: versions: description: 'Version of the interpreter' required: true default: "['8.2']" # https://docs.github.com/en/enterprise-cloud@latest/actions/using-workflows/workflow-syntax-for-github-actions#onworkflow_dispatchinputsinput_idtype type: choice options: - "['7.4','8.2']" - "['8.2']" - "['7.4']" permissions: # Setting permissions for the token contents: read # needed to fetch code # A list of the jobs that run in the workflow file. jobs: demo-job: # The identifier of the job name: Env printing with the matrix version ${{ matrix.version }} # The name of the job runs-on: ubuntu-latest # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstrategy strategy: # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstrategyfail-fast fail-fast: false # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix matrix: # 2 jobs will run, one for each include entry # because we don't specify any matrix variables # All configurations under include will run # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-adding-configurations # Using context to create matrix # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-using-contexts-to-create-matrices # Note you can also set it programmatically: https://docs.github.com/en/actions/learn-github-actions/expressions#example-returning-a-json-object version: ${{ fromJson(github.event.inputs.versions) }} # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#env # https://docs.github.com/en/actions/learn-github-actions/contexts#env-context # only string, boolean, number env: LITERAL_STRING_ENV: lib/plugins/combo DEPENDENCY_VIA_COMMAND: "${{ matrix.version == '7.4' && '7.4 version' || 'not 7.4 version' }}" steps: # https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable # https://docs.github.com/en/actions/learn-github-actions/variables#passing-values-between-steps-and-jobs-in-a-workflow # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsenv - name: Adding a conditional dependant variable run: | echo "DEPENDENCY_VIA_ARRAY=${{ fromJson(env.LITERAL_ARRAY_ENV)[matrix.version] }}" >> $GITHUB_ENV env: # only string, boolean, number LITERAL_ARRAY_ENV: '{"7.4":"Dependency Variable for 7.4","8.2":"Dependency Variable for 8.2"}' - name: Echo env created run: | echo "$LITERAL_STRING_ENV"; echo "$DEPENDENCY_VIA_COMMAND"; echo "$DEPENDENCY_VIA_ARRAY"; # https://docs.github.com/en/actions/learn-github-actions/contexts#example-printing-context-information-to-the-log - name: Dump GitHub context run: echo '${{ toJSON(github) }}' - name: Dump job context run: echo '${{ toJSON(job) }}' - name: Dump steps context run: echo '${{ toJSON(steps) }}' - name: Dump runner context run: echo '${{ toJSON(runner) }}' - name: Dump strategy context run: echo '${{ toJSON(strategy) }}' - name: Dump matrix context run: echo '${{ toJSON(matrix) }}' - name: Dump Input context run: echo '${{ toJSON(inputs) }}'