kubernetes/.forgejo/workflows/argocd-diff-preview.yaml

71 lines
2.2 KiB
YAML
Raw Normal View History

2026-03-23 19:57:46 +01:00
---
name: ArgoCD Diff
on:
workflow_dispatch:
workflow_call:
pull_request:
branches:
- main
jobs:
argocd-diff-preview:
runs-on: docker
2026-05-29 09:38:00 +02:00
services:
docker:
image: docker:27-dind
options: --privileged
env:
DOCKER_TLS_CERTDIR: ""
2026-03-23 19:57:46 +01:00
env:
PR_NUMBER: ${{ forge.event.pull_request.number }}
2026-03-23 20:02:02 +01:00
GITHUB_TOKEN: ${{ secrets.FORGEJO_TOKEN }}
2026-05-29 09:38:00 +02:00
DOCKER_HOST: tcp://docker:2375
2026-03-23 19:57:46 +01:00
steps:
2026-05-29 09:38:00 +02:00
- uses: https://github.com/actions/checkout@v6
2026-03-23 19:57:46 +01:00
with:
path: pull-request
2026-05-29 09:38:00 +02:00
- uses: https://github.com/actions/checkout@v6
2026-03-23 19:57:46 +01:00
with:
ref: main
path: main
- name: Generate Diff
run: |
docker run \
-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 }} \
2026-05-29 09:38:00 +02:00
dagandersen/argocd-diff-preview:v0.2.8
2026-03-23 19:57:46 +01:00
- 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