generated from CatChen/typescript-github-action-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
216 lines (188 loc) · 7.1 KB
/
test.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
name: Test
on:
push:
branches: [main]
pull_request:
branches: [main, '[0-9]+-[0-9]+-*']
workflow_dispatch:
workflow_run:
workflows: ['Dependabot']
branches-ignore: ['workflows/tests/*']
types:
- completed
workflow_call:
jobs:
test-with-github-actions-token:
name: Test with GitHub Actions Token
if: ${{ !startsWith(github.head_ref, 'workflows/tests/') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
if: ${{ github.event_name != 'workflow_run' }}
- uses: actions/checkout@v4
if: ${{ github.event_name == 'workflow_run' }}
with:
ref: ${{ github.event.workflow_run.head_branch }}
- name: Test with GitHub Actions token
id: test
uses: ./
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Verify name and email
env:
TEST_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
GIT_USER_NAME=$(git config --get user.name)
if [[ "$GIT_USER_NAME" != "GitHub Actions" ]]
then
echo "::error::Expected git config user.name to be 'GitHub Actions' but got '$GIT_USER_NAME'"
exit 1
fi
GIT_USER_EMAIL=$(git config --get user.email)
if [[ "$GIT_USER_EMAIL" != "41898282+github-actions[bot]@users.noreply.github.com" ]]
then
echo "::error::Expected git config user.email to be '41898282+github-actions[bot]@users.noreply.github.com' but got '$GIT_USER_EMAIL'"
exit 1
fi
- name: Verify remote access
run: |
git ls-remote origin
gh repo view
test-with-user-app-installation-token:
name: Test with User App Installation Token
if: ${{ !startsWith(github.head_ref, 'workflows/tests/') }}
runs-on: ubuntu-latest
steps:
- uses: actions/create-github-app-token@v1
id: get-github-app-token
with:
app-id: ${{ secrets.CHECK_GIT_STATUS_BOT_APP_ID }}
private-key: ${{ secrets.CHECK_GIT_STATUS_BOT_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
- uses: actions/checkout@v4
if: ${{ github.event_name != 'workflow_run' }}
with:
token: ${{ steps.get-github-app-token.outputs.token }}
- uses: actions/checkout@v4
if: ${{ github.event_name == 'workflow_run' }}
with:
ref: ${{ github.event.workflow_run.head_branch }}
token: ${{ steps.get-github-app-token.outputs.token }}
- name: Test
id: test
uses: ./
with:
github-token: ${{ steps.get-github-app-token.outputs.token }}
- name: Verify name and email
env:
TEST_TOKEN: ${{ steps.get-github-app-token.outputs.token }}
run: |
GIT_USER_NAME=$(git config --get user.name)
if [[ "$GIT_USER_NAME" != "Check Git Status Bot" ]]
then
echo "::error::Expected git config user.name to be 'Check Git Status Bot' but got '$GIT_USER_NAME'"
exit 1
fi
GIT_USER_EMAIL=$(git config --get user.email)
if [[ "$GIT_USER_EMAIL" != "172423145+check-git-status-bot[bot]@users.noreply.github.com" ]]
then
echo "::error::Expected git config user.email to be '172423145+check-git-status-bot[bot]@users.noreply.github.com' but got '$GIT_USER_EMAIL'"
exit 1
fi
- name: Verify remote access
run: |
git ls-remote origin
gh repo view
test-with-repo-app-installation-token:
name: Test with Repo App Installation Token
if: ${{ !startsWith(github.head_ref, 'workflows/tests/') }}
runs-on: ubuntu-latest
steps:
- uses: actions/create-github-app-token@v1
id: get-github-app-token
with:
app-id: ${{ secrets.CHECK_GIT_STATUS_BOT_APP_ID }}
private-key: ${{ secrets.CHECK_GIT_STATUS_BOT_APP_PRIVATE_KEY }}
- uses: actions/checkout@v4
if: ${{ github.event_name != 'workflow_run' }}
with:
token: ${{ steps.get-github-app-token.outputs.token }}
- uses: actions/checkout@v4
if: ${{ github.event_name == 'workflow_run' }}
with:
ref: ${{ github.event.workflow_run.head_branch }}
token: ${{ steps.get-github-app-token.outputs.token }}
- name: Test
id: test
uses: ./
with:
github-token: ${{ steps.get-github-app-token.outputs.token }}
- name: Verify name and email
env:
TEST_TOKEN: ${{ steps.get-github-app-token.outputs.token }}
run: |
GIT_USER_NAME=$(git config --get user.name)
if [[ "$GIT_USER_NAME" != "Check Git Status Bot" ]]
then
echo "::error::Expected git config user.name to be 'Check Git Status Bot' but got '$GIT_USER_NAME'"
exit 1
fi
GIT_USER_EMAIL=$(git config --get user.email)
if [[ "$GIT_USER_EMAIL" != "172423145+check-git-status-bot[bot]@users.noreply.github.com" ]]
then
echo "::error::Expected git config user.email to be '172423145+check-git-status-bot[bot]@users.noreply.github.com' but got '$GIT_USER_EMAIL'"
exit 1
fi
- name: Verify remote access
run: |
git ls-remote origin
gh repo view
test-with-classic-personal-access-token:
name: Test with Classic Personal Access Token
if: ${{ !startsWith(github.head_ref, 'workflows/tests/') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
if: ${{ github.event_name != 'workflow_run' }}
- uses: actions/checkout@v4
if: ${{ github.event_name == 'workflow_run' }}
with:
ref: ${{ github.event.workflow_run.head_branch }}
- name: Test
id: test
uses: ./
with:
github-token: ${{ secrets.CLASSIC_PERSONAL_ACCESS_TOKEN }}
- name: Verify name and email
run: |
GIT_USER_NAME=$(git config --get user.name)
if [[ "$GIT_USER_NAME" != "Cat Chen" ]]
then
echo "::error::Expected git config user.name to be 'Cat Chen' but got '$GIT_USER_NAME'"
exit 1
fi
GIT_USER_EMAIL=$(git config --get user.email)
if [[ "$GIT_USER_EMAIL" != "catchen@catchen.me" ]]
then
echo "::error::Expected git config user.email to be 'catchen@catchen.me' but got '$GIT_USER_EMAIL'"
exit 1
fi
- name: Verify remote URL
env:
TEST_TOKEN: ${{ secrets.CLASSIC_PERSONAL_ACCESS_TOKEN }}
run: |
GIT_REMOTE_URL=$(git remote get-url origin)
if [[ ! "$GIT_REMOTE_URL" =~ ^'https://CatChen' ]]
then
echo "::error::Expected git remote url to have login and token but got '$GIT_REMOTE_URL'"
exit 1
fi
if [[ ! "$GIT_REMOTE_URL" =~ ^'https://CatChen:'"$TEST_TOKEN" ]]
then
echo "::error::Expected git remote url to have token but got '$GIT_REMOTE_URL'"
exit 1
fi
- name: Verify remote access
run: |
git ls-remote origin
gh repo view