-
Notifications
You must be signed in to change notification settings - Fork 3
242 lines (212 loc) · 10.3 KB
/
e2e_push.yaml
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
name: E2E Pushing Tests
on:
workflow_dispatch:
pull_request:
concurrency: e2e-tests
jobs:
e2e-tests-reconcile:
permissions: write-all
runs-on: ubuntu-22.04
steps:
# Each job has to have this configuration because secrets can be passed through the output of
# another job
- name: Generate discourse configuration
id: configuration
run: |
echo "discourse= \
{ \
\"hostname\":\"discourse.charmhub.io\", \
\"category_id\":\"41\", \
\"api_username\":\"${{ secrets.DISCOURSE_API_USERNAME }}\", \
\"api_key\":\"${{ secrets.DISCOURSE_API_KEY }}\" \
}" >> $GITHUB_OUTPUT
- uses: actions/checkout@v3
- name: Setup Python
run: |
sudo apt update && sudo apt install python3-pip git
pip3 install --upgrade pip
pip3 install -r requirements.txt
- name: Prepare for action to run
run: |
# Create metadata.yaml file
echo "name: $(echo ${{ github.repository }} | sed 's:.*/::')-test" > metadata.yaml
# Create documentation index file
mkdir docs
# need some values in the content that change on every commit as discourse looks for file
# similarity
echo -e "# Charm Upload Automation Reconcile Test Index Title some uuid: $(uuidgen)\n" \
"placeholder index content for testing, " \
"repository: ${{ github.repository }}, " \
"branch: ${{ github.head_ref }}, " \
"commit sha: ${{ github.sha }}, " \
"some uuid: $(uuidgen)" \
> docs/index.md
echo -e "# Charm Upload Automation Reconcile Test Documentation Title some uuid: $(uuidgen)\n" \
"placeholder documentation content for testing, " \
"repository: ${{ github.repository }}, " \
"branch: ${{ github.head_ref }}, " \
"commit sha: ${{ github.sha }}, " \
"some uuid: $(uuidgen)" \
> docs/doc.md
echo -e "# Charm Upload Automation Reconcile Test Documentation Alternate Title some uuid: $(uuidgen)\n" \
"placeholder documentation alternate content for testing, " \
"repository: ${{ github.repository }}, " \
"branch: ${{ github.head_ref }}, " \
"commit sha: ${{ github.sha }}, " \
"some uuid: $(uuidgen)" \
> docs/alternate_doc.md
- name: Prepare stage
id: prepare-stage
run: |
PYTHONPATH=$(pwd) python3 tests/e2e/reconcile.py --action prepare --github-token ${{ secrets.GITHUB_TOKEN }} '{}' '${{ steps.configuration.outputs.discourse }}'
echo $(git log | head -n 1)
echo "Tags"
echo $(git tag -l | cat)
COMMIT_SHA=$(git log | head -n 1 | sed -En "s/commit\ //p")
echo "commit_sha=$COMMIT_SHA" >> "$GITHUB_OUTPUT"
- name: Draft self test
id: dry-create
uses: canonical/discourse-gatekeeper@main
with:
discourse_host: discourse.charmhub.io
discourse_api_username: ${{ secrets.DISCOURSE_API_USERNAME }}
discourse_api_key: ${{ secrets.DISCOURSE_API_KEY }}
github_token: ${{ secrets.GITHUB_TOKEN }}
dry_run: true
base_branch: "tests/base"
commit_sha: ${{ steps.prepare-stage.outputs.commit_sha }}
- name: Check dry creation
run: |
echo '${{ steps.dry-create.outputs.topics }}'
echo $(git log | head -n 1)
PYTHONPATH=$(pwd) python3 tests/e2e/reconcile.py --action check-draft --github-token ${{ secrets.GITHUB_TOKEN }} --action-kwargs '{"expected_url_results": []}' '${{ steps. dry-create.outputs.topics }}' '${{ steps.configuration.outputs.discourse }}'
echo $(git log | head -n 1)
echo "Tags"
echo $(git tag -l | cat)
- name: Create self test
id: create
uses: canonical/discourse-gatekeeper@main
with:
discourse_host: discourse.charmhub.io
discourse_api_username: ${{ secrets.DISCOURSE_API_USERNAME }}
discourse_api_key: ${{ secrets.DISCOURSE_API_KEY }}
github_token: ${{ secrets.GITHUB_TOKEN }}
base_branch: "tests/base"
commit_sha: ${{ steps.prepare-stage.outputs.commit_sha }}
- name: Check creation
run: |
echo '${{ steps.create.outputs.index_url }}'
echo '${{ steps.create.outputs.topics }}'
echo $(git log | head -n 1)
PYTHONPATH=$(pwd) python3 tests/e2e/reconcile.py --action check-create --github-token ${{ secrets.GITHUB_TOKEN }} --action-kwargs '{"expected_url_results": ["success", "success", "success"]}' '${{ steps.create.outputs.topics }}' '${{ steps.configuration.outputs.discourse }}'
echo $(git log | head -n 1)
echo "Tags"
echo $(git tag -l | cat)
- name: Add docs key to metadata
id: add-docs-key
run: |
echo "docs: ${{ steps.create.outputs.index_url }}" >> metadata.yaml
cat metadata.yaml
git status
git add -u
git commit -m "Update metadata"
git push
echo $(git log | head -n 1)
COMMIT_SHA=$(git log | head -n 1 | sed -En "s/commit\ //p")
echo "commit_sha=$COMMIT_SHA" >> "$GITHUB_OUTPUT"
echo "Tags"
echo $(git tag -l | cat)
- name: Update self test
id: update
uses: canonical/discourse-gatekeeper@main
with:
discourse_host: discourse.charmhub.io
discourse_api_username: ${{ secrets.DISCOURSE_API_USERNAME }}
discourse_api_key: ${{ secrets.DISCOURSE_API_KEY }}
github_token: ${{ secrets.GITHUB_TOKEN }}
base_branch: "tests/base"
commit_sha: ${{ steps.add-docs-key.outputs.commit_sha }}
- name: Show pages
run: |
# The previous action should have created a PR to fix the formats as well as file naming
echo '${{ steps.update.outputs.pr_action }}'
echo '${{ steps.update.outputs.pr_link }}'
- name: Check update
id: check-update
run: |
GITHUB_TOKEN='${{ secrets.GITHUB_TOKEN }}'
REPO='${{ github.repository }}'
# This should also merge the PR, and the next action run should automatically close the PR
PYTHONPATH=$(pwd) python3 tests/e2e/reconcile.py --action check-update --github-token ${{ secrets.GITHUB_TOKEN }} --action-kwargs "{\"expected_url_results\": [\"success\", \"success\", \"success\"]}" '${{ steps.create.outputs.topics }}' '${{ steps.configuration.outputs.discourse }}'
echo $(git log | head -n 1)
COMMIT_SHA=$(git log | head -n 1 | sed -En "s/commit\ //p")
echo "commit_sha=$COMMIT_SHA" >> "$GITHUB_OUTPUT"
echo "Tags"
echo $(git tag -l | cat)
- name: Close Merged PR
id: update-closed
uses: canonical/discourse-gatekeeper@main
with:
discourse_host: discourse.charmhub.io
discourse_api_username: ${{ secrets.DISCOURSE_API_USERNAME }}
discourse_api_key: ${{ secrets.DISCOURSE_API_KEY }}
github_token: ${{ secrets.GITHUB_TOKEN }}
base_branch: "tests/base"
commit_sha: ${{ steps.check-update.outputs.commit_sha }}
- name: Delete the alternate doc with delete_topics disabled
id: alternate-doc-deleted
run: |
rm docs/alternate-doc.md
sed -i '/alternate-doc/d' docs/index.md
git add -u
git commit -m "Delete docs/alternate_doc.md"
echo $(git log | head -n 1)
COMMIT_SHA=$(git log | head -n 1 | sed -En "s/commit\ //p")
echo "commit_sha=$COMMIT_SHA" >> "$GITHUB_OUTPUT"
- name: Delete topics disabled self test
id: e2e-test-delete-topics
uses: canonical/discourse-gatekeeper@main
with:
delete_topics: false
discourse_host: discourse.charmhub.io
discourse_api_username: ${{ secrets.DISCOURSE_API_USERNAME }}
discourse_api_key: ${{ secrets.DISCOURSE_API_KEY }}
github_token: ${{ secrets.GITHUB_TOKEN }}
base_branch: "tests/base"
commit_sha: ${{ steps.alternate-doc-deleted.outputs.commit_sha }}
- name: Show pages
run: echo '${{ steps.e2e-test-delete-topics.outputs.topics }}'
- name: Check delete topics disabled
run: |
PYTHONPATH=$(pwd) python3 tests/e2e/reconcile.py --action check-delete-topics --github-token ${{ secrets.GITHUB_TOKEN }} --action-kwargs '{"expected_url_results": ["success", "skip", "success"]}' '${{ steps.e2e-test-delete-topics.outputs.topics }}' '${{ steps.configuration.outputs.discourse }}'
- name: Delete the doc with delete_topics enabled
id: doc-deleted
run: |
rm docs/doc.md
sed -i '/doc/d' docs/index.md
git add -u
git commit -m "Delete docs/alternate_doc.md"
echo $(git log | head -n 1)
COMMIT_SHA=$(git log | head -n 1 | sed -En "s/commit\ //p")
echo "commit_sha=$COMMIT_SHA" >> "$GITHUB_OUTPUT"
- name: Delete topics enabled self test
id: e2e-test-delete
uses: canonical/discourse-gatekeeper@main
with:
discourse_host: discourse.charmhub.io
discourse_api_username: ${{ secrets.DISCOURSE_API_USERNAME }}
discourse_api_key: ${{ secrets.DISCOURSE_API_KEY }}
github_token: ${{ secrets.GITHUB_TOKEN }}
base_branch: "tests/base"
commit_sha: ${{ steps.doc-deleted.outputs.commit_sha }}
- name: Show pages
run: echo '${{ steps.e2e-test-delete.outputs.topics }}'
- name: Check delete topics enabled
run: |
PYTHONPATH=$(pwd) python3 tests/e2e/reconcile.py --action check-delete --github-token ${{ secrets.GITHUB_TOKEN }} --action-kwargs '{"expected_url_results": ["success", "success"]}' '${{ steps.e2e-test-delete.outputs.topics }}' '${{ steps.configuration.outputs.discourse }}'
- name: Clean up
if: always()
run: |
GITHUB_TOKEN='${{ secrets.GITHUB_TOKEN }}'
REPO='${{ github.repository }}'
PYTHONPATH=$(pwd) python3 tests/e2e/reconcile.py --action cleanup --github-token ${{ secrets.GITHUB_TOKEN }} --action-kwargs "{\"github_token\": \"$GITHUB_TOKEN\", \"repo\": \"$REPO\"}" '${{ steps.create.outputs.topics }}' '${{ steps.configuration.outputs.discourse }}'