Merge pull request #82 from seannowotny/patch-3 #256
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: Tangle code extracted from documentation | |
on: | |
# Runs on pushes targeting the default branch | |
push: | |
branches: ["main"] | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | |
permissions: | |
contents: read | |
# Allow one concurrent test | |
concurrency: | |
group: "tangle" | |
cancel-in-progress: true | |
env: | |
BUILD_TYPE: Release | |
jobs: | |
# Tangle job | |
tangle: | |
runs-on: ubuntu-latest | |
outputs: | |
tangle-roots: ${{ steps.set-tangle-roots.outputs.roots }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Setup Pages | |
uses: actions/configure-pages@v2 | |
- name: Setup Python | |
run: pip install -r requirements.txt | |
- name: Build with Sphinx | |
run: make tangle | |
- name: List tangle roots | |
id: set-tangle-roots | |
run: echo "roots=$(printf '['; find _build/tangle -maxdepth 1 -mindepth 1 -type d -printf '"%P", '; printf ']\n')" >> $GITHUB_OUTPUT | |
- name: Upload artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: tangled-code | |
path: _build/tangle | |
# Filter unnecessary tests | |
filter-unchanged: | |
runs-on: ubuntu-latest | |
needs: tangle | |
outputs: | |
tangle-roots: ${{ steps.filter-tangle-roots.outputs.roots }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Download current tangle | |
uses: actions/download-artifact@v3 | |
with: | |
name: tangled-code | |
path: current | |
- name: Download previous tangle | |
id: download-previous-tangle | |
continue-on-error: true | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
RUN_ID: ${{ github.run_id }} | |
REPO: ${{ github.repository }} | |
BRANCH: ${{ github.branch }} | |
run: | | |
# FTR: API_HEADERS="-H 'Accept: application/vnd.github+json' -H 'X-GitHub-Api-Version: 2022-11-28'" | |
API_PREFIX=repos/$REPO/actions | |
# Get Workflow ID from Run ID | |
WORKFLOW_ID=$(gh api $API_PREFIX/runs/$RUN_ID -q .workflow_id) | |
echo WORKFLOW_ID=$WORKFLOW_ID | |
# Get previous Run ID from Workflow ID | |
PREV_RUN_ID=$(gh api "$API_PREFIX/workflows/$WORKFLOW_ID/runs?status=success&per_page=1&branch=$BRANCH" -q '.workflow_runs[0] | .id') | |
echo PREV_RUN_ID=$PREV_RUN_ID | |
# Download previous artifact | |
gh run download $PREV_RUN_ID -R $REPO -n tangled-code -D previous | |
- name: Filter out unchanged roots | |
if: failure() || success() | |
id: filter-tangle-roots | |
env: | |
roots: ${{ needs.tangle.outputs.tangle-roots }} | |
downloadPreviousOutcome: ${{ steps.download-previous-tangle.outcome }} | |
run: |- | |
if [[ $downloadPreviousOutcome -eq "success" ]] | |
then | |
# Only keep the ones that changed | |
echo "roots=$(python tools/filter_unchanged_tangle_roots.py "$roots" current previous)" >> $GITHUB_OUTPUT | |
else | |
# Just forward the list | |
echo "roots=$roots" >> $GITHUB_OUTPUT | |
fi | |
# Test job | |
test: | |
if: ${{ needs.filter-unchanged.outputs.tangle-roots != '[]' }} | |
strategy: | |
matrix: | |
os: [ubuntu-latest, windows-latest, macos-latest] | |
tangle-root: ${{ fromJson(needs.filter-unchanged.outputs.tangle-roots) }} | |
include: | |
- os: ubuntu-latest | |
install-deps: | | |
sudo apt-get update -y | |
sudo apt-get install -y xorg-dev | |
runs-on: ${{ matrix.os }} | |
needs: [tangle, filter-unchanged] | |
steps: | |
- if: ${{ matrix.install-deps }} | |
name: Install dependencies | |
run: ${{ matrix.install-deps }} | |
- name: Download artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: tangled-code | |
- name: Configure CMake | |
run: > | |
cmake | |
-S "${{ matrix.tangle-root }}" | |
-B ${{github.workspace}}/build | |
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} | |
-DGLFW_BUILD_WAYLAND=OFF | |
- name: Build | |
run: > | |
cmake | |
--build ${{github.workspace}}/build | |
--config ${{env.BUILD_TYPE}} |