Create setup job to set dry-run #36
This file contains 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
name: Main - explore CI primitives | |
on: | |
push: | |
branches: | |
- main | |
env: | |
KOSLI_WIBBLE: "2.3" | |
# KOSLI_DRY_RUN: "false" | |
jobs: | |
setup: | |
runs-on: ubuntu-latest | |
outputs: | |
kosli_dry_run: ${{ steps.prepare.outputs.kosli_dry_run }} | |
steps: | |
- name: set-env-var in setup | |
id: prepare | |
run: | | |
if ${{ github.ref == 'refs/heads/main' }} ; then | |
value=true | |
else | |
value=false | |
fi | |
echo "kosli_dry_run=$(echo $value)" >> ${GITHUB_OUTPUT} | |
job-1: | |
runs-on: ubuntu-latest | |
needs: [ setup ] | |
env: | |
KOSLI_DRY_RUN: "${{ needs.setup.outputs.kosli_dry_run }}" | |
steps: | |
- name: step-1 from job-1 | |
run: | | |
echo Hello from job-1, step-1 | |
echo "KOSLI_DRY_RUN=:${{ env.KOSLI_DRY_RUN }}:" | |
echo ":${{ github.ref == 'refs/heads/master' }}:" | |
if ${{ github.ref == 'refs/heads/main' }} ; then | |
echo we are inside the bald if | |
exit 25 | |
else | |
echo we are inside the bald else | |
exit 24 | |
fi | |
if [ "${{ github.ref == 'refs/heads/master' }}" == "false" ]; then | |
echo we are inside the if | |
exit 27 | |
fi | |
if [ ${{ github.ref == 'refs/heads/master' }} ]; then | |
echo its-true | |
exit 28 | |
else | |
echo its-false | |
fi | |
echo do we get here | |
exit 42 | |
- name: step-2 from job-1 | |
if: "(success() || failure()) && (github.ref == 'refs/heads/main')" | |
run: | |
echo Hello from job-1, step-2 | |
exit 43 | |
- name: step-3 from job-1 | |
if: ${{ success() || failure() }} | |
run: | |
echo Hello from job-1, step-3 | |
exit 44 | |
job-2: | |
runs-on: ubuntu-latest | |
needs: [ job-1 ] | |
if: ${{ success() || failure() }} | |
steps: | |
- name: step-1 from job-2 | |
run: | | |
echo Hello from job-2, step-1 | |
echo "TEST_UNIT_COVERAGE_IS_COMPLIANT=wibble" >> ${GITHUB_ENV} | |
- name: step-2 from job-2 | |
run: | | |
echo Hello from job-2, step-2 | |
echo "env-var=:${{ env.TEST_UNIT_COVERAGE_IS_COMPLIANT }}:" | |
# plain exit-42 on job-1,step-1 and success()||failure() on job-1,step-2 means | |
# job-1,step-2 runs? YES | |
# job-2 runs? NO | |
# plain exit-42 on job-1,step-1 and NO success()||failure() on job-1,step-2 means | |
# job-1,step-2 runs? NO | |
# job-2 runs? NO | |
# With this... | |
# - name: step-1 from job-1 | |
# run: | | |
# echo Hello from job-1, step-1 | |
# sdf | |
# echo Hello from job-1, step-1, after an error | |
# exit 42 | |
# then | |
# the second echo is NOT run, and the exit code of the job is 127 (not 42) | |
# With this... | |
# job-2: | |
# runs-on: ubuntu-latest | |
# needs: [ job-1 ] | |
# if: ${{ success() || failure() }} | |
# then | |
# job1 failed, job2 waits for job1 to finish, and does then run. | |
# Putting continue-on-error: true | |
# at the step level, means that if the step fails | |
# the other steps still run, and the job succeeds | |
# Eg, there is no "Rerun failed jobs" option in the CI. | |
# Putting continue-on-error: true | |
# at the job-2 level, seems to have no effect. | |
# job1 fails, but job2 is not run (it is skipped) | |
# Putting continue-on-error: true | |
# at the job-1 level, means that job1 steps 2,3 are not run. | |
# and job-1 fails, and job-2 is run. | |
# env-var added to >> ${GITHUB_ENV} | |
# is available in the next step (in the same job) |