diff --git a/.gitea/workflows/nix-update.yml b/.gitea/workflows/nix-update.yml index 213def9..0d37533 100644 --- a/.gitea/workflows/nix-update.yml +++ b/.gitea/workflows/nix-update.yml @@ -40,7 +40,6 @@ jobs: cd /tmp/nixpkgs # Configure git author/committer (local to this repo) - # Removing --global to avoid polluting the runner's user config git config user.name "${{ env.GIT_AUTHOR_NAME }}" git config user.email "${{ env.GIT_AUTHOR_EMAIL }}" git config init.defaultBranch master @@ -86,14 +85,35 @@ jobs: UPDATES_FOUND=false UPDATED_PACKAGES="" + # Function to check if commit happened + check_commit() { + local pkg=$1 + local before=$2 + local after=$(git rev-parse HEAD) + + if [ "$before" != "$after" ]; then + echo "✓ Successfully updated $pkg (commit created)" + echo "true" + else + echo "ℹ️ No changes committed for $pkg" + echo "false" + fi + } + # Check if specific package was requested if [ -n "${{ inputs.package }}" ]; then echo "Updating specific package: ${{ inputs.package }}" if [ -d "pkgs/${{ inputs.package }}" ]; then + + BEFORE_HASH=$(git rev-parse HEAD) + + # Run update (allow fail, but capturing output) if nix-update --flake --commit "${{ inputs.package }}" 2>&1 | tee /tmp/update.log; then - UPDATES_FOUND=true - UPDATED_PACKAGES="${{ inputs.package }}" - echo "✓ Updated ${{ inputs.package }}" + # Check if commit was actually made + if [ "$(check_commit "${{ inputs.package }}" "$BEFORE_HASH")" = "true" ]; then + UPDATES_FOUND=true + UPDATED_PACKAGES="${{ inputs.package }}" + fi else echo "ℹ️ Package ${{ inputs.package }} update failed or not needed" cat /tmp/update.log @@ -104,7 +124,7 @@ jobs: else echo "Checking all packages for updates..." - # Get list of package directories (exclude default.nix and AGENTS.md) + # Get list of package directories if [ -d "pkgs" ]; then PACKAGES=$(find pkgs -mindepth 1 -maxdepth 1 -type d -not -name default.nix -not -name AGENTS.md -exec basename {} \; 2>/dev/null | sort) else @@ -121,12 +141,15 @@ jobs: for pkg in $PACKAGES; do echo "" echo "━━━ Checking $pkg ━━━" + + BEFORE_HASH=$(git rev-parse HEAD) + if nix-update --flake --commit "$pkg" 2>&1 | tee /tmp/update-${pkg}.log; then - UPDATES_FOUND=true - UPDATED_PACKAGES="${UPDATED_PACKAGES}, $pkg" - echo "✓ Updated $pkg" + if [ "$(check_commit "$pkg" "$BEFORE_HASH")" = "true" ]; then + UPDATES_FOUND=true + UPDATED_PACKAGES="${UPDATED_PACKAGES}, $pkg" + fi else - # Check if it was actually an update or just "already up to date" if grep -q "already up to date\|No new version found" /tmp/update-${pkg}.log; then echo "ℹ️ $pkg already up to date" else @@ -140,29 +163,24 @@ jobs: # Remove trailing comma from package list UPDATED_PACKAGES=$(echo "$UPDATED_PACKAGES" | sed 's/^, //') - # Check if there are any changes - if [ "$UPDATES_FOUND" = "true" ]; then + # Final verification of changes + COMMIT_COUNT=$(git rev-list --count master..HEAD) + + if [ "$COMMIT_COUNT" -gt 0 ]; then echo "" echo "━━━ Summary ━━━" - echo "✓ Package updates found: $UPDATED_PACKAGES" + echo "✓ $COMMIT_COUNT package updates committed" + echo "Updates: $UPDATED_PACKAGES" echo "has_updates=true" >> $GITHUB_OUTPUT echo "updated_packages=${UPDATED_PACKAGES}" >> $GITHUB_OUTPUT echo "branch_name=${BRANCH_NAME}" >> $GITHUB_OUTPUT - - # Check if there are actual git changes - if git diff-index --quiet HEAD --; then - echo "⚠️ No actual git changes detected despite nix-update success" - echo "has_updates=false" >> $GITHUB_OUTPUT - else - echo "✓ Git changes detected" - git status - fi else echo "" echo "━━━ Summary ━━━" - echo "ℹ️ No package updates found" + echo "ℹ️ No package updates found (no commits created)" echo "has_updates=false" >> $GITHUB_OUTPUT - # Switch back to master if no updates + + # Switch back to master and clean up empty branch git checkout master git branch -D "${BRANCH_NAME}" 2>/dev/null || true fi @@ -174,7 +192,6 @@ jobs: PACKAGES="${{ steps.update.outputs.updated_packages }}" echo "Verifying builds for: $PACKAGES" - # Parse comma-separated package list IFS=', ' read -ra PKG_ARRAY <<< "$PACKAGES" for pkg in "${PKG_ARRAY[@]}"; do echo "━━━ Building $pkg ━━━" @@ -200,7 +217,6 @@ jobs: echo "Creating pull request..." - # Ensure tea is available (using host package) if ! command -v tea &> /dev/null; then echo "Error: tea not found in PATH" exit 1 @@ -212,7 +228,7 @@ jobs: tea login add --name m3ta --url https://code.m3ta.dev --token "${{ secrets.NIX_UPDATE_TOKEN }}" fi - # Get commit messages for PR description + # Get commit messages COMMITS=$(git log origin/master..origin/"${BRANCH}" --pretty=format:"%h %s" | sed 's/^/- /') # Create PR