Skip to content

Instantly share code, notes, and snippets.

@parjun8840
Last active January 21, 2023 00:09
Show Gist options
  • Save parjun8840/29c08f16fe5c51737b347c2d4683a809 to your computer and use it in GitHub Desktop.
Save parjun8840/29c08f16fe5c51737b347c2d4683a809 to your computer and use it in GitHub Desktop.
build_failure workflow with dummy build and test script
#gha01/.github/workflows/build_failure.yml
% cat build_failure.yml
on: [push]
jobs:
FailBuildIssueDemo:
runs-on: ubuntu-latest
steps:
- name: checkout the code
uses: actions/checkout@v3
- name: build
run: |
pwd
ls -lrtR
bash build.sh
- name: test
run: bash test.sh
id: test
- name: upload
run: bash build.sh
if: success() || steps.test.conclusion == 'failure'
- name: create issue on build or test failure
if: ${{ failure() }}
run: |
curl --request POST \
--url https://api.github.com/repos/${{ github.repository }}/issues \
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
--header 'content-type: application/json' \
--data '{
"title": "Issue created bcz of workflow fialure: ${{ github.run_id }}",
"body": "This issue was automatically created by the GitHub Action workflow **${{ github.workflow }}**. \n\n due to failure in run: _${{ github.run_id }}_."
}'
#gha01/build.sh
% cat build.sh
#!/bin/bash
var="Hello World"
# Store date, hostname & pwd command output to shell variables
now="$(date)"
host_name="$(hostname)"
pwd="$(pwd)"
# print variables
echo "$var"
echo "Current date and time : $now"
echo "Computer name : $hostname_name"
echo "PWD: $pwd"
#gha01/test.sh
% cat test.sh
#!/bin/bash
cat << EOF
1..13
ok 1 - IS $(whoami) != root
ok 2 - IS "$var" =~ parjun8840
ok 3 - ISNT "$var" == parjun8840
ok 4 - OK -f /etc/passwd
ok 5 - NOK -w /etc/passwd
ok 6 - RUNS true
ok 7 - NRUNS false
ok 8 - RUNS echo -e 'parjun8840\nbar\nbaz'
ok 9 - GREP bar
ok 10 - OGREP bar
ok 11 - NEGREP . # verify empty
ok 12 - DIFF. # verify empty
not ok 13 - TODO RUNS false # TODO Test Know to fail
EOF
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment