xref: /plugin/combo/.github/workflows/scratch-env.yml (revision 5b7a56ccb7c57144ce99d82ebd684c7eb5d4f441)
1# https://docs.github.com/en/actions/learn-github-actions/contexts
2name: Scratch Learning Workflow
3
4
5## Expression
6# https://docs.github.com/en/github-ae@latest/actions/learn-github-actions/expressions
7## Error: .github/workflows/example-env-github.yml (Line: 53, Col: 26): A mapping was not expected
8## Means that the expression syntax ${{ }} is not supported
9
10
11on:
12  # Manually running a workflow from the UI
13  # https://docs.github.com/en/actions/using-workflows/triggering-a-workflow#defining-inputs-for-manually-triggered-workflows
14  # https://docs.github.com/en/actions/managing-workflow-runs/manually-running-a-workflow#configuring-a-workflow-to-run-manually
15  # https://docs.github.com/en/actions/learn-github-actions/contexts#inputs-context
16  workflow_dispatch:
17    inputs:
18      versions:
19        description: 'Version of the interpreter'
20        required: true
21        default: "['8.2']"
22        # https://docs.github.com/en/enterprise-cloud@latest/actions/using-workflows/workflow-syntax-for-github-actions#onworkflow_dispatchinputsinput_idtype
23        type: choice
24        options:
25          - "['7.4','8.2']"
26          - "['8.2']"
27          - "['7.4']"
28
29
30permissions: # Setting permissions for the token
31  contents: read # needed to fetch code
32
33# A list of the jobs that run in the workflow file.
34jobs:
35  demo-job: # The identifier of the job
36
37    name: Env printing with the matrix version ${{ matrix.version }} # The name of the job
38
39    runs-on: ubuntu-latest
40
41    # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstrategy
42    strategy:
43      # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstrategyfail-fast
44      fail-fast: false
45
46      # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix
47      matrix:
48        # 2 jobs will run, one for each include entry
49        # because we don't specify any matrix variables
50        # All configurations under include will run
51        # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-adding-configurations
52        # Using context to create matrix
53        # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-using-contexts-to-create-matrices
54        # Note you can also set it programmatically: https://docs.github.com/en/actions/learn-github-actions/expressions#example-returning-a-json-object
55        version: ${{ fromJson(github.event.inputs.versions) }}
56
57    # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#env
58    # https://docs.github.com/en/actions/learn-github-actions/contexts#env-context
59    # only string, boolean, number
60    env:
61      LITERAL_STRING_ENV: lib/plugins/combo
62      DEPENDENCY_VIA_COMMAND: "${{ matrix.version == '7.4' && '7.4 version' || 'not 7.4 version' }}"
63
64    steps:
65
66      # https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable
67      # https://docs.github.com/en/actions/learn-github-actions/variables#passing-values-between-steps-and-jobs-in-a-workflow
68      # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsenv
69      - name: Adding a conditional dependant variable
70        run: |
71          echo "DEPENDENCY_VIA_ARRAY=${{ fromJson(env.LITERAL_ARRAY_ENV)[matrix.version] }}" >> $GITHUB_ENV
72        env:
73          # only string, boolean, number
74          LITERAL_ARRAY_ENV: '{"7.4":"Dependency Variable for 7.4","8.2":"Dependency Variable for 8.2"}'
75
76      - name: Echo env created
77        run: |
78          echo "$LITERAL_STRING_ENV";
79          echo "$DEPENDENCY_VIA_COMMAND";
80          echo "$DEPENDENCY_VIA_ARRAY";
81
82      # https://docs.github.com/en/actions/learn-github-actions/contexts#example-printing-context-information-to-the-log
83      - name: Dump GitHub context
84        run: echo '${{ toJSON(github) }}'
85      - name: Dump job context
86        run: echo '${{ toJSON(job) }}'
87      - name: Dump steps context
88        run: echo '${{ toJSON(steps) }}'
89      - name: Dump runner context
90        run: echo '${{ toJSON(runner) }}'
91      - name: Dump strategy context
92        run: echo '${{ toJSON(strategy) }}'
93      - name: Dump matrix context
94        run: echo '${{ toJSON(matrix) }}'
95      - name: Dump Input context
96        run: echo '${{ toJSON(inputs) }}'
97
98