Skip to content

Commit

Permalink
Run MacOS tests every night instead of every pull request (#756)
Browse files Browse the repository at this point in the history
  • Loading branch information
Akuli authored Feb 7, 2025
1 parent 119bd85 commit f0c3258
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 61 deletions.
56 changes: 42 additions & 14 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
on:
push:
branches:
- main
pull_request:
# MacOS is super slow in GitHub Actions for some reason, so run this every
# night instead of every pull request.
schedule:
- cron: '0 4 * * *'
workflow_dispatch: # Can also be triggered manually from github UI

jobs:
# Please keep in sync with valgrind.yml
check-if-needed:
timeout-minutes: 1
runs-on: ubuntu-latest
outputs:
needed: ${{ steps.check.outputs.run }}
steps:
- uses: actions/checkout@v4
- id: check
run: |
if [ "$GITHUB_EVENT_NAME" == "workflow_dispatch" ]; then
echo "Triggered manually"
echo "run=true" >> $GITHUB_OUTPUT
elif [ "$GITHUB_REPOSITORY" != "Akuli/jou" ]; then
echo "This is a fork of Jou, skipping"
echo "run=false" >> $GITHUB_OUTPUT
elif git --no-pager log --oneline --since="24 hours ago" --exit-code; then
echo "No recent commits, skipping"
echo "run=false" >> $GITHUB_OUTPUT
else
echo "run=true" >> $GITHUB_OUTPUT
fi
bootstrap:
needs: check-if-needed
if: ${{ needs.check-if-needed.outputs.needed == 'true' }}
runs-on: macos-latest
timeout-minutes: 10
steps:
Expand All @@ -19,7 +45,8 @@ jobs:
path: jou_bootstrap

test:
needs: bootstrap
needs: [bootstrap, check-if-needed]
if: ${{ needs.check-if-needed.outputs.needed == 'true' }}
runs-on: macos-latest
timeout-minutes: 10
strategy:
Expand All @@ -42,16 +69,17 @@ jobs:
run: mv jou jou_bootstrap && make
- name: "Compile and test again"
run: ./runtests.sh --verbose --jou-flags "${{ matrix.opt-level }}"
- run: ./doctest.sh

doctest:
needs: bootstrap
runs-on: macos-latest
# Please keep in sync with valgrind.yml
create-issue-on-failure:
name: Create an issue if failed
runs-on: ubuntu-latest
timeout-minutes: 5
needs: [check-if-needed, bootstrap, test]
if: ${{ github.repository == 'Akuli/jou' && always() && needs.check-if-needed.outputs.needed == 'true' && (needs.bootstrap.result == 'failure' || needs.test.result == 'failure') }}
permissions:
issues: write
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: bootstrapped
- run: chmod +x jou_bootstrap
- run: brew install bash diffutils llvm@15
- run: ./doctest.sh
- run: ./create_issue.sh "${{ secrets.GITHUB_TOKEN }}" "Running tests on MacOS failed"
52 changes: 5 additions & 47 deletions .github/workflows/valgrind.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
workflow_dispatch: # Can also be triggered manually from github UI

jobs:
# Check if there was any commits within the last 24 hours
# Please keep in sync with macos.yml
check-if-needed:
timeout-minutes: 1
runs-on: ubuntu-latest
Expand Down Expand Up @@ -73,57 +73,15 @@ jobs:
- name: "Test compiler with valgrind"
run: ./runtests.sh --verbose --valgrind --jou-flags "${{ matrix.opt-level }}"

# Based on: https://github.com/python/typeshed/blob/9f28171658b9ca6c32a7cb93fbb99fc92b17858b/.github/workflows/daily.yml
# Please keep in sync with macos.yml
create-issue-on-failure:
name: Create an issue if valgrind failed
name: Create an issue if failed
runs-on: ubuntu-latest
timeout-minutes: 5
needs: [check-if-needed, bootstrap, valgrind]
if: ${{ github.repository == 'Akuli/jou' && always() && needs.check-if-needed.outputs.needed == 'true' && (needs.bootstrap.result == 'failure' || needs.valgrind.result == 'failure') }}
permissions:
issues: write
steps:
- run: |
# Usage: find_issue <title>
# Echos issue number, if any
function find_issue() {
curl -s "https://api.github.com/repos/${{ github.repository }}/issues?state=open" \
| jq -r --arg t "$1" '.[] | select(.title==$t) | .number'
}
# Usage: get_body <issue_number>
function get_body() {
curl -s "https://api.github.com/repos/${{ github.repository }}/issues/$1" | jq -r .body
}
# Usage: echo body | set_body <issue_number>
function set_body() {
curl -s -X PATCH \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/${{ github.repository }}/issues/$1" \
-d "$(jq -n --arg b "$(cat)" '{body: $b}')"
}
# Usage: echo body | new_issue <title>
function new_issue() {
curl -s -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/${{ github.repository }}/issues" \
-d "$(jq -n --arg t "$1" --arg b "$(cat)" '{title: $t, body: $b}')"
}
link="- [$(date)](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})"
echo $link
echo "Checking if there is already an issue about valgrind errors..."
n=$(find_issue "Running tests with valgrind failed")
if [ -n "$n" ]; then
echo "There is already an open issue about the valgrind errors. Appending link to issue description."
((get_body $n | awk 1) && echo "$link") | set_body $n
else
echo "No open issue found, creating a new one."
(echo "Valgrind outputs:" && echo "$link") | new_issue "Running tests with valgrind failed"
fi
- uses: actions/checkout@v4
- run: ./create_issue.sh "${{ secrets.GITHUB_TOKEN }}" "Running tests with valgrind failed"
63 changes: 63 additions & 0 deletions create_issue.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash

# This script is invoked from GitHub actions that run every night.
# It creates an issue on GitHub that lets me know the tests failed.

set -e -o pipefail

if [ -z "$GITHUB_RUN_ID" ]; then
echo "This script can only be ran in GitHub Actions"
exit 1
fi

if [ $# != 2 ]; then
echo "Usage: $0 <github-token> <issue-title>"
exit 2
fi

auth_header="Authorization: token $1"
issue_title="$2"

# Usage: find_issue <title>
# Echos issue number, if any
function find_issue() {
curl -s "https://api.github.com/repos/Akuli/jou/issues?state=open" \
| jq -r --arg t "$1" '.[] | select(.title==$t) | .number'
}

# Usage: get_body <issue_number>
function get_body() {
curl -s "https://api.github.com/repos/Akuli/jou/issues/$1" | jq -r .body
}

# Usage: echo body | set_body <issue_number>
function set_body() {
curl -s -X PATCH \
-H "$auth_header" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/Akuli/jou/issues/$1" \
-d "$(jq -n --arg b "$(cat)" '{body: $b}')"
}

# Usage: echo body | new_issue <title>
function new_issue() {
curl -s -X POST \
-H "$auth_header" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/Akuli/jou/issues" \
-d "$(jq -n --arg t "$1" --arg b "$(cat)" '{title: $t, body: $b}')"
}

link="- [$(date)](https://github.com/Akuli/jou/actions/runs/$GITHUB_RUN_ID)"
echo $link

echo "Checking if there is already an issue with title \"$issue_title\"..."
n=$(find_issue "$issue_title")

if [ -n "$n" ]; then
echo "There is already an open issue (#$n). Appending link to issue description."
( (get_body $n | awk 1) && echo "$link") | set_body $n
else
echo "No open issue found, creating a new one."
(echo "Test outputs:" && echo "$link") | new_issue "$issue_title"
fi

0 comments on commit f0c3258

Please sign in to comment.