1
1
name : APPCD Diff check
2
2
on :
3
+ push :
4
+ branches :
5
+ - feature/sks-test
3
6
pull_request :
4
7
branches :
5
8
- main
6
9
jobs :
7
10
compare-artifacts :
11
+ permissions :
12
+ contents : write
13
+ pull-requests : write
8
14
runs-on : ubuntu-latest
9
15
steps :
10
16
- name : Checkout Main Branch
11
- uses : actions/checkout@v2
17
+ uses : actions/checkout@v4
12
18
with :
13
19
ref : main
14
20
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
18
22
- name : Generate IaC from Main Branch
23
+ env :
24
+ APPCD_TOKEN : ${{ secrets.APPCD_TOKEN }}
25
+ APPCD_URL : ${{ secrets.APPCD_URL }}
19
26
run : |
20
- mkdir -p artifact/main/
27
+ mkdir -p artifact/main/ ./artifact/tmp
21
28
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
25
45
- name : Checkout PR Branch
26
- uses : actions/checkout@v2
46
+ uses : actions/checkout@v4
27
47
with :
28
48
ref : ${{ github.head_ref }}
29
49
path : pr_branch
50
+ fetch-depth : 1
30
51
- name : Extract branch name
31
52
id : extract_branch
32
53
run : echo "branch=$(basename ${{ github.head_ref}})" >> $GITHUB_OUTPUT
33
54
- name : echo branch name
34
55
run : echo ${{ steps.extract_branch.outputs.branch }}
35
56
- name : Generate IaC from PR branch
57
+ env :
58
+ APPCD_TOKEN : ${{ secrets.APPCD_TOKEN }}
59
+ APPCD_URL : ${{ secrets.APPCD_URL }}
36
60
run : |
37
- mkdir -p artifact/${{ steps.extract_branch.outputs.branch }}/
61
+ mkdir -p artifact/${{ steps.extract_branch.outputs.branch }}/ ./artifact/tmp
38
62
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
42
79
- name : Generate diff between Main and PR branch
43
80
run : |
44
81
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/
46
83
cd pr_branch
47
84
git config --local user.email "action@github.com"
48
85
git config --local user.name "GitHub Action"
49
86
git add deployment_files
50
87
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
53
89
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/
55
92
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
57
95
cat ../diff.txt
58
96
- name : Comment PR with IaC Changes
59
97
uses : actions/github-script@v6
@@ -62,7 +100,20 @@ jobs:
62
100
script : |
63
101
const fs = require('fs');
64
102
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`;
66
117
await github.rest.issues.createComment({
67
118
issue_number: context.issue.number,
68
119
owner: context.repo.owner,
0 commit comments