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+ mkdir -p artifact/main/ ./artifact/tmp
2128 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
29+ --workdir=/app/scan \
30+ -e APPCD_TOKEN=$APPCD_TOKEN \
31+ -e APPCD_URL=$APPCD_URL \
32+ -v ./main_branch:/app/scan \
33+ -v ./artifact/tmp:/tmp \
34+ -v ./artifact/main:/artifact/main \
35+ --entrypoint=appcd \
36+ ghcr.io/appcd-dev/appcd-dist/appcd:cli \
37+ generate --log 2 --output=/artifact/main/.appcd/charts
38+ cd artifact/main/.appcd/charts
39+ unzip scan.zip && rm scan.zip && ls -latr && pwd
40+ - name : Upload logs
41+ uses : actions/upload-artifact@v2
42+ with :
43+ name : analyzer_logs_1
44+ path : artifact
2545 - name : Checkout PR Branch
26- uses : actions/checkout@v2
46+ uses : actions/checkout@v4
2747 with :
2848 ref : ${{ github.head_ref }}
2949 path : pr_branch
50+ fetch-depth : 1
3051 - name : Extract branch name
3152 id : extract_branch
3253 run : echo "branch=$(basename ${{ github.head_ref}})" >> $GITHUB_OUTPUT
3354 - name : echo branch name
3455 run : echo ${{ steps.extract_branch.outputs.branch }}
3556 - name : Generate IaC from PR branch
57+ env :
58+ APPCD_TOKEN : ${{ secrets.APPCD_TOKEN }}
59+ APPCD_URL : ${{ secrets.APPCD_URL }}
3660 run : |
37- mkdir -p artifact/${{ steps.extract_branch.outputs.branch }}/
61+ mkdir -p artifact/${{ steps.extract_branch.outputs.branch }}/ ./artifact/tmp
3862 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
63+ --workdir=/app/scan \
64+ -v ./pr_branch/:/app/scan \
65+ -v ./artifact/${{ steps.extract_branch.outputs.branch }}:/artifact/${{ steps.extract_branch.outputs.branch }} \
66+ -v ./artifact/tmp:/tmp \
67+ -e APPCD_TOKEN=$APPCD_TOKEN \
68+ -e APPCD_URL=$APPCD_URL \
69+ --entrypoint=appcd \
70+ ghcr.io/appcd-dev/appcd-dist/appcd:cli \
71+ generate --mode ci --lang Python --log 2 --iac-type Helm --output=/artifact/${{ steps.extract_branch.outputs.branch }}/.appcd/charts
72+ cd artifact/${{ steps.extract_branch.outputs.branch }}/.appcd/charts
73+ unzip scan.zip && rm scan.zip && ls -latr
74+ - name : Upload logs
75+ uses : actions/upload-artifact@v2
76+ with :
77+ name : analyzer_logs_2
78+ path : artifact
4279 - name : Generate diff between Main and PR branch
4380 run : |
4481 mkdir -p pr_branch/deployment_files
45- mv ./artifact/main/.appcd pr_branch/deployment_files/
82+ mv ./artifact/main/.appcd/charts/helm/scan_*/* pr_branch/deployment_files/
4683 cd pr_branch
4784 git config --local user.email "action@github.com"
4885 git config --local user.name "GitHub Action"
4986 git add deployment_files
5087 git commit -m "staging deployment files from main to compare them"
51- rm -rf deploment_files/*
52- rm -rf deployment_files/.appcd
88+ rm -rf deploment_files
5389 cd ..
54- mv artifact/${{ steps.extract_branch.outputs.branch }}/.appcd pr_branch/deployment_files/
90+ mkdir -p pr_branch/deployment_files/
91+ cp -R artifact/${{ steps.extract_branch.outputs.branch }}/.appcd/charts/helm/scan_*/* pr_branch/deployment_files/
5592 cd pr_branch
56- git diff --output=../diff.txt deployment_files/ | cat
93+ git add .
94+ git diff --staged --output=../diff.txt deployment_files/ | cat
5795 cat ../diff.txt
5896 - name : Comment PR with IaC Changes
5997 uses : actions/github-script@v6
@@ -62,7 +100,20 @@ jobs:
62100 script : |
63101 const fs = require('fs');
64102 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}\`\`\``;
103+ const body = `### AppCD Diff:\n\`\`\`${diff}\`\`\``;
104+ await github.rest.issues.createComment({
105+ issue_number: context.issue.number,
106+ owner: context.repo.owner,
107+ repo: context.repo.repo,
108+ body: body
109+ })
110+ - name : Trigger atlantis plan
111+ uses : actions/github-script@v6
112+ with :
113+ github-token : ${{secrets.GITHUB_TOKEN}}
114+ script : |
115+ const fs = require('fs');
116+ const body = `atlantis plan`;
66117 await github.rest.issues.createComment({
67118 issue_number: context.issue.number,
68119 owner: context.repo.owner,
0 commit comments