-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
107 lines (90 loc) · 4.22 KB
/
action.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
name: AxoSyslog CFG diff (PR)
description: Calculates the config differences that a PR introduces and prepares a comment about it, to be picked up by a workflow_run workflow.
runs:
using: composite
steps:
- name: Checkout axosyslog-cfg-helper source
uses: actions/checkout@v4
with:
repository: alltilla/axosyslog-cfg-helper
path: axosyslog-cfg-helper
- name: Setup axosyslog-cfg-helper
shell: bash
working-directory: axosyslog-cfg-helper
run: |
curl -sSL https://install.python-poetry.org | python3 -
make venv
make bison BISON_INSTALL_PATH=${GITHUB_WORKSPACE}/bin
echo "${GITHUB_WORKSPACE}/bin" >> $GITHUB_PATH
- name: Checkout AxoSyslog
uses: actions/checkout@v4
with:
repository: ${{ github.repository }}
path: axosyslog
- name: Query PR info and add PR head remote
shell: bash
working-directory: axosyslog
run: |
git fetch origin
PR_INFO=$(gh -R ${{ github.repository }} pr view ${{ github.event.number }} --json "baseRefName,headRefName,headRepository,headRepositoryOwner")
HEAD_REPOSITORY_OWNER=$(echo $PR_INFO | jq -r .headRepositoryOwner.login)
HEAD_REPOSITORY=$(echo $PR_INFO | jq -r .headRepository.name)
HEAD_REF_NAME=$(echo $PR_INFO | jq -r .headRefName)
BASE_REF_NAME=$(echo $PR_INFO | jq -r .baseRefName)
git remote add ${HEAD_REPOSITORY_OWNER} https://github.com/${HEAD_REPOSITORY_OWNER}/${HEAD_REPOSITORY}.git
git fetch ${HEAD_REPOSITORY_OWNER}
COMMON_ANCESTOR_REF=$(git merge-base origin/${BASE_REF_NAME} ${HEAD_REPOSITORY_OWNER}/${HEAD_REF_NAME})
echo "HEAD_REPOSITORY_OWNER=${HEAD_REPOSITORY_OWNER}" >> ${GITHUB_ENV}
echo "HEAD_REPOSITORY=${HEAD_REPOSITORY}" >> ${GITHUB_ENV}
echo "HEAD_REF_NAME=${HEAD_REF_NAME}" >> ${GITHUB_ENV}
echo "BASE_REF_NAME=${BASE_REF_NAME}" >> ${GITHUB_ENV}
echo "COMMON_ANCESTOR_REF=${COMMON_ANCESTOR_REF}" >> ${GITHUB_ENV}
- name: Checkout PR base branch
shell: bash
working-directory: axosyslog
run: |
git checkout ${COMMON_ANCESTOR_REF}
- name: Generate base CFG database
shell: bash
working-directory: axosyslog-cfg-helper
run: |
make clean
make db AXOSYSLOG_SOURCE_DIR=${GITHUB_WORKSPACE}/axosyslog DATABASE_FILE=${GITHUB_WORKSPACE}/base.db
- name: Checkout PR head branch
shell: bash
working-directory: axosyslog
run: |
git checkout ${HEAD_REPOSITORY_OWNER}/${HEAD_REF_NAME}
- name: Generate head CFG database
shell: bash
working-directory: axosyslog-cfg-helper
run: |
make clean
make db AXOSYSLOG_SOURCE_DIR=${GITHUB_WORKSPACE}/axosyslog DATABASE_FILE=${GITHUB_WORKSPACE}/head.db
- name: Generate CFG diff
shell: bash
working-directory: axosyslog-cfg-helper
run: |
poetry run python ./axosyslog_cfg_helper/generate_diff.py -o ${GITHUB_WORKSPACE}/base.db -n ${GITHUB_WORKSPACE}/head.db > ${GITHUB_WORKSPACE}/diff
- name: Generate comment of CFG differences
shell: bash
working-directory: axosyslog
run: |
if [[ $(wc -l ${GITHUB_WORKSPACE}/diff | cut -d " " -f1) -gt 1 ]]; then
awk '{printf "%s\\n", $0}' ${GITHUB_WORKSPACE}/diff > ${GITHUB_WORKSPACE}/diff_escaped
COMMENT="#### This Pull Request introduces config grammar changes\r\n"
COMMENT="${COMMENT}[${{ github.repository_owner }}/${COMMON_ANCESTOR_REF}](https://github.com/${{ github.repository }}/tree/${COMMON_ANCESTOR_REF}) -> [${HEAD_REPOSITORY_OWNER}/${HEAD_REF_NAME}](https://github.com/${HEAD_REPOSITORY_OWNER}/${HEAD_REPOSITORY}/tree/${HEAD_REF_NAME})\r\n"
COMMENT="${COMMENT}<details>\r\n\r\n"
COMMENT="${COMMENT}\`\`\`diff\r\n"
COMMENT="${COMMENT}$(cat ${GITHUB_WORKSPACE}/diff_escaped)\n"
COMMENT="${COMMENT}\`\`\`\r\n"
COMMENT="${COMMENT}</details>"
jq -n --arg body "$(echo -e "${COMMENT}")" '{body:$body}' > ${GITHUB_WORKSPACE}/comment
else
touch ${GITHUB_WORKSPACE}/comment
fi
- name: Upload comment as artifact
uses: actions/upload-artifact@v3
with:
name: comment
path: comment