From cfd50cddce9e7ddf8cabab2f1f1d2abb80357463 Mon Sep 17 00:00:00 2001 From: Gabriel Simmer Date: Tue, 25 Apr 2023 16:13:49 +0100 Subject: [PATCH] Conditionally run tasks --- .builds/changed-paths.sh | 31 +++++++++++++++++++++++++++++++ .builds/tests.yml | 16 +++++++++++----- .builds/website.yml | 10 ++++++++-- 3 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 .builds/changed-paths.sh diff --git a/.builds/changed-paths.sh b/.builds/changed-paths.sh new file mode 100644 index 0000000..6cf6d3d --- /dev/null +++ b/.builds/changed-paths.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# Get the list of changed paths in the latest commit +changed_paths=$(git diff-tree --no-commit-id --name-only -r HEAD) + +# Variables to track changes in specified paths +source_changed=false +website_changed=false + +# Check if any of the specified paths have changed +for path in $changed_paths; do + if [[ $path == Cargo.* || $path == src/* || $path == .build/* ]]; then + source_changed=true + elif [[ $path == website/* ]]; then + website_changed=true + fi +done + +# Determine the result based on the changes detected +if $source_changed && $website_changed; then + result="all" +elif $source_changed; then + result="source" +elif $website_changed; then + result="website" +else + result="none" +fi + +echo "Result: $result" +exit 0 diff --git a/.builds/tests.yml b/.builds/tests.yml index a2982e3..7a197a1 100644 --- a/.builds/tests.yml +++ b/.builds/tests.yml @@ -11,10 +11,16 @@ environment: tasks: - check: | cd osc-triggers - echo "Running nix flake check..." - nix flake check + export CHANGED_FILES=$(./.builds/changed-paths.sh) + if [[ $CHANGED_FILES == "source" || $CHANGED_FILES == "all" ]]; then + echo "Running nix flake check..." + nix flake check + fi - mirror-to-github: | cd osc-triggers - git remote add github git@github.com:$GITHUB_REPO.git - ssh-keyscan github.com >> ~/.ssh/known_hosts - git push --mirror github + export CHANGED_FILES=$(./.builds/changed-paths.sh) + if [[ $CHANGED_FILES == "source" || $CHANGED_FILES == "all" ]]; then + git remote add github git@github.com:$GITHUB_REPO.git + ssh-keyscan github.com >> ~/.ssh/known_hosts + git push --mirror github + fi diff --git a/.builds/website.yml b/.builds/website.yml index feb0884..e934905 100644 --- a/.builds/website.yml +++ b/.builds/website.yml @@ -9,6 +9,12 @@ sources: tasks: - package: | cd osc-triggers/website - tar -cvz . > ../../site.tar.gz + export CHANGED_FILES=$(../.builds/changed-paths.sh) + if [[ $CHANGED_FILES == "website" || $CHANGED_FILES == "all" ]]; then + tar -cvz . > ../../site.tar.gz + fi - upload: | - hut pages publish -d $site site.tar.gz + export CHANGED_FILES=$(./osc-triggers/.builds/changed-paths.sh) + if [[ $CHANGED_FILES == "website" || $CHANGED_FILES == "all" ]]; then + hut pages publish -d $site site.tar.gz + fi