diff --git a/action.yml b/action.yml index 5c834a2..a5d3559 100644 --- a/action.yml +++ b/action.yml @@ -38,6 +38,8 @@ inputs: {{ env.GIT_COMMIT_MESSAGE }} ``` + {{ env.GIT_COMMIT_MESSAGE_2 }} + ### Running GitHub Actions on this PR GitHub Actions will not run workflows on pull requests which are opened by a GitHub Action. @@ -154,6 +156,9 @@ runs: TARGETS: ${{ inputs.inputs }} COMMIT_MSG: ${{ inputs.commit-msg }} PATH_TO_FLAKE_DIR: ${{ inputs.path-to-flake-dir }} + - name: Compare flake.lock files + run: $GITHUB_ACTION_PATH/compare-flake-lock.sh | tee urls.txt + shell: bash - name: Save PR Body as file uses: DamianReeves/write-file-action@v1.2 with: @@ -169,6 +174,11 @@ runs: echo "$COMMIT_MESSAGE" >> $GITHUB_ENV echo "$DELIMITER" >> $GITHUB_ENV echo "GIT_COMMIT_MESSAGE is: ${COMMIT_MESSAGE}" + COMMIT_MESSAGE_2="$(cat urls.txt)" + echo "GIT_COMMIT_MESSAGE_2<<$DELIMITER" >> $GITHUB_ENV + echo "$COMMIT_MESSAGE_2" >> $GITHUB_ENV + echo "$DELIMITER" >> $GITHUB_ENV + echo "GIT_COMMIT_MESSAGE_2 is: ${COMMIT_MESSAGE_2}" - name: Interpolate PR Body uses: pedrolamas/handlebars-action@v2.2.0 with: @@ -184,7 +194,7 @@ runs: # action commits all new and modified files). - name: Remove PR body template files shell: bash - run: rm -f pr_body.txt pr_body.template + run: rm -f pr_body.txt pr_body.template urls.txt - name: Create PR id: create-pr uses: peter-evans/create-pull-request@v4 diff --git a/compare-flake-lock.sh b/compare-flake-lock.sh new file mode 100755 index 0000000..3b99263 --- /dev/null +++ b/compare-flake-lock.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +set -euo pipefail + +git checkout HEAD~1 &>/dev/null +nodes1="$(nix flake metadata '.#' --json | jq '.locks.nodes')" +git checkout - &>/dev/null +nodes2="$(nix flake metadata '.#' --json | jq '.locks.nodes')" +keys1="$(echo "${nodes1}" | jq 'keys | .[]')" +keys2="$(echo "${nodes2}" | jq 'keys | .[]')" + +if [[ "${keys1}" != "${keys2}" ]]; then + echo 'Flake inputs changed!' + exit 1 +fi + +for key in ${keys1}; do + owner="$(echo "${nodes1}" | jq -r ".${key}.locked.owner")" + repo="$(echo "${nodes1}" | jq -r ".${key}.locked.repo")" + type="$(echo "${nodes1}" | jq -r ".${key}.locked.type")" + rev1="$(echo "${nodes1}" | jq -r ".${key}.locked.rev")" + rev2="$(echo "${nodes2}" | jq -r ".${key}.locked.rev")" + if [[ "${rev1}" != "${rev2}" ]]; then + if [[ "${type}" == 'github' ]]; then + echo "- https://github.com/${owner}/${repo}/compare/${rev1}...${rev2}" + fi + # TODO: support gitlab and possibly other services + fi +done