Skip to content

Commit

Permalink
test: pr
Browse files Browse the repository at this point in the history
  • Loading branch information
cterence committed Jan 19, 2025
1 parent cfcce21 commit 96a6133
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 15 deletions.
70 changes: 57 additions & 13 deletions .github/workflows/pr-argo-diff.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,85 @@ on:
- "k8s-apps/**"

jobs:
argocd-diff:
argocd_diff:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up environment
run: |
# Install ArgoCD CLI
curl -sSL -o /usr/local/bin/argocd https://github.com/argoproj/argo-cd/releases/latest/download/argocd-linux-amd64
chmod +x /usr/local/bin/argocd
- name: Get updated charts
id: updated-charts
- name: Get updated apps
id: updated_apps
run: |
UPDATED_APPS=$(git diff --name-only origin/main...HEAD | grep '^k8s-apps/' | awk -F'/' '{print $2}' | sort -u)
echo "Updated charts: $UPDATED_APPS"
echo "::set-output name=apps::$UPDATED_APPS"
git fetch origin
# Extract unique app names from the modified paths under k8s-apps
MODIFIED_APPS=$(git diff --name-only origin/main...HEAD | grep '^k8s-apps/' | awk -F'/' '{print $2}' | sort -u | xargs)
if [ -z "$MODIFIED_APPS" ]; then
echo "No changes detected"
echo "apps=" >> $GITHUB_OUTPUT
else
echo "Modified apps: $MODIFIED_APPS"
echo "apps=$MODIFIED_APPS" >> $GITHUB_OUTPUT
fi
- name: Login to ArgoCD
if: steps.updated-charts.outputs.apps != ''
if: steps.updated_apps.outputs.apps != ''
run: |
argocd login --grpc-web --username admin --password $ARGOCD_ADMIN_PASSWORD argocd.terence.cloud
argocd login argocd.terence.cloud --grpc-web --username admin --password $ARGOCD_ADMIN_PASSWORD
env:
ARGOCD_ADMIN_PASSWORD: ${{ secrets.ARGOCD_ADMIN_PASSWORD }}

- name: ArgoCD Diff for updated apps
if: steps.updated-charts.outputs.apps != ''
id: argocd_diff
if: steps.updated_apps.outputs.apps != ''
run: |
for APP in ${{ steps.updated-charts.outputs.apps }}; do
DIFF_OUTPUT=""
for APP in ${{ steps.updated_apps.outputs.apps }}; do
echo "Processing app: $APP"
cd "k8s-apps/$APP"
argocd app diff "$APP" \
helm dependency update
DIFF=$(argocd app diff "$APP" \
--grpc-web \
--local-repo-root $(git rev-parse --show-toplevel) \
--local $PWD \
--loglevel warn
--loglevel warn \
--exit-code=false)
DIFF_OUTPUT="${DIFF_OUTPUT}\n\n### Diff for $APP:\n\`\`\`diff$DIFF\`\`\`"
cd -
done
if [ -n "$DIFF_OUTPUT" ]; then
{
echo 'diff_output<<EOF'
echo -e "$DIFF_OUTPUT"
echo 'EOF'
} >> "$GITHUB_OUTPUT"
else
echo "diff_output=No differences found." >> $GITHUB_OUTPUT
fi
- name: Publish PR Comment
if: steps.updated_apps.outputs.apps != ''
uses: actions/github-script@v7
env:
ARGOCD_ADMIN_PASSWORD: ${{ secrets.ARGOCD_ADMIN_PASSWORD }}
DIFF_OUTPUT: ${{ steps.argocd_diff.outputs.diff_output }}
with:
script: |
const diffOutput = process.env.DIFF_OUTPUT;
if (diffOutput) {
const commentBody = `### ArgoCD Diff Results\n${diffOutput}`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody,
});
}
2 changes: 1 addition & 1 deletion k8s-apps/argocd/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ argo-cd:
rbac:
policy.default: role:readonly
policy.csv: |
g, terence.chateigne@posteo.net, role:admin
g, terence.chateigne@posteo.nets, role:admin
scopes: "[groups, email]"

secret:
Expand Down
2 changes: 1 addition & 1 deletion k8s-apps/crowdsec/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ crowdsec:
whitelist:
reason: "My IP ranges"
ip:
- "109.0.228.97"
- "109.0.228.97s"
- "195.135.98.90"
- "46.193.107.14"
- "34.68.56.138"
Expand Down

0 comments on commit 96a6133

Please sign in to comment.