-
Notifications
You must be signed in to change notification settings - Fork 62
118 lines (114 loc) · 4.5 KB
/
lift.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
name: Lift
on: [pull_request, workflow_dispatch]
jobs:
analyze_src:
name: Source Branch Analysis
runs-on: ubuntu-latest
container:
image: musedev/analyst
credentials:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
# - name: Setup build environment
# env:
# nexus_token: ${{ secrets.MY_NEXUS_TOKEN }}
# run: |
# ... put shell script to create .m2/settings.xml
# .... put shell script to install build dependencies if needed
- name: Produce src artifact
run: |
if [[ -z "$GITHUB_BASE_REF" ]] ; then
echo "This is not a pull request."
echo "Look for any result in the 'Destination Branch Analysis' job"
else
export SRC_SHA=$(cat $GITHUB_EVENT_PATH | jq -r -j .pull_request.head.sha)
export DST_SHA=$(cat $GITHUB_EVENT_PATH | jq -r -j .pull_request.base.sha)
analyst -t "$GITHUB_WORKSPACE" -C $SRC_SHA > lift-src-results.json
cat lift-src-results.json | jq . | sed 's/\\n/\n/g'
echo -n "$SRC_SHA" > lift-commit
echo -n "Source commit: " ; cat lift-commit ; echo ""
echo "SRC_SHA -> DST_SHA: $SRC_SHA -> $DST_SHA"
git -C $GITHUB_WORKSPACE diff ${DST_SHA}..${SRC_SHA} > lift.git.diff
fi
- name: Upload src artifact
uses: actions/upload-artifact@v2
with:
name: lift_src_results
path: lift*
analyze_dst:
name: Destination Branch Analysis
runs-on: ubuntu-latest
container:
image: musedev/analyst
credentials:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
# - name: Setup build environment
# env:
# nexus_token: ${{ secrets.MY_NEXUS_TOKEN }}
# run: |
# ... put shell script to create .m2/settings.xml
# .... put shell script to install build dependencies if needed
- name: Produce dst artifact
run: |
if [ -z "$GITHUB_BASE_REF" ] ; then
export DST_SHA="$GITHUB_SHA"
else
export DST_SHA=$(cat $GITHUB_EVENT_PATH | jq -r -j .pull_request.base.sha)
fi
analyst -t "$GITHUB_WORKSPACE" -C $DST_SHA > lift-dst-results.json
cat lift-dst-results.json | jq . | sed 's/\\n/\n/g'
- name: Upload dst artifact
uses: actions/upload-artifact@v2
with:
name: lift_dst_results
path: lift-dst-results.json
unify_results:
name: Distill Result
needs: [analyze_src, analyze_dst]
runs-on: ubuntu-latest
container:
image: musedev/github-comment-composer
credentials:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
steps:
- name: Get Dst
uses: actions/download-artifact@v2
with:
name: lift_dst_results
- name: Get Src
uses: actions/download-artifact@v2
with:
name: lift_src_results
- name: Combine
run: |
github-comment-composer lift.git.diff lift-src-results.json lift-dst-results.json > github-comments.json
- name: Post comments
uses: actions/github-script@v4
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const { promises: fs } = require('fs')
const commit = await fs.readFile('lift-commit', 'utf8')
console.log('Commit for comment: ' + commit)
const comments = await fs.readFile('github-comments.json', 'utf8')
console.log('Comments string (raw): ' + comments)
for(const comment of JSON.parse(comments)) {
console.log('Comment: ' + comment)
github.pulls.createReviewComment({
...comment,
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
commit_id: commit,
});
}