8000 add WebSocketsVersion.h and some build checks · IceWalnut/arduinoWebSockets@fd83d6a · GitHub
[go: up one dir, main page]

Skip to content

Commit fd83d6a

Browse files
committed
add WebSocketsVersion.h and some build checks
1 parent 0e729cd commit fd83d6a

File tree

5 files changed

+143
-14
lines changed

5 files changed

+143
-14
lines changed

.github/workflows/main.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ on:
1414

1515
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
1616
jobs:
17+
check_version_files:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v2
21+
22+
- name: check version
23+
run: |
24+
$GITHUB_WORKSPACE/travis/version.py --check
1725
1826
prepare_example_json:
1927
runs-on: ubuntu-latest
@@ -147,6 +155,7 @@ jobs:
147155
148156
- name: copy code
149157
run: |
158+
mkdir -p $HOME/Arduino/libraries/
150159
cp -r $GITHUB_WORKSPACE $HOME/Arduino/libraries/arduinoWebSockets
151160
152161
- name: config IDE
@@ -158,6 +167,7 @@ jobs:
158167
arduino --pref update.check=false
159168
160169
- name: build example
170+
timeout-minutes: 20
161171
run: |
162172
export DISPLAY=:1.0
163173
export PATH="$HOME/arduino_ide:$PATH"
@@ -166,7 +176,7 @@ jobs:
166176
build_sketch arduino $SKETCH
167177
168178
done:
169-
needs: [prepare_ide, prepare_example_json, build]
179+
needs: [prepare_ide, prepare_example_json, build, check_version_files]
170180
runs-on: ubuntu-latest
171181
steps:
172182
- name: Done

library.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
{
2-
"name": "WebSockets",
3-
"description": "WebSocket Server and Client for Arduino based on RFC6455",
4-
"keywords": "wifi, http, web, server, client, websocket",
52
"authors": [
63
{
4+
"maintainer": true,
75
"name": "Markus Sattler",
8-
"url": "https://github.com/Links2004",
9-
"maintainer": true
6+
"url": "https://github.com/Links2004"
107
}
118
],
12-
"repository": {
13-
"type": "git",
14-
"url": "https://github.com/Links2004/arduinoWebSockets.git"
15-
},
16-
"version": "2.3.2",
17-
"license": "LGPL-2.1",
9+
"description": "WebSocket Server and Client for Arduino based on RFC6455",
1810
"export": {
1911
"exclude": [
2012
"tests"
2113
]
2214
},
2315
"frameworks": "arduino",
24-
"platforms": "atmelavr, espressif8266, espressif32"
25-
}
16+
"keywords": "wifi, http, web, server, client, websocket",
17+
"license": "LGPL-2.1",
18+
"name": "WebSockets",
19+
"platforms": "atmelavr, espressif8266, espressif32",
20+
"repository": {
21+
"type": "git",
22+
"url": "https://github.com/Links2004/arduinoWebSockets.git"
23+
},
24+
"version": "2.3.2"
25+
}

src/WebSockets.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
#include <functional>
4141
#endif
4242

43+
#include "WebSocketsVersion.h"
44+
4345
#ifndef NODEBUG_WEBSOCKETS
4446
#ifdef DEBUG_ESP_PORT
4547
#define DEBUG_WEBSOCKETS(...) \

src/WebSocketsVersion.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* @file WebSocketsVersion.h
3+
* @date 07.01.2021
4+
* @author Markus Sattler
5+
*
6+
* Copyright (c) 2015 Markus Sattler. All rights reserved.
7+
* This file is part of the WebSockets for Arduino.
8+
*
9+
* This library is free software; you can redistribute it and/or
10+
* modify it under the terms of the GNU Lesser General Public
11+
* License as published by the Free Software Foundation; either
12+
* version 2.1 of the License, or (at your option) any later version.
13+
*
14+
* This library is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
* Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public
20+
* License along with this library; if not, write to the Free Software
21+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22+
*
23+
*/
24+
25+
#ifndef WEBSOCKETSVERSION_H_
26+
#define WEBSOCKETSVERSION_H_
27+
28+
#define WEBSOCKETS_VERSION "2.3.2"
29+
30+
#define WEBSOCKETS_VERSION_MAJOR 2
31+
#define WEBSOCKETS_VERSION_MINOR 3
32+
#define WEBSOCKETS_VERSION_PATCH 2
33+
34+
#define WEBSOCKETS_VERSION_INT 2003002
35+
36+
#endif /* WEBSOCKETSVERSION_H_ */

travis/version.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/usr/bin/python3
2+
3+
import json
4+
import configparser
5+
import argparse
6+
import re
7+
import os
8+
9+
travis_dir = os.path.dirname(os.path.abspath(__file__))
10+
base_dir = os.path.abspath(travis_dir + "/../")
11+
12+
def get_library_properties_version():
13+
library_properties = {}
14+
with open(f'{base_dir}/library.properties', 'r') as f:
15+
library_properties = configparser.ConfigParser()
16+
library_properties.read_string('[root]\n' + f.read())
17+
return library_properties['root']['version']
18+
19+
def get_library_json_version():
20+
library_json = {}
21+
with open(f'{base_dir}/library.json', 'r') as f:
22+
library_json = json.load(f)
23+
return library_json['version']
24+
25+
def get_header_versions():
26+
data = {}
27+
define = re.compile('^#define WEBSOCKETS_VERSION_?(.*) "?([0-9\.]*)"?$')
28+
with open(f'{base_dir}/src/WebSocketsVersion.h', 'r') as f:
29+
for line in f:
30+
m = define.match(line)
31+
if m:
32+
name = m[1]
33+
if name == "":
34+
name = "VERSION"
35+
data[name] = m[2]
36+
return data
37+
38+
39+
parser = argparse.ArgumentParser(description='Checks and update Version files')
40+
parser.add_argument(
41+
'--update', action=argparse.BooleanOptionalAction, default=False)
42+
parser.add_argument(
43+
'--check', action=argparse.BooleanOptionalAction, default=True)
44+
45+
args = parser.parse_args()
46+
47+
if args.update:
48+
library_properties_version = get_library_properties_version()
49+
50+
with open(f'{base_dir}/library.json', 'r') as f:
51+
library_json = json.load(f)
52+
53+
library_json['version'] = library_properties_version
54+
55+
with open(f'{base_dir}/library.json', 'w') as f:
56+
json.dump(library_json, f, indent=4, sort_keys=True)
57+
58+
59+
library_json_version = get_library_json_version()
60+
library_properties_version = get_library_properties_version()
61+
header_version = get_header_versions()
62+
63+
print("WebSocketsVersion.h", header_version)
64+
print(f"library.json: {library_json_version}")
65+
print(f"library.properties: {library_properties_version}")
66+
67+
if args.check:
68+
if library_json_version != library_properties_version or header_version['VERSION'] != library_properties_version:
69+
raise Exception('versions did not match!')
70+
71+
hvs = header_version['VERSION'].split('.')
72+
if header_version['MAJOR'] != hvs[0]:
73+
raise Exception('header MAJOR version wrong!')
74+
if header_version['MINOR'] != hvs[1]:
75+
raise Exception('header MINOR version wrong!')
76+
if header_version['PATCH'] != hvs[2]:
77+
raise Exception('header PATCH version wrong!')
78+
79+
intversion = int(hvs[0]) * 1000000 + int(hvs[1]) * 1000 + int(hvs[2])
80+
if int(header_version['INT']) != intversion:
81+
raise Exception('header INT version wrong!')

0 commit comments

Comments
 (0) 2F9C
0