diff --git a/.github/filters.yaml b/.github/filters.yaml new file mode 100644 index 0000000..fdff690 --- /dev/null +++ b/.github/filters.yaml @@ -0,0 +1,27 @@ +# nix updates are common to all workflows +nix: &nix + - "flake.nix" + - "flake.lock" +docs-shell: + - *nix + - "docs/**/*.nix" + - "docs/pyproject/**" +docs: + - "docs/**" + - *nix + # software paths should only include files which are used by Doxygen + - "software/**/*.cpp" + - "software/**/*.hpp" + - "software/**/*.c" + - "software/**/*.h" + - "software/**/*.py" + - "software/**/*.pyi" +software: + - "software/**" + - *nix + # ignore script updates + - "!software/scripts/**" + - "!software/ros_ws/colcon/**" + # we don't care about package.xml updates since they don't affect the nix build, + # we only care about it when the nix files get updated + - "!software/ros_ws/**/package.xml" diff --git a/.github/workflows/all.yaml b/.github/workflows/all.yaml new file mode 100644 index 0000000..bea02cf --- /dev/null +++ b/.github/workflows/all.yaml @@ -0,0 +1,103 @@ +name: Nix CI/CD +on: [push, pull_request, workflow_dispatch] +permissions: + contents: read +jobs: + # get the file changes to filter other jobs + changes: + name: Detect changes + runs-on: ubuntu-latest + outputs: + software: ${{ steps.filter.outputs.software }} + docs: ${{ steps.filter.outputs.docs }} + docs-shell: ${{ steps.filter.outputs.docs-shell }} + steps: + - uses: actions/checkout@v4 + - uses: dorny/paths-filter@v3 + id: filter + with: + filters: .github/filters.yaml + format: + name: Format and lint + # jobs which push to the repo all need to be in this concurrency group + concurrency: + group: "push" + # needed to push changes if needed + permissions: + contents: write + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: nixbuild/nix-quick-install-action@v29 + - uses: DeterminateSystems/magic-nix-cache-action@main + - name: Format and lint repository + run: nix fmt + - uses: stefanzweifel/git-auto-commit-action@v5 + # don't want to run the commit action on pull request workflows (ie, after the merge commit), only on push + # note: this applies to all push workflows, not just this job + if: ${{ github.event_name != 'pull_request' }} + with: + commit_message: "Run format and lint" + docs-shell: + runs-on: ubuntu-latest + if: ${{ needs.changes.outputs.docs-shell == 'true' }} + needs: [changes, format] + steps: + - uses: actions/checkout@v4 + - uses: nixbuild/nix-quick-install-action@v29 + - uses: DeterminateSystems/magic-nix-cache-action@main + - name: Upload docs dev shell to Cachix + run: nix run -L .#scripts.cachix.docs-shell + env: + CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_AUTH_TOKEN }} + docs: + runs-on: ubuntu-latest + if: ${{ needs.changes.outputs.docs == 'true' }} + needs: [changes, format, docs-shell] + steps: + - uses: actions/checkout@v4 + - uses: nixbuild/nix-quick-install-action@v29 + - uses: DeterminateSystems/magic-nix-cache-action@main + - name: Build docs + run: nix build -L .#docs + # From here, deploying to the website repo + - name: Checkout website repo + # only run on origin main branch + if: ${{ (github.event_name != 'pull_request') && (github.repository == 'ROAR-QUTRC/perseus-v2') && (github.ref == 'refs/heads/main') }} + id: checkout-website + uses: actions/checkout@v4 + with: + repository: ROAR-QUTRC/roar-qutrc.github.io + ssh-key: ${{ secrets.DOCS_DEPLOY_KEY }} + path: docs + - name: Update docs in checked out repo + if: ${{ steps.checkout-website.outcome == 'success' }} + run: | + rm -rf docs/* + cp -a result/html/. docs/ + - uses: stefanzweifel/git-auto-commit-action@v5 + name: Commit and push changes + if: ${{ steps.checkout-website.outcome == 'success' }} + with: + commit_message: "Update generated docs" + repository: ./docs + build: + runs-on: ubuntu-latest + if: ${{ needs.changes.outputs.software == 'true' }} + needs: [changes, format] + steps: + - uses: actions/checkout@v4 + - uses: nixbuild/nix-quick-install-action@v29 + - uses: DeterminateSystems/magic-nix-cache-action@main + - name: Build repository + run: nix build -L + - name: Upload build to Cachix + run: nix run -L .#scripts.cachix.build + - name: Test dev shell + run: nix develop -L -c echo 'Shell test success' + - name: Upload dev shell to Cachix + run: nix run -L .#scripts.cachix.shell + - name: Run flake checks + run: nix flake check -L + env: + CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_AUTH_TOKEN }} diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml deleted file mode 100644 index bf0c821..0000000 --- a/.github/workflows/build.yaml +++ /dev/null @@ -1,41 +0,0 @@ -# Workflow to build the repo, run tests, and push the binaries to Cachix -name: Build repo and run tests -on: - push: - # no point rebuilding if the code doesn't change - paths: - - "software/**" - - "flake.nix" - - "flake.lock" - # ignore script updates - - "!software/scripts/**" - - "!software/ros_ws/colcon/**" - # we don't care about package.xml updates since they don't affect the nix build, - # we only care about it when the nix files get updated - - "!software/ros_ws/**/package.xml" - # launch files don't affect the tests - - "!software/ros_ws/**/launch/**" - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: -jobs: - run-build: - concurrency: - group: "build" - cancel-in-progress: true - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: nixbuild/nix-quick-install-action@v29 - - uses: DeterminateSystems/magic-nix-cache-action@main - - name: Build repository - run: nix build -L - - name: Run flake checks - run: nix flake check -L - - name: Upload build to Cachix - run: nix run -L .#scripts.cachix.build - - name: Test dev shell - run: nix develop -L -c echo 'Shell test success' - - name: Upload dev shell to Cachix - run: nix run -L .#scripts.cachix.shell - env: - CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_AUTH_TOKEN }} diff --git a/.github/workflows/deploy-docs.yaml b/.github/workflows/deploy-docs.yaml deleted file mode 100644 index 98c62be..0000000 --- a/.github/workflows/deploy-docs.yaml +++ /dev/null @@ -1,75 +0,0 @@ -# Workflow to build and deploy the docs using a deploy key -name: Deploy documentation to GH Pages -on: - push: - paths: - - "docs/**" - # software paths should only include files which are used by Doxygen - - "software/**/*.cpp" - - "software/**/*.hpp" - - "software/**/*.c" - - "software/**/*.h" - - "software/**/*.py" - - "software/**/*.pyi" - - "flake.nix" - - "flake.lock" - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: -# only run one job at a time -# needed for the intersphinx update -concurrency: - group: "docs" - cancel-in-progress: true -jobs: - deploy-docs: - # jobs which push to the repo all need to be in this concurrency group - concurrency: - group: "pushers" - permissions: - contents: write - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - path: source - - uses: nixbuild/nix-quick-install-action@v29 - # - uses: DeterminateSystems/magic-nix-cache-action@main - - name: Update intersphinx inventory files - # only run intersphinx update on main branch! - if: ${{ github.ref == 'refs/heads/main' }} - continue-on-error: true # if there are no changes to the files, technically this fails - run: | - cd source - git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - git config user.name "github-actions[bot]" - nix run .#docs.fetch-inventories - git push - - name: Build docs - run: nix build -L ./source#docs - # From here, deploying to the website repo - - name: Checkout website repo - # only run on origin main branch - if: ${{ github.repository == 'ROAR-QUTRC/perseus-v2' && github.ref == 'refs/heads/main' }} - id: checkout-website - uses: actions/checkout@v4 - with: - repository: ROAR-QUTRC/roar-qutrc.github.io - ref: main - ssh-key: ${{ secrets.DOCS_DEPLOY_KEY }} - path: docs - - name: Update docs in checked out repo - if: ${{ steps.checkout-website.outcome == 'success' }} - run: | - rm -rf docs/* - # copy from previous nix build - cp -a result/html/. docs/ - - name: Commit and push changes - if: ${{ steps.checkout-website.outcome == 'success' }} - continue-on-error: true # if there's nothing to push, this step fails - run: | - cd docs - git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - git config user.name "github-actions[bot]" - git add . - git commit -m "$(date +%z:%Y-%m-%dT%H:%M:%S) Automatic docs update" - git push diff --git a/.github/workflows/intersphinx.yaml b/.github/workflows/intersphinx.yaml new file mode 100644 index 0000000..c1392f3 --- /dev/null +++ b/.github/workflows/intersphinx.yaml @@ -0,0 +1,23 @@ +on: + schedule: + # WARNING: When @RandomSpaceship leaves the project, this will need to be updated + # see: https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#schedule + # note: the time is semi-random + - cron: "42 0 * * 1" +jobs: + intersphinx: + if: ${{ github.ref == 'refs/heads/main' }} + concurrency: + group: "push" + permissions: + contents: write + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: nixbuild/nix-quick-install-action@v29 + - uses: DeterminateSystems/magic-nix-cache-action@main + - name: Update intersphinx inventory files + run: nix run .#docs.fetch-inventories + - uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: "Update intersphinx inventory files" diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml deleted file mode 100644 index 16fd0a9..0000000 --- a/.github/workflows/lint.yaml +++ /dev/null @@ -1,32 +0,0 @@ -# Workflow to format + lint the repo -name: Format and lint repository -on: - # Run on any push - we always want the code formatted! - push: - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: -# only run one job at a time -concurrency: - group: "format" - cancel-in-progress: true -jobs: - run-format: - # jobs which push to the repo all need to be in this concurrency group - concurrency: - group: "pushers" - # needed to push changes if needed - permissions: - contents: write - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: nixbuild/nix-quick-install-action@v29 - - uses: DeterminateSystems/magic-nix-cache-action@main - - name: Format and lint repository - run: nix fmt - - name: Push changes - continue-on-error: true # if there are no changes to the files, technically this fails - run: | - git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - git config user.name "github-actions[bot]" - git push