11name : APPCD Diff check
22on :
3+ push :
4+ branches :
5+ - feature/sks-test
36 pull_request :
47 branches :
58 - main
69jobs :
710 compare-artifacts :
11+ permissions :
12+ contents : write
13+ pull-requests : write
814 runs-on : ubuntu-latest
915 steps :
1016 - name : Checkout Main Branch
11- uses : actions/checkout@v2
17+ uses : actions/checkout@v4
1218 with :
1319 ref : main
1420 path : main_branch
15- - name : Login to docker
16- run : echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin
17-
21+ fetch-depth : 1
1822 - name : Generate IaC from Main Branch
23+ env :
24+ APPCD_TOKEN : ${{ secrets.APPCD_TOKEN }}
25+ APPCD_URL : ${{ secrets.APPCD_URL }}
1926 run : |
20- mkdir -p artifact/main/
27+ docker pull ghcr.io/appcd-dev/appcd-dist/appcd-cli:cli
28+ mkdir -p artifact/main/ ./artifact/tmp
2129 docker run --rm \
22- --workdir=/code \
23- -v ./main_branch:/code -v ./artifact/main:/artifact/main ghcr.io/appcd-dev/appcd-dist/appcd@sha256:a38ade31e60f3f7f76b1135a388db158eed3c90816d5b5c09e33dd806efb67d5 \
24- generate --mode ci --output=/artifact/main/.appcd/charts
30+ --workdir=/app/scan \
31+ -e APPCD_TOKEN=$APPCD_TOKEN \
32+ -e APPCD_URL=$APPCD_URL \
33+ -v ./main_branch:/app/scan \
34+ -v ./artifact/tmp:/tmp \
35+ -v ./artifact/main:/artifact/main \
36+ --entrypoint=appcd \
37+ ghcr.io/appcd-dev/appcd-dist/appcd-cli:cli \
38+ generate --log 2 --output=/artifact/main/.appcd/charts
39+ cd artifact/main/.appcd/charts
40+ unzip scan.zip && rm scan.zip && ls -latr && pwd
41+ - name : Upload logs
42+ uses : actions/upload-artifact@v2
43+ with :
44+ name : analyzer_logs_1
45+ path : artifact
2546 - name : Checkout PR Branch
26- uses : actions/checkout@v2
47+ uses : actions/checkout@v4
2748 with :
2849 ref : ${{ github.head_ref }}
2950 path : pr_branch
51+ fetch-depth : 1
3052 - name : Extract branch name
3153 id : extract_branch
3254 run : echo "branch=$(basename ${{ github.head_ref}})" >> $GITHUB_OUTPUT
3355 - name : echo branch name
3456 run : echo ${{ steps.extract_branch.outputs.branch }}
3557 - name : Generate IaC from PR branch
58+ env :
59+ APPCD_TOKEN : ${{ secrets.APPCD_TOKEN }}
60+ APPCD_URL : ${{ secrets.APPCD_URL }}
3661 run : |
37- mkdir -p artifact/${{ steps.extract_branch.outputs.branch }}/
62+ docker pull ghcr.io/appcd-dev/appcd-dist/appcd-cli:cli
63+ mkdir -p artifact/${{ steps.extract_branch.outputs.branch }}/ ./artifact/tmp
3864 docker run --rm \
39- --workdir=/code \
40- -v ./pr_branch/:/code -v ./artifact/${{ steps.extract_branch.outputs.branch }}:/artifact/${{ steps.extract_branch.outputs.branch }} ghcr.io/appcd-dev/appcd-dist/appcd@sha256:a38ade31e60f3f7f76b1135a388db158eed3c90816d5b5c09e33dd806efb67d5 \
41- generate --mode ci --output=/artifact/${{ steps.extract_branch.outputs.branch }}/.appcd/charts
65+ --workdir=/app/scan \
66+ -v ./pr_branch/:/app/scan \
67+ -v ./artifact/${{ steps.extract_branch.outputs.branch }}:/artifact/${{ steps.extract_branch.outputs.branch }} \
68+ -v ./artifact/tmp:/tmp \
69+ -e APPCD_TOKEN=$APPCD_TOKEN \
70+ -e APPCD_URL=$APPCD_URL \
71+ --entrypoint=appcd \
72+ ghcr.io/appcd-dev/appcd-dist/appcd-cli:cli \
73+ generate --mode ci --log 2 --output=/artifact/${{ steps.extract_branch.outputs.branch }}/.appcd/charts
74+ cd artifact/${{ steps.extract_branch.outputs.branch }}/.appcd/charts
75+ unzip scan.zip && rm scan.zip && ls -latr
76+ - name : Upload logs
77+ uses : actions/upload-artifact@v2
78+ with :
79+ name : analyzer_logs_2
80+ path : artifact
4281 - name : Generate diff between Main and PR branch
4382 run : |
4483 mkdir -p pr_branch/deployment_files
45- mv ./artifact/main/.appcd pr_branch/deployment_files/
84+ mv ./artifact/main/.appcd/charts/helm/scan_*/* pr_branch/deployment_files/
4685 cd pr_branch
4786 git config --local user.email "action@github.com"
4887 git config --local user.name "GitHub Action"
4988 git add deployment_files
5089 git commit -m "staging deployment files from main to compare them"
51- rm -rf deploment_files/*
52- rm -rf deployment_files/.appcd
90+ rm -rf deploment_files
5391 cd ..
54- mv artifact/${{ steps.extract_branch.outputs.branch }}/.appcd pr_branch/deployment_files/
92+ mkdir -p pr_branch/deployment_files/
93+ cp -R artifact/${{ steps.extract_branch.outputs.branch }}/.appcd/charts/helm/scan_*/* pr_branch/deployment_files/
5594 cd pr_branch
56- git diff --output=../diff.txt deployment_files/ | cat
95+ git add .
96+ git diff --staged --output=../diff.txt deployment_files/ | cat
5797 cat ../diff.txt
5898 - name : Comment PR with IaC Changes
5999 uses : actions/github-script@v6
@@ -62,7 +102,20 @@ jobs:
62102 script : |
63103 const fs = require('fs');
64104 const diff = fs.readFileSync('diff.txt', 'utf-8');
65- const body = `### AppCD AppStack: http://demo.dev.appcd.io/appstacks/DogeAPI/\n ### IaC Diff:\n\`\`\`${diff}\`\`\``;
105+ const body = `### AppCD Diff:\n\`\`\`${diff}\`\`\``;
106+ await github.rest.issues.createComment({
107+ issue_number: context.issue.number,
108+ owner: context.repo.owner,
109+ repo: context.repo.repo,
110+ body: body
111+ })
112+ - name : Trigger atlantis plan
113+ uses : actions/github-script@v6
114+ with :
115+ github-token : ${{secrets.GITHUB_TOKEN}}
116+ script : |
117+ const fs = require('fs');
118+ const body = `atlantis plan`;
66119 await github.rest.issues.createComment({
67120 issue_number: context.issue.number,
68121 owner: context.repo.owner,
0 commit comments