Some checks failed
ArgoCD Diff / argocd-diff-preview (pull_request) Failing after 4s
71 lines
2.3 KiB
YAML
71 lines
2.3 KiB
YAML
---
|
|
name: ArgoCD Diff
|
|
on:
|
|
workflow_dispatch:
|
|
workflow_call:
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
|
|
jobs:
|
|
argocd-diff-preview:
|
|
runs-on: docker
|
|
container: docker:27
|
|
services:
|
|
docker:
|
|
image: docker:27-dind
|
|
options: --privileged
|
|
env:
|
|
DOCKER_TLS_CERTDIR: ""
|
|
env:
|
|
PR_NUMBER: ${{ forge.event.pull_request.number }}
|
|
GITHUB_TOKEN: ${{ secrets.FORGEJO_TOKEN }}
|
|
DOCKER_HOST: tcp://docker:2375
|
|
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: 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 }} \
|
|
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
|