feat: Add ArgoCD diff workflow
Some checks failed
ArgoCD Diff / argocd-diff-preview (pull_request) Failing after 1m21s
Some checks failed
ArgoCD Diff / argocd-diff-preview (pull_request) Failing after 1m21s
This commit is contained in:
parent
12f4226ae8
commit
290a5ce0c9
1 changed files with 65 additions and 0 deletions
65
.forgejo/workflows/argocd-diff-preview.yaml
Normal file
65
.forgejo/workflows/argocd-diff-preview.yaml
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
---
|
||||||
|
name: ArgoCD Diff
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
workflow_call:
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
argocd-diff-preview:
|
||||||
|
runs-on: docker
|
||||||
|
env:
|
||||||
|
PR_NUMBER: ${{ forge.event.pull_request.number }}
|
||||||
|
steps:
|
||||||
|
- uses: https://github.com/actions/checkout@v4
|
||||||
|
with:
|
||||||
|
path: pull-request
|
||||||
|
|
||||||
|
- uses: https://github.com/actions/checkout@v4
|
||||||
|
with:
|
||||||
|
ref: main
|
||||||
|
path: main
|
||||||
|
|
||||||
|
- name: Generate Diff
|
||||||
|
run: |
|
||||||
|
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.1
|
||||||
|
|
||||||
|
- name: Add comment
|
||||||
|
id: comment
|
||||||
|
if: always()
|
||||||
|
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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue