Update test workflows and improve expression_test.go/run_context_test.go (#560)

* fix: give case insensitive secret more meanigful name

* refactor: use `string` in generating `env:` and `steps:` for workflows

Smaller text generation is much better to read with normal strings than
raw string literals.

* feat: sort keys for `env:` so it's always in specific order

* fix: update test workflows
This commit is contained in:
hackercat 2021-03-13 01:25:10 +01:00 committed by GitHub
parent eb2774275f
commit 09679f0156
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 475 additions and 469 deletions

View file

@ -3,12 +3,12 @@ name: "Test how expressions are handled on Github"
on: push on: push
env: env:
KEYWITHNOTHING: valuewithnothing
KEY-WITH-HYPHENS: value-with-hyphens
KEY_WITH_UNDERSCORES: value_with_underscores
SOMETHING_TRUE: true
SOMETHING_FALSE: false
ACT: true ACT: true
KEY-WITH-HYPHENS: value-with-hyphens
KEYWITHNOTHING: valuewithnothing
KEY_WITH_UNDERSCORES: value_with_underscores
SOMETHING_FALSE: false
SOMETHING_TRUE: true
jobs: jobs:
@ -16,68 +16,74 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: €{{ 1 }} to €{{ 2 }} -> ${{1}} to ${{2}} should be equal to 1 to 2 - name: €{{ 1 }} to €{{ 2 }} -> ${{1}} to ${{2}} should be equal to 1 to 2
run: echo "Done " run: echo "Done "
- name: €{{ env.KEYWITHNOTHING }} -> ${{ env.KEYWITHNOTHING }} should be equal to valuewithnothing - name: €{{ env.KEYWITHNOTHING }} -> ${{ env.KEYWITHNOTHING }} should be equal to valuewithnothing
run: echo "Done " run: echo "Done "
- name: €{{ env.KEY-WITH-HYPHENS }} -> ${{ env.KEY-WITH-HYPHENS }} should be equal to value-with-hyphens - name: €{{ env.KEY-WITH-HYPHENS }} -> ${{ env.KEY-WITH-HYPHENS }} should be equal to value-with-hyphens
run: echo "Done " run: echo "Done "
- name: €{{ env.KEY_WITH_UNDERSCORES }} -> ${{ env.KEY_WITH_UNDERSCORES }} should be equal to value_with_underscores - name: €{{ env.KEY_WITH_UNDERSCORES }} -> ${{ env.KEY_WITH_UNDERSCORES }} should be equal to value_with_underscores
run: echo "Done " run: echo "Done "
- name: €{{ env.UNKNOWN }} -> ${{ env.UNKNOWN }} should be equal to - name: €{{ secrets.CASE_INSENSITIVE_SECRET }} -> ${{ secrets.CASE_INSENSITIVE_SECRET }} should be equal to value
run: echo "Done " run: echo "Done "
- name: €{{ env.SOMETHING_TRUE }} -> ${{ env.SOMETHING_TRUE }} should be equal to true - name: €{{ secrets.case_insensitive_secret }} -> ${{ secrets.case_insensitive_secret }} should be equal to value
run: echo "Done " run: echo "Done "
- name: €{{ env.SOMETHING_FALSE }} -> ${{ env.SOMETHING_FALSE }} should be equal to false - name: €{{ env.UNKNOWN }} -> ${{ env.UNKNOWN }} should be equal to
run: echo "Done " run: echo "Done "
- name: €{{ !env.SOMETHING_TRUE }} -> ${{ !env.SOMETHING_TRUE }} should be equal to false - name: €{{ env.SOMETHING_TRUE }} -> ${{ env.SOMETHING_TRUE }} should be equal to true
run: echo "Done " run: echo "Done "
- name: €{{ !env.SOMETHING_FALSE }} -> ${{ !env.SOMETHING_FALSE }} should be equal to false - name: €{{ env.SOMETHING_FALSE }} -> ${{ env.SOMETHING_FALSE }} should be equal to false
run: echo "Done " run: echo "Done "
- name: €{{ !env.SOMETHING_TRUE && true }} -> ${{ !env.SOMETHING_TRUE && true }} should be equal to false - name: €{{ !env.SOMETHING_TRUE }} -> ${{ !env.SOMETHING_TRUE }} should be equal to false
run: echo "Done " run: echo "Done "
- name: €{{ !env.SOMETHING_FALSE && true }} -> ${{ !env.SOMETHING_FALSE && true }} should be equal to false - name: €{{ !env.SOMETHING_FALSE }} -> ${{ !env.SOMETHING_FALSE }} should be equal to false
run: echo "Done " run: echo "Done "
- name: €{{ env.SOMETHING_TRUE && true }} -> ${{ env.SOMETHING_TRUE && true }} should be equal to true - name: €{{ !env.SOMETHING_TRUE && true }} -> ${{ !env.SOMETHING_TRUE && true }} should be equal to false
run: echo "Done " run: echo "Done "
- name: €{{ env.SOMETHING_FALSE && true }} -> ${{ env.SOMETHING_FALSE && true }} should be equal to true - name: €{{ !env.SOMETHING_FALSE && true }} -> ${{ !env.SOMETHING_FALSE && true }} should be equal to false
run: echo "Done " run: echo "Done "
- name: €{{ !env.SOMETHING_TRUE || true }} -> ${{ !env.SOMETHING_TRUE || true }} should be equal to true - name: €{{ env.SOMETHING_TRUE && true }} -> ${{ env.SOMETHING_TRUE && true }} should be equal to true
run: echo "Done " run: echo "Done "
- name: €{{ !env.SOMETHING_FALSE || true }} -> ${{ !env.SOMETHING_FALSE || true }} should be equal to true - name: €{{ env.SOMETHING_FALSE && true }} -> ${{ env.SOMETHING_FALSE && true }} should be equal to true
run: echo "Done " run: echo "Done "
- name: €{{ !env.SOMETHING_TRUE && false }} -> ${{ !env.SOMETHING_TRUE && false }} should be equal to false - name: €{{ !env.SOMETHING_TRUE || true }} -> ${{ !env.SOMETHING_TRUE || true }} should be equal to true
run: echo "Done " run: echo "Done "
- name: €{{ !env.SOMETHING_FALSE && false }} -> ${{ !env.SOMETHING_FALSE && false }} should be equal to false - name: €{{ !env.SOMETHING_FALSE || true }} -> ${{ !env.SOMETHING_FALSE || true }} should be equal to true
run: echo "Done " run: echo "Done "
- name: €{{ !env.SOMETHING_TRUE || false }} -> ${{ !env.SOMETHING_TRUE || false }} should be equal to false - name: €{{ !env.SOMETHING_TRUE && false }} -> ${{ !env.SOMETHING_TRUE && false }} should be equal to false
run: echo "Done " run: echo "Done "
- name: €{{ !env.SOMETHING_FALSE || false }} -> ${{ !env.SOMETHING_FALSE || false }} should be equal to false - name: €{{ !env.SOMETHING_FALSE && false }} -> ${{ !env.SOMETHING_FALSE && false }} should be equal to false
run: echo "Done " run: echo "Done "
- name: €{{ env.SOMETHING_TRUE || false }} -> ${{ env.SOMETHING_TRUE || false }} should be equal to true - name: €{{ !env.SOMETHING_TRUE || false }} -> ${{ !env.SOMETHING_TRUE || false }} should be equal to false
run: echo "Done " run: echo "Done "
- name: €{{ env.SOMETHING_FALSE || false }} -> ${{ env.SOMETHING_FALSE || false }} should be equal to false - name: €{{ !env.SOMETHING_FALSE || false }} -> ${{ !env.SOMETHING_FALSE || false }} should be equal to false
run: echo "Done " run: echo "Done "
- name: €{{ env.SOMETHING_FALSE }} && €{{ env.SOMETHING_TRUE }} -> ${{ env.SOMETHING_FALSE }} && ${{ env.SOMETHING_TRUE }} should be equal to false && true - name: €{{ env.SOMETHING_TRUE || false }} -> ${{ env.SOMETHING_TRUE || false }} should be equal to true
run: echo "Done " run: echo "Done "
- name: €{{ env.SOMETHING_FALSE || false }} -> ${{ env.SOMETHING_FALSE || false }} should be equal to false
run: echo "Done "
- name: €{{ env.SOMETHING_FALSE }} && €{{ env.SOMETHING_TRUE }} -> ${{ env.SOMETHING_FALSE }} && ${{ env.SOMETHING_TRUE }} should be equal to false && true
run: echo "Done "

View file

@ -3,10 +3,10 @@ name: "Test what expressions result in true and false on Github"
on: push on: push
env: env:
SOMETHING_TRUE: true
SOMETHING_FALSE: false
SOME_TEXT: text
ACT: true ACT: true
SOMETHING_FALSE: false
SOMETHING_TRUE: true
SOME_TEXT: text
jobs: jobs:
@ -14,393 +14,393 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: "❌ I should not run, expr: failure()" - name: "❌ I should not run, expr: failure()"
id: step0 id: step0
if: failure() if: failure()
run: echo "failure() should be false, but was evaluated to true;" exit 1; run: echo "failure() should be false, but was evaluated to true;" exit 1;
- name: "✅ I should run, expr: success()" - name: "✅ I should run, expr: success()"
id: step1 id: step1
if: success() if: success()
run: echo OK run: echo OK
- name: "Double checking expr: success()" - name: "Double checking expr: success()"
if: steps.step1.conclusion == 'skipped' if: steps.step1.conclusion == 'skipped'
run: echo "success() should have been true, but wasn't" run: echo "success() should have been true, but wasn't"
- name: "❌ I should not run, expr: cancelled()" - name: "❌ I should not run, expr: cancelled()"
id: step2 id: step2
if: cancelled() if: cancelled()
run: echo "cancelled() should be false, but was evaluated to true;" exit 1; run: echo "cancelled() should be false, but was evaluated to true;" exit 1;
- name: "✅ I should run, expr: always()" - name: "✅ I should run, expr: always()"
id: step3 id: step3
if: always() if: always()
run: echo OK run: echo OK
- name: "Double checking expr: always()" - name: "Double checking expr: always()"
if: steps.step3.conclusion == 'skipped' if: steps.step3.conclusion == 'skipped'
run: echo "always() should have been true, but wasn't" run: echo "always() should have been true, but wasn't"
- name: "✅ I should run, expr: true" - name: "✅ I should run, expr: true"
id: step4 id: step4
if: true if: true
run: echo OK run: echo OK
- name: "Double checking expr: true" - name: "Double checking expr: true"
if: steps.step4.conclusion == 'skipped' if: steps.step4.conclusion == 'skipped'
run: echo "true should have been true, but wasn't" run: echo "true should have been true, but wasn't"
- name: "❌ I should not run, expr: false" - name: "❌ I should not run, expr: false"
id: step5 id: step5
if: false if: false
run: echo "false should be false, but was evaluated to true;" exit 1; run: echo "false should be false, but was evaluated to true;" exit 1;
- name: "✅ I should run, expr: 1 != 0" - name: "✅ I should run, expr: 1 != 0"
id: step8 id: step8
if: 1 != 0 if: 1 != 0
run: echo OK run: echo OK
- name: "Double checking expr: 1 != 0" - name: "Double checking expr: 1 != 0"
if: steps.step8.conclusion == 'skipped' if: steps.step8.conclusion == 'skipped'
run: echo "1 != 0 should have been true, but wasn't" run: echo "1 != 0 should have been true, but wasn't"
- name: "❌ I should not run, expr: 1 != 1" - name: "❌ I should not run, expr: 1 != 1"
id: step9 id: step9
if: 1 != 1 if: 1 != 1
run: echo "1 != 1 should be false, but was evaluated to true;" exit 1; run: echo "1 != 1 should be false, but was evaluated to true;" exit 1;
- name: "✅ I should run, expr: €{{ 1 != 0 }}" - name: "✅ I should run, expr: €{{ 1 != 0 }}"
id: step10 id: step10
if: ${{ 1 != 0 }} if: ${{ 1 != 0 }}
run: echo OK run: echo OK
- name: "Double checking expr: €{{ 1 != 0 }}" - name: "Double checking expr: €{{ 1 != 0 }}"
if: steps.step10.conclusion == 'skipped' if: steps.step10.conclusion == 'skipped'
run: echo "${{ 1 != 0 }} should have been true, but wasn't" run: echo "${{ 1 != 0 }} should have been true, but wasn't"
- name: "❌ I should not run, expr: €{{ 1 != 1 }}" - name: "❌ I should not run, expr: €{{ 1 != 1 }}"
id: step11 id: step11
if: ${{ 1 != 1 }} if: ${{ 1 != 1 }}
run: echo "${{ 1 != 1 }} should be false, but was evaluated to true;" exit 1; run: echo "${{ 1 != 1 }} should be false, but was evaluated to true;" exit 1;
- name: "❌ I should not run, expr: 1 == 0" - name: "❌ I should not run, expr: 1 == 0"
id: step12 id: step12
if: 1 == 0 if: 1 == 0
run: echo "1 == 0 should be false, but was evaluated to true;" exit 1; run: echo "1 == 0 should be false, but was evaluated to true;" exit 1;
- name: "✅ I should run, expr: 1 == 1" - name: "✅ I should run, expr: 1 == 1"
id: step13 id: step13
if: 1 == 1 if: 1 == 1
run: echo OK run: echo OK
- name: "Double checking expr: 1 == 1" - name: "Double checking expr: 1 == 1"
if: steps.step13.conclusion == 'skipped' if: steps.step13.conclusion == 'skipped'
run: echo "1 == 1 should have been true, but wasn't" run: echo "1 == 1 should have been true, but wasn't"
- name: "❌ I should not run, expr: 1 > 2" - name: "❌ I should not run, expr: 1 > 2"
id: step14 id: step14
if: 1 > 2 if: 1 > 2
run: echo "1 > 2 should be false, but was evaluated to true;" exit 1; run: echo "1 > 2 should be false, but was evaluated to true;" exit 1;
- name: "✅ I should run, expr: 1 < 2" - name: "✅ I should run, expr: 1 < 2"
id: step15 id: step15
if: 1 < 2 if: 1 < 2
run: echo OK run: echo OK
- name: "Double checking expr: 1 < 2" - name: "Double checking expr: 1 < 2"
if: steps.step15.conclusion == 'skipped' if: steps.step15.conclusion == 'skipped'
run: echo "1 < 2 should have been true, but wasn't" run: echo "1 < 2 should have been true, but wasn't"
- name: "❌ I should not run, expr: true && false" - name: "❌ I should not run, expr: true && false"
id: step16 id: step16
if: true && false if: true && false
run: echo "true && false should be false, but was evaluated to true;" exit 1; run: echo "true && false should be false, but was evaluated to true;" exit 1;
- name: "✅ I should run, expr: true && 1 < 2" - name: "✅ I should run, expr: true && 1 < 2"
id: step17 id: step17
if: true && 1 < 2 if: true && 1 < 2
run: echo OK run: echo OK
- name: "Double checking expr: true && 1 < 2" - name: "Double checking expr: true && 1 < 2"
if: steps.step17.conclusion == 'skipped' if: steps.step17.conclusion == 'skipped'
run: echo "true && 1 < 2 should have been true, but wasn't" run: echo "true && 1 < 2 should have been true, but wasn't"
- name: "✅ I should run, expr: false || 1 < 2" - name: "✅ I should run, expr: false || 1 < 2"
id: step18 id: step18
if: false || 1 < 2 if: false || 1 < 2
run: echo OK run: echo OK
- name: "Double checking expr: false || 1 < 2" - name: "Double checking expr: false || 1 < 2"
if: steps.step18.conclusion == 'skipped' if: steps.step18.conclusion == 'skipped'
run: echo "false || 1 < 2 should have been true, but wasn't" run: echo "false || 1 < 2 should have been true, but wasn't"
- name: "❌ I should not run, expr: false || false" - name: "❌ I should not run, expr: false || false"
id: step19 id: step19
if: false || false if: false || false
run: echo "false || false should be false, but was evaluated to true;" exit 1; run: echo "false || false should be false, but was evaluated to true;" exit 1;
- name: "❌ I should not run, expr: env.UNKNOWN == 'true'" - name: "❌ I should not run, expr: env.UNKNOWN == 'true'"
id: step20 id: step20
if: env.UNKNOWN == 'true' if: env.UNKNOWN == 'true'
run: echo "env.UNKNOWN == 'true' should be false, but was evaluated to true;" exit 1; run: echo "env.UNKNOWN == 'true' should be false, but was evaluated to true;" exit 1;
- name: "❌ I should not run, expr: env.UNKNOWN" - name: "❌ I should not run, expr: env.UNKNOWN"
id: step21 id: step21
if: env.UNKNOWN if: env.UNKNOWN
run: echo "env.UNKNOWN should be false, but was evaluated to true;" exit 1; run: echo "env.UNKNOWN should be false, but was evaluated to true;" exit 1;
- name: "✅ I should run, expr: env.SOME_TEXT" - name: "✅ I should run, expr: env.SOME_TEXT"
id: step22 id: step22
if: env.SOME_TEXT if: env.SOME_TEXT
run: echo OK run: echo OK
- name: "Double checking expr: env.SOME_TEXT" - name: "Double checking expr: env.SOME_TEXT"
if: steps.step22.conclusion == 'skipped' if: steps.step22.conclusion == 'skipped'
run: echo "env.SOME_TEXT should have been true, but wasn't" run: echo "env.SOME_TEXT should have been true, but wasn't"
- name: "✅ I should run, expr: env.SOME_TEXT == 'text'" - name: "✅ I should run, expr: env.SOME_TEXT == 'text'"
id: step23 id: step23
if: env.SOME_TEXT == 'text' if: env.SOME_TEXT == 'text'
run: echo OK run: echo OK
- name: "Double checking expr: env.SOME_TEXT == 'text'" - name: "Double checking expr: env.SOME_TEXT == 'text'"
if: steps.step23.conclusion == 'skipped' if: steps.step23.conclusion == 'skipped'
run: echo "env.SOME_TEXT == 'text' should have been true, but wasn't" run: echo "env.SOME_TEXT == 'text' should have been true, but wasn't"
- name: "✅ I should run, expr: env.SOMETHING_TRUE == 'true'" - name: "✅ I should run, expr: env.SOMETHING_TRUE == 'true'"
id: step24 id: step24
if: env.SOMETHING_TRUE == 'true' if: env.SOMETHING_TRUE == 'true'
run: echo OK run: echo OK
- name: "Double checking expr: env.SOMETHING_TRUE == 'true'" - name: "Double checking expr: env.SOMETHING_TRUE == 'true'"
if: steps.step24.conclusion == 'skipped' if: steps.step24.conclusion == 'skipped'
run: echo "env.SOMETHING_TRUE == 'true' should have been true, but wasn't" run: echo "env.SOMETHING_TRUE == 'true' should have been true, but wasn't"
- name: "❌ I should not run, expr: env.SOMETHING_FALSE == 'true'" - name: "❌ I should not run, expr: env.SOMETHING_FALSE == 'true'"
id: step25 id: step25
if: env.SOMETHING_FALSE == 'true' if: env.SOMETHING_FALSE == 'true'
run: echo "env.SOMETHING_FALSE == 'true' should be false, but was evaluated to true;" exit 1; run: echo "env.SOMETHING_FALSE == 'true' should be false, but was evaluated to true;" exit 1;
- name: "✅ I should run, expr: env.SOMETHING_TRUE" - name: "✅ I should run, expr: env.SOMETHING_TRUE"
id: step26 id: step26
if: env.SOMETHING_TRUE if: env.SOMETHING_TRUE
run: echo OK run: echo OK
- name: "Double checking expr: env.SOMETHING_TRUE" - name: "Double checking expr: env.SOMETHING_TRUE"
if: steps.step26.conclusion == 'skipped' if: steps.step26.conclusion == 'skipped'
run: echo "env.SOMETHING_TRUE should have been true, but wasn't" run: echo "env.SOMETHING_TRUE should have been true, but wasn't"
- name: "✅ I should run, expr: env.SOMETHING_FALSE" - name: "✅ I should run, expr: env.SOMETHING_FALSE"
id: step27 id: step27
if: env.SOMETHING_FALSE if: env.SOMETHING_FALSE
run: echo OK run: echo OK
- name: "Double checking expr: env.SOMETHING_FALSE" - name: "Double checking expr: env.SOMETHING_FALSE"
if: steps.step27.conclusion == 'skipped' if: steps.step27.conclusion == 'skipped'
run: echo "env.SOMETHING_FALSE should have been true, but wasn't" run: echo "env.SOMETHING_FALSE should have been true, but wasn't"
- name: "❌ I should not run, expr: €{{ !env.SOMETHING_TRUE }}" - name: "❌ I should not run, expr: €{{ !env.SOMETHING_TRUE }}"
id: step30 id: step30
if: ${{ !env.SOMETHING_TRUE }} if: ${{ !env.SOMETHING_TRUE }}
run: echo "${{ !env.SOMETHING_TRUE }} should be false, but was evaluated to true;" exit 1; run: echo "${{ !env.SOMETHING_TRUE }} should be false, but was evaluated to true;" exit 1;
- name: "❌ I should not run, expr: €{{ !env.SOMETHING_FALSE }}" - name: "❌ I should not run, expr: €{{ !env.SOMETHING_FALSE }}"
id: step31 id: step31
if: ${{ !env.SOMETHING_FALSE }} if: ${{ !env.SOMETHING_FALSE }}
run: echo "${{ !env.SOMETHING_FALSE }} should be false, but was evaluated to true;" exit 1; run: echo "${{ !env.SOMETHING_FALSE }} should be false, but was evaluated to true;" exit 1;
- name: "❌ I should not run, expr: €{{ ! env.SOMETHING_TRUE }}" - name: "❌ I should not run, expr: €{{ ! env.SOMETHING_TRUE }}"
id: step32 id: step32
if: ${{ ! env.SOMETHING_TRUE }} if: ${{ ! env.SOMETHING_TRUE }}
run: echo "${{ ! env.SOMETHING_TRUE }} should be false, but was evaluated to true;" exit 1; run: echo "${{ ! env.SOMETHING_TRUE }} should be false, but was evaluated to true;" exit 1;
- name: "❌ I should not run, expr: €{{ ! env.SOMETHING_FALSE }}" - name: "❌ I should not run, expr: €{{ ! env.SOMETHING_FALSE }}"
id: step33 id: step33
if: ${{ ! env.SOMETHING_FALSE }} if: ${{ ! env.SOMETHING_FALSE }}
run: echo "${{ ! env.SOMETHING_FALSE }} should be false, but was evaluated to true;" exit 1; run: echo "${{ ! env.SOMETHING_FALSE }} should be false, but was evaluated to true;" exit 1;
- name: "✅ I should run, expr: €{{ env.SOMETHING_TRUE }}" - name: "✅ I should run, expr: €{{ env.SOMETHING_TRUE }}"
id: step34 id: step34
if: ${{ env.SOMETHING_TRUE }} if: ${{ env.SOMETHING_TRUE }}
run: echo OK run: echo OK
- name: "Double checking expr: €{{ env.SOMETHING_TRUE }}" - name: "Double checking expr: €{{ env.SOMETHING_TRUE }}"
if: steps.step34.conclusion == 'skipped' if: steps.step34.conclusion == 'skipped'
run: echo "${{ env.SOMETHING_TRUE }} should have been true, but wasn't" run: echo "${{ env.SOMETHING_TRUE }} should have been true, but wasn't"
- name: "✅ I should run, expr: €{{ env.SOMETHING_FALSE }}" - name: "✅ I should run, expr: €{{ env.SOMETHING_FALSE }}"
id: step35 id: step35
if: ${{ env.SOMETHING_FALSE }} if: ${{ env.SOMETHING_FALSE }}
run: echo OK run: echo OK
- name: "Double checking expr: €{{ env.SOMETHING_FALSE }}" - name: "Double checking expr: €{{ env.SOMETHING_FALSE }}"
if: steps.step35.conclusion == 'skipped' if: steps.step35.conclusion == 'skipped'
run: echo "${{ env.SOMETHING_FALSE }} should have been true, but wasn't" run: echo "${{ env.SOMETHING_FALSE }} should have been true, but wasn't"
- name: "❌ I should not run, expr: €{{ !env.SOMETHING_TRUE }}" - name: "❌ I should not run, expr: €{{ !env.SOMETHING_TRUE }}"
id: step36 id: step36
if: ${{ !env.SOMETHING_TRUE }} if: ${{ !env.SOMETHING_TRUE }}
run: echo "${{ !env.SOMETHING_TRUE }} should be false, but was evaluated to true;" exit 1; run: echo "${{ !env.SOMETHING_TRUE }} should be false, but was evaluated to true;" exit 1;
- name: "❌ I should not run, expr: €{{ !env.SOMETHING_FALSE }}" - name: "❌ I should not run, expr: €{{ !env.SOMETHING_FALSE }}"
id: step37 id: step37
if: ${{ !env.SOMETHING_FALSE }} if: ${{ !env.SOMETHING_FALSE }}
run: echo "${{ !env.SOMETHING_FALSE }} should be false, but was evaluated to true;" exit 1; run: echo "${{ !env.SOMETHING_FALSE }} should be false, but was evaluated to true;" exit 1;
- name: "❌ I should not run, expr: €{{ !env.SOMETHING_TRUE && true }}" - name: "❌ I should not run, expr: €{{ !env.SOMETHING_TRUE && true }}"
id: step38 id: step38
if: ${{ !env.SOMETHING_TRUE && true }} if: ${{ !env.SOMETHING_TRUE && true }}
run: echo "${{ !env.SOMETHING_TRUE && true }} should be false, but was evaluated to true;" exit 1; run: echo "${{ !env.SOMETHING_TRUE && true }} should be false, but was evaluated to true;" exit 1;
- name: "❌ I should not run, expr: €{{ !env.SOMETHING_FALSE && true }}" - name: "❌ I should not run, expr: €{{ !env.SOMETHING_FALSE && true }}"
id: step39 id: step39
if: ${{ !env.SOMETHING_FALSE && true }} if: ${{ !env.SOMETHING_FALSE && true }}
run: echo "${{ !env.SOMETHING_FALSE && true }} should be false, but was evaluated to true;" exit 1; run: echo "${{ !env.SOMETHING_FALSE && true }} should be false, but was evaluated to true;" exit 1;
- name: "✅ I should run, expr: €{{ !env.SOMETHING_TRUE || true }}" - name: "✅ I should run, expr: €{{ !env.SOMETHING_TRUE || true }}"
id: step40 id: step40
if: ${{ !env.SOMETHING_TRUE || true }} if: ${{ !env.SOMETHING_TRUE || true }}
run: echo OK run: echo OK
- name: "Double checking expr: €{{ !env.SOMETHING_TRUE || true }}" - name: "Double checking expr: €{{ !env.SOMETHING_TRUE || true }}"
if: steps.step40.conclusion == 'skipped' if: steps.step40.conclusion == 'skipped'
run: echo "${{ !env.SOMETHING_TRUE || true }} should have been true, but wasn't" run: echo "${{ !env.SOMETHING_TRUE || true }} should have been true, but wasn't"
- name: "❌ I should not run, expr: €{{ !env.SOMETHING_FALSE || false }}" - name: "❌ I should not run, expr: €{{ !env.SOMETHING_FALSE || false }}"
id: step41 id: step41
if: ${{ !env.SOMETHING_FALSE || false }} if: ${{ !env.SOMETHING_FALSE || false }}
run: echo "${{ !env.SOMETHING_FALSE || false }} should be false, but was evaluated to true;" exit 1; run: echo "${{ !env.SOMETHING_FALSE || false }} should be false, but was evaluated to true;" exit 1;
- name: "✅ I should run, expr: €{{ env.SOMETHING_TRUE && true }}" - name: "✅ I should run, expr: €{{ env.SOMETHING_TRUE && true }}"
id: step42 id: step42
if: ${{ env.SOMETHING_TRUE && true }} if: ${{ env.SOMETHING_TRUE && true }}
run: echo OK run: echo OK
- name: "Double checking expr: €{{ env.SOMETHING_TRUE && true }}" - name: "Double checking expr: €{{ env.SOMETHING_TRUE && true }}"
if: steps.step42.conclusion == 'skipped' if: steps.step42.conclusion == 'skipped'
run: echo "${{ env.SOMETHING_TRUE && true }} should have been true, but wasn't" run: echo "${{ env.SOMETHING_TRUE && true }} should have been true, but wasn't"
- name: "✅ I should run, expr: €{{ env.SOMETHING_FALSE || true }}" - name: "✅ I should run, expr: €{{ env.SOMETHING_FALSE || true }}"
id: step43 id: step43
if: ${{ env.SOMETHING_FALSE || true }} if: ${{ env.SOMETHING_FALSE || true }}
run: echo OK run: echo OK
- name: "Double checking expr: €{{ env.SOMETHING_FALSE || true }}" - name: "Double checking expr: €{{ env.SOMETHING_FALSE || true }}"
if: steps.step43.conclusion == 'skipped' if: steps.step43.conclusion == 'skipped'
run: echo "${{ env.SOMETHING_FALSE || true }} should have been true, but wasn't" run: echo "${{ env.SOMETHING_FALSE || true }} should have been true, but wasn't"
- name: "✅ I should run, expr: €{{ env.SOMETHING_FALSE || false }}" - name: "✅ I should run, expr: €{{ env.SOMETHING_FALSE || false }}"
id: step44 id: step44
if: ${{ env.SOMETHING_FALSE || false }} if: ${{ env.SOMETHING_FALSE || false }}
run: echo OK run: echo OK
- name: "Double checking expr: €{{ env.SOMETHING_FALSE || false }}" - name: "Double checking expr: €{{ env.SOMETHING_FALSE || false }}"
if: steps.step44.conclusion == 'skipped' if: steps.step44.conclusion == 'skipped'
run: echo "${{ env.SOMETHING_FALSE || false }} should have been true, but wasn't" run: echo "${{ env.SOMETHING_FALSE || false }} should have been true, but wasn't"
- name: "✅ I should run, expr: €{{ env.SOMETHING_TRUE == 'true' }}" - name: "✅ I should run, expr: €{{ env.SOMETHING_TRUE == 'true' }}"
id: step46 id: step46
if: ${{ env.SOMETHING_TRUE == 'true'}} if: ${{ env.SOMETHING_TRUE == 'true'}}
run: echo OK run: echo OK
- name: "Double checking expr: €{{ env.SOMETHING_TRUE == 'true' }}" - name: "Double checking expr: €{{ env.SOMETHING_TRUE == 'true' }}"
if: steps.step46.conclusion == 'skipped' if: steps.step46.conclusion == 'skipped'
run: echo "${{ env.SOMETHING_TRUE == 'true'}} should have been true, but wasn't" run: echo "${{ env.SOMETHING_TRUE == 'true'}} should have been true, but wasn't"
- name: "❌ I should not run, expr: €{{ env.SOMETHING_FALSE == 'true' }}" - name: "❌ I should not run, expr: €{{ env.SOMETHING_FALSE == 'true' }}"
id: step47 id: step47
if: ${{ env.SOMETHING_FALSE == 'true'}} if: ${{ env.SOMETHING_FALSE == 'true'}}
run: echo "${{ env.SOMETHING_FALSE == 'true'}} should be false, but was evaluated to true;" exit 1; run: echo "${{ env.SOMETHING_FALSE == 'true'}} should be false, but was evaluated to true;" exit 1;
- name: "✅ I should run, expr: €{{ env.SOMETHING_FALSE == 'false' }}" - name: "✅ I should run, expr: €{{ env.SOMETHING_FALSE == 'false' }}"
id: step48 id: step48
if: ${{ env.SOMETHING_FALSE == 'false'}} if: ${{ env.SOMETHING_FALSE == 'false'}}
run: echo OK run: echo OK
- name: "Double checking expr: €{{ env.SOMETHING_FALSE == 'false' }}" - name: "Double checking expr: €{{ env.SOMETHING_FALSE == 'false' }}"
if: steps.step48.conclusion == 'skipped' if: steps.step48.conclusion == 'skipped'
run: echo "${{ env.SOMETHING_FALSE == 'false'}} should have been true, but wasn't" run: echo "${{ env.SOMETHING_FALSE == 'false'}} should have been true, but wasn't"
- name: "✅ I should run, expr: €{{ env.SOMETHING_FALSE }} && €{{ env.SOMETHING_TRUE }}" - name: "✅ I should run, expr: €{{ env.SOMETHING_FALSE }} && €{{ env.SOMETHING_TRUE }}"
id: step49 id: step49
if: ${{ env.SOMETHING_FALSE }} && ${{ env.SOMETHING_TRUE }} if: ${{ env.SOMETHING_FALSE }} && ${{ env.SOMETHING_TRUE }}
run: echo OK run: echo OK
- name: "Double checking expr: €{{ env.SOMETHING_FALSE }} && €{{ env.SOMETHING_TRUE }}" - name: "Double checking expr: €{{ env.SOMETHING_FALSE }} && €{{ env.SOMETHING_TRUE }}"
if: steps.step49.conclusion == 'skipped' if: steps.step49.conclusion == 'skipped'
run: echo "${{ env.SOMETHING_FALSE }} && ${{ env.SOMETHING_TRUE }} should have been true, but wasn't" run: echo "${{ env.SOMETHING_FALSE }} && ${{ env.SOMETHING_TRUE }} should have been true, but wasn't"
- name: "✅ I should run, expr: false || env.SOMETHING_TRUE == 'true'" - name: "✅ I should run, expr: false || env.SOMETHING_TRUE == 'true'"
id: step50 id: step50
if: false || env.SOMETHING_TRUE == 'true' if: false || env.SOMETHING_TRUE == 'true'
run: echo OK run: echo OK
- name: "Double checking expr: false || env.SOMETHING_TRUE == 'true'" - name: "Double checking expr: false || env.SOMETHING_TRUE == 'true'"
if: steps.step50.conclusion == 'skipped' if: steps.step50.conclusion == 'skipped'
run: echo "false || env.SOMETHING_TRUE == 'true' should have been true, but wasn't" run: echo "false || env.SOMETHING_TRUE == 'true' should have been true, but wasn't"
- name: "✅ I should run, expr: true || env.SOMETHING_FALSE == 'true'" - name: "✅ I should run, expr: true || env.SOMETHING_FALSE == 'true'"
id: step51 id: step51
if: true || env.SOMETHING_FALSE == 'true' if: true || env.SOMETHING_FALSE == 'true'
run: echo OK run: echo OK
- name: "Double checking expr: true || env.SOMETHING_FALSE == 'true'" - name: "Double checking expr: true || env.SOMETHING_FALSE == 'true'"
if: steps.step51.conclusion == 'skipped' if: steps.step51.conclusion == 'skipped'
run: echo "true || env.SOMETHING_FALSE == 'true' should have been true, but wasn't" run: echo "true || env.SOMETHING_FALSE == 'true' should have been true, but wasn't"
- name: "✅ I should run, expr: true && env.SOMETHING_TRUE == 'true'" - name: "✅ I should run, expr: true && env.SOMETHING_TRUE == 'true'"
id: step52 id: step52
if: true && env.SOMETHING_TRUE == 'true' if: true && env.SOMETHING_TRUE == 'true'
run: echo OK run: echo OK
- name: "Double checking expr: true && env.SOMETHING_TRUE == 'true'" - name: "Double checking expr: true && env.SOMETHING_TRUE == 'true'"
if: steps.step52.conclusion == 'skipped' if: steps.step52.conclusion == 'skipped'
run: echo "true && env.SOMETHING_TRUE == 'true' should have been true, but wasn't" run: echo "true && env.SOMETHING_TRUE == 'true' should have been true, but wasn't"
- name: "❌ I should not run, expr: false && env.SOMETHING_TRUE == 'true'" - name: "❌ I should not run, expr: false && env.SOMETHING_TRUE == 'true'"
id: step53 id: step53
if: false && env.SOMETHING_TRUE == 'true' if: false && env.SOMETHING_TRUE == 'true'
run: echo "false && env.SOMETHING_TRUE == 'true' should be false, but was evaluated to true;" exit 1; run: echo "false && env.SOMETHING_TRUE == 'true' should be false, but was evaluated to true;" exit 1;
- name: "❌ I should not run, expr: env.SOMETHING_FALSE == 'true' && env.SOMETHING_TRUE == 'true'" - name: "❌ I should not run, expr: env.SOMETHING_FALSE == 'true' && env.SOMETHING_TRUE == 'true'"
id: step54 id: step54
if: env.SOMETHING_FALSE == 'true' && env.SOMETHING_TRUE == 'true' if: env.SOMETHING_FALSE == 'true' && env.SOMETHING_TRUE == 'true'
run: echo "env.SOMETHING_FALSE == 'true' && env.SOMETHING_TRUE == 'true' should be false, but was evaluated to true;" exit 1; run: echo "env.SOMETHING_FALSE == 'true' && env.SOMETHING_TRUE == 'true' should be false, but was evaluated to true;" exit 1;
- name: "❌ I should not run, expr: env.SOMETHING_FALSE == 'true' && true" - name: "❌ I should not run, expr: env.SOMETHING_FALSE == 'true' && true"
id: step55 id: step55
if: env.SOMETHING_FALSE == 'true' && true if: env.SOMETHING_FALSE == 'true' && true
run: echo "env.SOMETHING_FALSE == 'true' && true should be false, but was evaluated to true;" exit 1; run: echo "env.SOMETHING_FALSE == 'true' && true should be false, but was evaluated to true;" exit 1;
- name: "✅ I should run, expr: €{{ env.SOMETHING_FALSE == 'true' }} && true" - name: "✅ I should run, expr: €{{ env.SOMETHING_FALSE == 'true' }} && true"
id: step56 id: step56
if: ${{ env.SOMETHING_FALSE == 'true' }} && true if: ${{ env.SOMETHING_FALSE == 'true' }} && true
run: echo OK run: echo OK
- name: "Double checking expr: €{{ env.SOMETHING_FALSE == 'true' }} && true" - name: "Double checking expr: €{{ env.SOMETHING_FALSE == 'true' }} && true"
if: steps.step56.conclusion == 'skipped' if: steps.step56.conclusion == 'skipped'
run: echo "${{ env.SOMETHING_FALSE == 'true' }} && true should have been true, but wasn't" run: echo "${{ env.SOMETHING_FALSE == 'true' }} && true should have been true, but wasn't"
- name: "✅ I should run, expr: true && €{{ env.SOMETHING_FALSE == 'true' }}" - name: "✅ I should run, expr: true && €{{ env.SOMETHING_FALSE == 'true' }}"
id: step57 id: step57
if: true && ${{ env.SOMETHING_FALSE == 'true' }} if: true && ${{ env.SOMETHING_FALSE == 'true' }}
run: echo OK run: echo OK
- name: "Double checking expr: true && €{{ env.SOMETHING_FALSE == 'true' }}" - name: "Double checking expr: true && €{{ env.SOMETHING_FALSE == 'true' }}"
if: steps.step57.conclusion == 'skipped' if: steps.step57.conclusion == 'skipped'
run: echo "true && ${{ env.SOMETHING_FALSE == 'true' }} should have been true, but wasn't" run: echo "true && ${{ env.SOMETHING_FALSE == 'true' }} should have been true, but wasn't"
- name: "✅ I should run, expr: €{{ env.ACT }}" - name: "✅ I should run, expr: €{{ env.ACT }}"
id: step60 id: step60
if: ${{ env.ACT }} if: ${{ env.ACT }}
run: echo OK run: echo OK
- name: "Double checking expr: €{{ env.ACT }}" - name: "Double checking expr: €{{ env.ACT }}"
if: steps.step60.conclusion == 'skipped' if: steps.step60.conclusion == 'skipped'
run: echo "${{ env.ACT }} should have been true, but wasn't" run: echo "${{ env.ACT }} should have been true, but wasn't"
- name: "❌ I should not run, expr: €{{ !env.ACT }}" - name: "❌ I should not run, expr: €{{ !env.ACT }}"
id: step61 id: step61
if: ${{ !env.ACT }} if: ${{ !env.ACT }}
run: echo "${{ !env.ACT }} should be false, but was evaluated to true;" exit 1; run: echo "${{ !env.ACT }} should be false, but was evaluated to true;" exit 1;

View file

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"os" "os"
"regexp" "regexp"
"sort"
"testing" "testing"
"github.com/nektos/act/pkg/model" "github.com/nektos/act/pkg/model"
@ -15,7 +16,7 @@ func TestEvaluate(t *testing.T) {
Config: &Config{ Config: &Config{
Workdir: ".", Workdir: ".",
Secrets: map[string]string{ Secrets: map[string]string{
"LOWER_CASE_SECRET": "value", "CASE_INSENSITIVE_SECRET": "value",
}, },
}, },
Env: map[string]string{ Env: map[string]string{
@ -107,7 +108,8 @@ func TestEvaluate(t *testing.T) {
{"matrix.os", "Linux", ""}, {"matrix.os", "Linux", ""},
{"matrix.foo", "bar", ""}, {"matrix.foo", "bar", ""},
{"env.key", "value", ""}, {"env.key", "value", ""},
{"secrets.lower_case_secret", "value", ""}, {"secrets.CASE_INSENSITIVE_SECRET", "value", ""},
{"secrets.case_insensitive_secret", "value", ""},
} }
for _, table := range tables { for _, table := range tables {
@ -131,7 +133,7 @@ func TestInterpolate(t *testing.T) {
Config: &Config{ Config: &Config{
Workdir: ".", Workdir: ".",
Secrets: map[string]string{ Secrets: map[string]string{
"LOWER_CASE_SECRET": "value", "CASE_INSENSITIVE_SECRET": "value",
}, },
}, },
Env: map[string]string{ Env: map[string]string{
@ -160,7 +162,8 @@ func TestInterpolate(t *testing.T) {
{" ${{ env.KEYWITHNOTHING }} ", " valuewithnothing "}, {" ${{ env.KEYWITHNOTHING }} ", " valuewithnothing "},
{" ${{ env.KEY-WITH-HYPHENS }} ", " value-with-hyphens "}, {" ${{ env.KEY-WITH-HYPHENS }} ", " value-with-hyphens "},
{" ${{ env.KEY_WITH_UNDERSCORES }} ", " value_with_underscores "}, {" ${{ env.KEY_WITH_UNDERSCORES }} ", " value_with_underscores "},
{" ${{ secrets.lower_case_secret }} ", " value "}, {"${{ secrets.CASE_INSENSITIVE_SECRET }}", "value"},
{"${{ secrets.case_insensitive_secret }}", "value"},
{"${{ env.UNKNOWN }}", ""}, {"${{ env.UNKNOWN }}", ""},
{"${{ env.SOMETHING_TRUE }}", "true"}, {"${{ env.SOMETHING_TRUE }}", "true"},
{"${{ env.SOMETHING_FALSE }}", "false"}, {"${{ env.SOMETHING_FALSE }}", "false"},
@ -198,11 +201,15 @@ func updateTestExpressionWorkflow(t *testing.T, tables []struct {
}, rc *RunContext) { }, rc *RunContext) {
var envs string var envs string
for k, v := range rc.Env { keys := make([]string, 0, len(rc.Env))
envs += fmt.Sprintf( for k := range rc.Env {
` %s: %s keys = append(keys, k)
`, k, v)
} }
sort.Strings(keys)
for _, k := range keys {
envs += fmt.Sprintf(" %s: %s\n", k, rc.Env[k])
}
workflow := fmt.Sprintf(` workflow := fmt.Sprintf(`
name: "Test how expressions are handled on Github" name: "Test how expressions are handled on Github"
on: push on: push
@ -223,10 +230,7 @@ jobs:
}) })
name := fmt.Sprintf(`%s -> %s should be equal to %s`, expr, table.in, table.out) name := fmt.Sprintf(`%s -> %s should be equal to %s`, expr, table.in, table.out)
echo := `run: echo "Done "` echo := `run: echo "Done "`
workflow += fmt.Sprintf(` workflow += fmt.Sprintf("\n - name: %s\n %s\n", name, echo)
- name: %s
%s
`, name, echo)
} }
file, err := os.Create("../../.github/workflows/test-expressions.yml") file, err := os.Create("../../.github/workflows/test-expressions.yml")

View file

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"os" "os"
"regexp" "regexp"
"sort"
"strings" "strings"
"testing" "testing"
@ -158,11 +159,15 @@ func updateTestIfWorkflow(t *testing.T, tables []struct {
}, rc *RunContext) { }, rc *RunContext) {
var envs string var envs string
for k, v := range rc.Env { keys := make([]string, 0, len(rc.Env))
envs += fmt.Sprintf( for k := range rc.Env {
` %s: %s keys = append(keys, k)
`, k, v)
} }
sort.Strings(keys)
for _, k := range keys {
envs += fmt.Sprintf(" %s: %s\n", k, rc.Env[k])
}
workflow := fmt.Sprintf(` workflow := fmt.Sprintf(`
name: "Test what expressions result in true and false on Github" name: "Test what expressions result in true and false on Github"
on: push on: push
@ -191,18 +196,9 @@ jobs:
echo = `run: echo OK` echo = `run: echo OK`
name = fmt.Sprintf(`"✅ I should run, expr: %s"`, expr) name = fmt.Sprintf(`"✅ I should run, expr: %s"`, expr)
} }
workflow += fmt.Sprintf(` workflow += fmt.Sprintf("\n - name: %s\n id: step%d\n if: %s\n %s\n", name, i, table.in, echo)
- name: %s
id: step%d
if: %s
%s
`, name, i, table.in, echo)
if table.out { if table.out {
workflow += fmt.Sprintf(` workflow += fmt.Sprintf("\n - name: \"Double checking expr: %s\"\n if: steps.step%d.conclusion == 'skipped'\n run: echo \"%s should have been true, but wasn't\"\n", expr, i, table.in)
- name: "Double checking expr: %s"
if: steps.step%d.conclusion == 'skipped'
run: echo "%s should have been true, but wasn't"
`, expr, i, table.in)
} }
} }