Include comparison URLs in PR body

This commit is contained in:
Dawid Dziurla 2023-08-10 16:31:53 +02:00
parent fd510d25c0
commit c757b01bd9
No known key found for this signature in database
GPG Key ID: 7B6D8368172E9B0B
2 changed files with 39 additions and 1 deletions

View File

@ -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

28
compare-flake-lock.sh Executable file
View File

@ -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