-
Notifications
You must be signed in to change notification settings - Fork 43
177 lines (158 loc) · 6.62 KB
/
check-pr.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# 为了试验,此处作为单独的 Workflow,在实际工作中可 Install -> Lint、Test -> Preview 串行检验
name: Check PR
# 执行 CI 的时机: 当 git push 到 main分支时
on:
pull_request:
branches: main
permissions:
pull-requests: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check if commit is from CI
run: |
if [[ "${{ github.event.head_commit.committer.username }}" == "github-actions[bot]" ]]; then
echo "Commit is from CI, skipping the build..."
exit 78
else
echo "Commit is not from CI, continuing with the build..."
fi
- name: see vars
run: |
echo '${{github.event.pull_request.head.ref}}'
echo '${{github.event.pull_request.head.sha}}'
echo '${{github.event.pull_request.head.repo.branches_url}}'
echo '${{github.event.pull_request.head.repo.full_name}}'
echo '${{github.event.pull_request.base.ref}}'
echo '${{github.event.pull_request.base.sha}}'
echo '${{github.event.pull_request.base.repo.branches_url}}'
echo '${{github.event.pull_request.base.repo.full_name}}'
echo '${{github.head_ref}}'
echo '${{github.ref}}'
echo '${{github.ref_name}}'
echo '${{github.repository}}'
echo '${{ github.event.pull_request.number }}'
echo '${{ github.run_id }}'
echo '${{github.event.pull_request.user.name}}'
echo '${{github.event.pull_request.maintainer_can_modify}}'
echo '${{github.event.pull_request.user.id}}'
echo '${{github.event.sender.id}}'
echo '${{github.event.repository.fork}}'
echo '${{github.event.repository.name}}'
echo '${{github.event.repository.full_name}}'
echo '${{github.actor}}'
echo '${{github.triggering_actor}}'
echo '${{github.event.pull_request.user.name}}'
- name: Checkout
uses: actions/checkout/@v3
with:
fetch-depth: 1
- name: Git Identity
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/$GITHUB_REPOSITORY
git fetch --unshallow
env:
GITHUB_TOKEN: ${{ github.token}}
- name: see git1
run: |
git branch --show-current
- name: see git2
run: |
git diff --name-only origin/main...HEAD
- name: Setup Nodejs
uses: actions/setup-node@v3
with:
cache: 'npm'
node-version: 16
- name: Install Dep
run: |
npm install
- name: Detect Pull Request Change
run: |
git config --global core.quotepath false
git config --global gui.encoding utf-8
git config --global i18n.commit.encoding utf-8
git config --global i18n.logoutputencoding utf-8
export LESSCHARSET=utf-8
npm run detectPR
{
echo "DIFF_STATE<<EOF"
echo "$(cat diff_stat.json)"
echo "EOF"
} >> "$GITHUB_ENV"
- name: Set up JDK 8
if: ${{fromJson(env.DIFF_STATE).needJAVA}}
uses: actions/setup-java@v4
with:
java-version: '8'
distribution: 'temurin'
- name: Install JDK Dependency
if: ${{fromJson(env.DIFF_STATE).needJAVA}}
run: |
mvn install:install-file -Dfile="demo_bjz_JiazhenBao/jar/nasl-metadata-maven-plugin-1.3.0/nasl-metadata-maven-plugin-1.3.0.jar" -DpomFile="demo_bjz_JiazhenBao/jar/nasl-metadata-maven-plugin-1.3.0/pom.xml"
mvn install:install-file -Dfile="demo_bjz_JiazhenBao/jar/nasl-metadata-maven-plugin-1.4.1/nasl-metadata-maven-plugin-1.4.1.jar" -DpomFile="demo_bjz_JiazhenBao/jar/nasl-metadata-maven-plugin-1.4.1/pom.xml"
mvn install:install-file -Dfile="demo_bjz_JiazhenBao/jar/nasl-metadata-maven-plugin-1.4.0/nasl-metadata-maven-plugin-1.4.0.jar" -DpomFile="demo_bjz_JiazhenBao/jar/nasl-metadata-maven-plugin-1.4.0/pom.xml"
mvn install:install-file -DgroupId=com.netease.lowcode -DartifactId=nasl-metadata-collector -Dversion=0.8.0 -Dpackaging=jar -Dfile="demo_bjz_JiazhenBao/jar/nasl-metadata-collector-0.8.0.jar"
- name: Install LCAP
run: |
npm install -g [email protected]
lcap config set platform https://defaulttenant.lcap.hadri.163yun.com
lcap config set username admin
lcap config set password Admin@123456
- name: Check Pull Request
run: |
npm run checkPR
{
echo 'CHECK_RESULT<<EOF'
echo $(cat pr_result.json)
echo EOF
} >> "$GITHUB_ENV"
env:
GITHUB_TOKEN: ${{ github.token}}
PULL_REQUEST_ID: ${{ github.event.pull_request.number }}
HEAD_BRANCH_NAME: ${{github.head_ref}}
HEAD_REPOSITORY: ${{github.event.pull_request.head.repo.full_name}}
BASE_REPOSITORY: ${{github.event.pull_request.base.repo.full_name}}
GITHUB_REPOSITORY: ${{github.repository}}
ACTION_ID: ${{github.run_id}}
PR_EVENT_ACTION: ${{github.event.action}}
NOTIFY_CONFIG_JSON: ${{secrets.NOTIFY_CONFIG_JSON}}
- name: Upload PR Result Error
if: ${{fromJson(env.CHECK_RESULT).hasError}}
uses: actions/upload-artifact@v4
with:
name: pr_result
path: pr_result.json
- name: Exit If Error
if: ${{fromJson(env.CHECK_RESULT).hasError}}
run: |
exit 1
- name: Upload Assets
if: ${{fromJson(env.DIFF_STATE).packages[0]}}
uses: actions/upload-artifact@v4
id: upload_assets
with:
name: dist
path: dist/
- name: Append Assets Download url
if: ${{fromJson(env.DIFF_STATE).packages[0]}}
run: |
npm run successPR
env:
ARTIFACT_ID: ${{steps.upload_assets.outputs.artifact-id}}
GITHUB_TOKEN: ${{ github.token}}
PULL_REQUEST_ID: ${{ github.event.pull_request.number }}
HEAD_BRANCH_NAME: ${{github.head_ref}}
HEAD_REPOSITORY: ${{github.event.pull_request.head.repo.full_name}}
BASE_REPOSITORY: ${{github.event.pull_request.base.repo.full_name}}
GITHUB_REPOSITORY: ${{github.repository}}
ACTION_ID: ${{github.run_id}}
- name: Upload PR Result Error
if: ${{fromJson(env.DIFF_STATE).packages[0]}}
uses: actions/upload-artifact@v4
with:
name: pr_result
path: pr_result.json