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
+ docker pull ghcr.io/appcd-dev/appcd-dist/appcd-cli:cli
28
+ mkdir -p artifact/main/ ./artifact/tmp
21
29
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
25
46
- name : Checkout PR Branch
26
- uses : actions/checkout@v2
47
+ uses : actions/checkout@v4
27
48
with :
28
49
ref : ${{ github.head_ref }}
29
50
path : pr_branch
51
+ fetch-depth : 1
30
52
- name : Extract branch name
31
53
id : extract_branch
32
54
run : echo "branch=$(basename ${{ github.head_ref}})" >> $GITHUB_OUTPUT
33
55
- name : echo branch name
34
56
run : echo ${{ steps.extract_branch.outputs.branch }}
35
57
- name : Generate IaC from PR branch
58
+ env :
59
+ APPCD_TOKEN : ${{ secrets.APPCD_TOKEN }}
60
+ APPCD_URL : ${{ secrets.APPCD_URL }}
36
61
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
38
64
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
42
81
- name : Generate diff between Main and PR branch
43
82
run : |
44
83
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/
46
85
cd pr_branch
47
86
git config --local user.email "action@github.com"
48
87
git config --local user.name "GitHub Action"
49
88
git add deployment_files
50
89
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
53
91
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/
55
94
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
57
97
cat ../diff.txt
58
98
- name : Comment PR with IaC Changes
59
99
uses : actions/github-script@v6
@@ -62,7 +102,20 @@ jobs:
62
102
script : |
63
103
const fs = require('fs');
64
104
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`;
66
119
await github.rest.issues.createComment({
67
120
issue_number: context.issue.number,
68
121
owner: context.repo.owner,
0 commit comments