Skip to content

Commit 2d480da

Browse files
authored
Check Echidna publishing results for failure or success (#1821)
* The API call does not return its results synchronously, so the status check script polls for the result and exits with an error if it fails. * The Makefiles and CI workflow introduce the ability to run the publishing step as a dry run, so it can be used with pull requests. * CI also supports the ability to use W3C username and password secrets instead of Echidna tokens
1 parent 924c1f8 commit 2d480da

File tree

5 files changed

+98
-10
lines changed

5 files changed

+98
-10
lines changed

.github/workflows/w3c-publish.yml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
name: Publish to W3C TR space
1+
name: Validate/Publish to W3C TR space
22

33
on:
44
push:
55
branches: [ main ]
66
paths: [ .github/**, document/** ]
7+
pull_request:
8+
paths: [ .github/**, document/** ]
79

810
# Allows you to run this workflow manually from the Actions tab, gh CLI tool,
911
# or REST API. THe w3c-status options correspond to the valid options for
@@ -23,9 +25,12 @@ on:
2325
- CRD
2426
- CR
2527

28+
env:
29+
YARN_ENABLE_IMMUTABLE_INSTALLS: false
30+
W3C_STATUS: ${{ github.event_name == 'workflow_dispatch' && inputs.w3c-status || 'WD' }}
31+
2632
jobs:
2733
publish-to-w3c-TR:
28-
if: github.repository == 'WebAssembly/spec'
2934
runs-on: ubuntu-latest
3035
steps:
3136
- name: Checkout repo
@@ -43,10 +48,16 @@ jobs:
4348
- name: Setup Sphinx
4449
run: pip install six && pip install sphinx==5.1.0
4550
- name: Publish all specs to their https://www.w3.org/TR/ URLs
51+
if: env.W3C_ECHIDNA_TOKEN_CORE
4652
run: cd document && make -e WD-echidna-CI
4753
env:
48-
W3C_STATUS: ${{ github.event_name == 'push' && 'WD' || inputs.w3c-status }}
4954
W3C_ECHIDNA_TOKEN_CORE: ${{ secrets.W3C_ECHIDNA_TOKEN_CORE }}
5055
W3C_ECHIDNA_TOKEN_JSAPI: ${{ secrets.W3C_ECHIDNA_TOKEN_JSAPI }}
5156
W3C_ECHIDNA_TOKEN_WEBAPI: ${{ secrets.W3C_ECHIDNA_TOKEN_WEBAPI }}
52-
YARN_ENABLE_IMMUTABLE_INSTALLS: false
57+
ECHIDNA_DRYRUN: ${{ !(github.event_name == 'push' && github.repository == 'WebAssembly/spec' && github.ref == 'refs/heads/main') }}
58+
- name: Validate all specs with Echidna
59+
if: env.W3C_USERNAME
60+
run: cd document && make -e WD-echidna
61+
env:
62+
W3C_USERNAME: ${{ secrets.W3C_USERNAME }}
63+
W3C_PASSWORD: ${{ secrets.W3C_PASSWORD }}

document/core/Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ NAME = WebAssembly
1313
DECISION_URL = https://github.com/WebAssembly/meetings/blob/main/main/2024/WG-06-12.md
1414
TAR = tar
1515
DEADLINE = $(shell date -d "+30 days" +%Y-%m-%d 2>/dev/null || date -v +30d +%Y-%m-%d)
16+
ECHIDNA_DRYRUN = true
1617

1718
# Internal variables.
1819
PAPEROPT_a4 = -D latex_paper_size=a4
@@ -196,7 +197,9 @@ WD-echidna: WD-tar
196197
curl 'https://labs.w3.org/echidna/api/request' \
197198
--user '$(W3C_USERNAME):$(W3C_PASSWORD)' \
198199
-F "tar=@$(BUILDDIR)/WD.tar" \
199-
-F "decision=$(DECISION_URL)" | tee $(BUILDDIR)/WD-echidna-id.txt
200+
-F "decision=$(DECISION_URL)" \
201+
-F "dry-run=$(ECHIDNA_DRYRUN)" | tee $(BUILDDIR)/WD-echidna-id.txt
202+
python3 ../util/check-echidna-status.py $(BUILDDIR)
200203
@echo
201204
@echo "Published $(W3C_STATUS). Check its status at https://labs.w3.org/echidna/api/status?id=`cat $(BUILDDIR)/WD-echidna-id.txt`"
202205

@@ -210,7 +213,9 @@ WD-echidna-CI: WD-tar
210213
curl 'https://labs.w3.org/echidna/api/request' \
211214
-F "tar=@$(BUILDDIR)/WD.tar" \
212215
-F "token=$(W3C_ECHIDNA_TOKEN_CORE)" \
213-
-F "decision=$(DECISION_URL)" | tee $(BUILDDIR)/WD-echidna-id.txt
216+
-F "decision=$(DECISION_URL)" \
217+
-F "dry-run=$(ECHIDNA_DRYRUN)" | tee $(BUILDDIR)/WD-echidna-id.txt
218+
python3 ../util/check-echidna-status.py $(BUILDDIR)
214219
@echo
215220
@echo "Published $(W3C_STATUS). Check its status at https://labs.w3.org/echidna/api/status?id=`cat $(BUILDDIR)/WD-echidna-id.txt`"
216221

document/js-api/Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ NAME = WebAssembly
66
DECISION_URL = https://github.com/WebAssembly/meetings/blob/main/main/2024/WG-06-12.md
77
TAR = tar
88
DEADLINE = $(shell date -d "+30 days" +%Y-%m-%d 2>/dev/null || date -v +30d +%Y-%m-%d)
9+
ECHIDNA_DRYRUN = true
910

1011
.PHONY: all
1112
all:
@@ -49,7 +50,11 @@ WD-echidna: WD-tar
4950
curl 'https://labs.w3.org/echidna/api/request' \
5051
--user '$(W3C_USERNAME):$(W3C_PASSWORD)' \
5152
-F "tar=@$(BUILDDIR)/WD.tar" \
52-
-F "decision=$(DECISION_URL)" | tee $(BUILDDIR)/WD-echidna-id.txt
53+
-F "decision=$(DECISION_URL)" \
54+
-F "dry-run=$(ECHIDNA_DRYRUN)" | tee $(BUILDDIR)/WD-echidna-id.txt
55+
python3 ../util/check-echidna-status.py $(BUILDDIR)
56+
@echo
57+
@echo "Published $(W3C_STATUS). Check its status at https://labs.w3.org/echidna/api/status?id=`cat $(BUILDDIR)/WD-echidna-id.txt`"
5358

5459
.PHONY: WD-echidna-CI
5560
WD-echidna-CI: WD-tar
@@ -61,6 +66,8 @@ WD-echidna-CI: WD-tar
6166
curl 'https://labs.w3.org/echidna/api/request' \
6267
-F "tar=@$(BUILDDIR)/WD.tar" \
6368
-F "token=$(W3C_ECHIDNA_TOKEN_JSAPI)" \
64-
-F "decision=$(DECISION_URL)" | tee $(BUILDDIR)/WD-echidna-id.txt
69+
-F "decision=$(DECISION_URL)" \
70+
-F "dry-run=$(ECHIDNA_DRYRUN)" | tee $(BUILDDIR)/WD-echidna-id.txt
71+
python3 ../util/check-echidna-status.py $(BUILDDIR)
6572
@echo
6673
@echo "Published $(W3C_STATUS). Check its status at https://labs.w3.org/echidna/api/status?id=`cat $(BUILDDIR)/WD-echidna-id.txt`"

document/util/check-echidna-status.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env python3
2+
3+
from datetime import datetime, timedelta
4+
import json
5+
import os
6+
import requests
7+
import sys
8+
import time
9+
10+
ECHIDNA_ID_FILE = 'WD-echidna-id.txt'
11+
ECHIDNA_STATUS_URL = 'http://labs.w3.org/echidna/api/status?id='
12+
13+
14+
def get_echidna_id(directory):
15+
id_file = os.path.join(directory, ECHIDNA_ID_FILE)
16+
file_time = os.path.getmtime(id_file)
17+
if datetime.fromtimestamp(file_time) < datetime.now() - timedelta(hours=1):
18+
print(f'Warning: Echidna ID is not recent: timestamp is {file_time}')
19+
with open(id_file, 'r') as f:
20+
return f.read().strip()
21+
22+
23+
def get_current_response(echidna_id):
24+
url = ECHIDNA_STATUS_URL + echidna_id
25+
print(f'Fetching {url}')
26+
response = requests.get(url, allow_redirects=True)
27+
if response.status_code != 200:
28+
print(f'Got status code {response.status_code}, text:')
29+
print(response.text)
30+
raise Exception('Failed to fetch echidna result')
31+
32+
return response.json()
33+
34+
35+
def get_echidna_result(echidna_id):
36+
response = get_current_response(echidna_id)
37+
while response['results']['status'] == 'started':
38+
time.sleep(5)
39+
print('Echidna run in progress, retrying...')
40+
response = get_current_response(echidna_id)
41+
42+
result = response['results']['status']
43+
print(f'Echidna issue {echidna_id} is {result}.')
44+
print(json.dumps(response, indent=2))
45+
return result == 'success'
46+
47+
48+
def main(argv):
49+
directory = os.getcwd() if len(argv) < 2 else argv[1]
50+
echidna_id = get_echidna_id(directory)
51+
print(f'Got echidna id {echidna_id}.')
52+
time.sleep(5)
53+
if not get_echidna_result(echidna_id):
54+
sys.exit(1)
55+
56+
57+
if __name__ == '__main__':
58+
main(sys.argv)

document/web-api/Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ NAME = WebAssembly
66
DECISION_URL = https://github.com/WebAssembly/meetings/blob/main/main/2024/WG-06-12.md
77
TAR = tar
88
DEADLINE = $(shell date -d "+30 days" +%Y-%m-%d 2>/dev/null || date -v +30d +%Y-%m-%d)
9+
ECHIDNA_DRYRUN = true
910

1011
.PHONY: all
1112
all:
@@ -49,7 +50,11 @@ WD-echidna: WD-tar
4950
curl 'https://labs.w3.org/echidna/api/request' \
5051
--user '$(W3C_USERNAME):$(W3C_PASSWORD)' \
5152
-F "tar=@$(BUILDDIR)/WD.tar" \
52-
-F "decision=$(DECISION_URL)" | tee $(BUILDDIR)/WD-echidna-id.txt
53+
-F "decision=$(DECISION_URL)" \
54+
-F "dry-run=$(ECHIDNA_DRYRUN)" | tee $(BUILDDIR)/WD-echidna-id.txt
55+
python3 ../util/check-echidna-status.py $(BUILDDIR)
56+
@echo
57+
@echo "Published $(W3C_STATUS). Check its status at https://labs.w3.org/echidna/api/status?id=`cat $(BUILDDIR)/WD-echidna-id.txt`"
5358

5459
.PHONY: WD-echidna-CI
5560
WD-echidna-CI: WD-tar
@@ -61,6 +66,8 @@ WD-echidna-CI: WD-tar
6166
curl 'https://labs.w3.org/echidna/api/request' \
6267
-F "tar=@$(BUILDDIR)/WD.tar" \
6368
-F "token=$(W3C_ECHIDNA_TOKEN_WEBAPI)" \
64-
-F "decision=$(DECISION_URL)" | tee $(BUILDDIR)/WD-echidna-id.txt
69+
-F "decision=$(DECISION_URL)" \
70+
-F "dry-run=$(ECHIDNA_DRYRUN)" | tee $(BUILDDIR)/WD-echidna-id.txt
71+
python3 ../util/check-echidna-status.py $(BUILDDIR)
6572
@echo
6673
@echo "Published $(W3C_STATUS). Check its status at https://labs.w3.org/echidna/api/status?id=`cat $(BUILDDIR)/WD-echidna-id.txt`"

0 commit comments

Comments
 (0)