Skip to content

Commit

Permalink
Create basic CI workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
jdkula committed Feb 15, 2023
1 parent 55ff36b commit eb01c08
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/run-ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: 'Run build and tests'
on:
push:
workflow_dispatch:
pull_request:

permissions:
contents: read
actions: write

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v3
- name: Run Makefile
run: make
- name: Upload build artifact
uses: actions/upload-artifact@v3
with:
name: program
path: program
retention-days: 1
test_setup:
runs-on: ubuntu-latest
outputs:
test_list: ${{ steps.get_list.outputs.TESTS_JSON }}
steps:
- name: Clone repository
uses: actions/checkout@v3
- name: Install jq
run: |-
apt-get update
apt-get install jq
- name: Get list of tests
id: get_list
run: |-
export TESTS_JSON=$(find ./tests -type f -exec test -x {} \; -print | jq -Rsc 'gsub("\\s*$";"") | split("\n") | sort')
echo "TESTS_JSON=$TESTS_JSON" >> $GITHUB_OUTPUT
test:
runs-on: ubuntu-latest
needs: [build, test-setup]
strategy:
fail-fast: true
matrix:
test: ${{ fromJSON(jobs.test_setup.outputs.test_list) }}
steps:
- name: Clone repository
uses: actions/checkout@v3
- name: Run Makefile
run: make
- name: Run test
run: |-
${{ matrix.test }} "$(pwd)"/program
16 changes: 16 additions & 0 deletions tests/01_example.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/urs/bin/env bash

# (The absolute path to the program is provided as the first and only argument.)
PROGRAM=$1

echo "We've set up a GitHub Actions Workflow that will run all"
echo "of the shell scripts in this directory as a series of tests."
echo
echo "To fail any test, you should use the exit 1 command;"
echo "To end a test early as a success, you should use the exit 0 command."

echo "Invoke your program with the \$PROGRAM variable; an example is below"


# Test 01: Ensure the program runs without error with no arguments.
$PROGRAM

0 comments on commit eb01c08

Please sign in to comment.