kubernetes/.forgejo/workflows/argocd-diff-preview.yaml
2026-05-29 11:52:59 +02:00

76 lines
2.5 KiB
YAML

---
name: ArgoCD Diff
on:
workflow_dispatch:
workflow_call:
pull_request:
branches:
- main
jobs:
argocd-diff-preview:
runs-on: docker
container:
options: --volume /var/run/docker.sock:/var/run/docker.sock
env:
PR_NUMBER: ${{ forge.event.pull_request.number }}
GITHUB_TOKEN: ${{ secrets.FORGEJO_TOKEN }}
steps:
- uses: https://github.com/actions/checkout@v6
with:
path: pull-request
- uses: https://github.com/actions/checkout@v6
with:
ref: main
path: main
- name: Install Docker CLI
run: |
if command -v apt-get &>/dev/null; then
apt-get update -qq && apt-get install -y --no-install-recommends docker.io
elif command -v apk &>/dev/null; then
apk add --no-cache docker-cli
fi
- name: Generate Diff
run: |
mkdir -p $(pwd)/output
docker run \
--network=host \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $(pwd)/main:/base-branch \
-v $(pwd)/pull-request:/target-branch \
-v $(pwd)/output:/output \
-e TARGET_BRANCH=refs/pull/$PR_NUMBER/merge \
-e REPO=${{ forge.repository }} \
dagandersen/argocd-diff-preview:v0.2.8
- name: Add comment
id: comment
run: |
DIFF_BODY=$(cat output/diff.md)
payload="{\"body\": $DIFF_BODY}"
existing_comment=$(curl -s \
-H "Authorization: token ${{ secrets.FORGEJO_TOKEN }}" \
"${{ forge.api_url }}/repos/${{ forge.repository }}/issues/$PR_NUMBER/comments")
comment_id=$(echo "$existing_comment" | jq -r \
'.[] | select(.body | test("${{ forge.workflow }}")) | .id' | head -n 1)
if [ -n "${comment_id}" ] && [ "${comment_id}" != "null" ]; then
echo "Found comment with id ${comment_id}, updating..." && \
curl -s -X PATCH \
-H "Authorization: token ${{ secrets.FORGEJO_TOKEN }}" \
-H "Content-Type: application/json" \
"${{ forge.api_url }}/repos/${{ forge.repository }}/issues/comments/${comment_id}" \
-d "$payload"
else
echo "Creating new comment..." && \
curl -s -X POST \
-H "Authorization: token ${{ secrets.FORGEJO_TOKEN }}" \
-H "Content-Type: application/json" \
"${{ forge.api_url }}/repos/${{ forge.repository }}/issues/$PR_NUMBER/comments" \
-d "$payload"
fi