Skip to content

Commit f331a0b

Browse files
authored
Update deprecated github actions to latest version (#1231)
* Update deprecated github actions Signed-off-by: thepetk <[email protected]> * Remove jsonschema dep from validate samples Signed-off-by: thepetk <[email protected]> --------- Signed-off-by: thepetk <[email protected]>
1 parent adde8ec commit f331a0b

8 files changed

+83
-14
lines changed

Diff for: .devfile/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ ENV GOROOT /usr/lib/go
33

44
RUN apk add --no-cache --update curl bash jq go git openssh \
55
&& pip3 install yq \
6-
&& pip3 install jsonschema-cli
6+
&& pip3 install pyyaml \
7+
&& pip3 install jsonschema
78

89
RUN mkdir -p /home/user/go && chmod -R a+w /home/user
910
ENV HOME /home/user

Diff for: .github/workflows/ci.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ jobs:
1717
runs-on: ubuntu-latest
1818

1919
steps:
20-
- uses: actions/checkout@v2
20+
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
2121

2222
- name: Setup Go environment
23-
uses: actions/setup-go@v2.1.3
23+
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
2424
with:
2525
# The Go version to download (if necessary) and use. Supports semver spec and ranges.
2626
go-version: 1.18
@@ -42,7 +42,7 @@ jobs:
4242
run: go test -coverprofile cover.out -v ./...
4343

4444
- name: Upload coverage to Codecov
45-
uses: codecov/codecov-action@v2.1.0
45+
uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4
4646

4747
- name: Check typescript model generation
4848
run: bash ./build/typescript-model/generate.sh

Diff for: .github/workflows/codecov.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ jobs:
1414
runs-on: ubuntu-20.04
1515
steps:
1616
- name: Checkout
17-
uses: actions/checkout@v2.3.1
17+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
1818
with:
1919
persist-credentials: false
2020
- name: Set up Go 1.x
21-
uses: actions/setup-go@v2
21+
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
2222
with:
2323
go-version: 1.17
2424
- name: Run tests
2525
run: go test ./... -coverprofile cover.out
2626
- name: Codecov
27-
uses: codecov/codecov-action@v2.1.0
27+
uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4

Diff for: .github/workflows/publish-devfile-schema.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ jobs:
2020
python-version: '3.9'
2121

2222
- name: Checkout devfile/devfile-web
23-
uses: actions/checkout@v2
23+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
2424
with:
2525
repository: devfile/devfile-web
2626
persist-credentials: false
2727
path: devfile-web-repo
2828

2929
- name: Checkout devfile api
30-
uses: actions/checkout@v2
30+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
3131
with:
3232
path: api-repo
3333

Diff for: .github/workflows/release-devfile-schema.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ jobs:
2020
python-version: '3.9'
2121

2222
- name: Checkout devfile/devfile-web
23-
uses: actions/checkout@v2
23+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
2424
with:
2525
repository: devfile/devfile-web
2626
persist-credentials: false
2727
path: devfile-web-repo
2828

2929
- name: Checkout devfile/api
30-
uses: actions/checkout@v2
30+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
3131
with:
3232
path: api-repo
3333

Diff for: .github/workflows/release-typescript-models.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
runs-on: ubuntu-latest
1616
steps:
1717
- name: Checkout devfile/api
18-
uses: actions/checkout@v2
18+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
1919
with:
2020
path: api
2121

Diff for: validate-samples.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ then
3232
exit 1
3333
fi
3434

35-
if ! command -v jsonschema-cli &> /dev/null
35+
if ! command -v jsonschema &> /dev/null
3636
then
3737
echo
3838
echo "#### ERROR ####"
@@ -58,7 +58,8 @@ do
5858
echo "Validating $schema files against ${schemaPath}"
5959
for devfile in $devfiles
6060
do
61-
if ! jsonschema-cli validate "${BASE_DIR}/${schemaPath}" "${BASE_DIR}/${devfile}" >> validate-output.txt
61+
python3 validate_yaml.py "${BASE_DIR}/${schemaPath}" "${BASE_DIR}/${devfile}" >> validate-output.txt
62+
if [ "$(cat validate-output.txt)" != "" ]
6263
then
6364
echo " - $devfile => INVALID"
6465
else

Diff for: validate_yaml.py

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env python
2+
import json
3+
import yaml
4+
import sys
5+
6+
from typing import Any
7+
from jsonschema import validate, ValidationError
8+
9+
10+
class ParseSchemaError(Exception):
11+
pass
12+
13+
14+
class YamlValidationError(Exception):
15+
pass
16+
17+
18+
class OpenFileError(Exception):
19+
pass
20+
21+
22+
class NotEnoughArgsError(Exception):
23+
pass
24+
25+
26+
class YamlValidator:
27+
"""
28+
Yaml validator validates a given yaml file against
29+
a chosen template.
30+
"""
31+
def __init__(self, schema_path: str) -> None:
32+
self.schema = self._parse_json_file(schema_path)
33+
34+
def _open_file(self, path: str) -> Any:
35+
try:
36+
return open(path)
37+
except OSError as exc:
38+
raise OpenFileError(f"::error:: failed to open file {path}: {exc}")
39+
40+
def _parse_json_file(self, json_path: str) -> dict[str, Any]:
41+
return json.load(self._open_file(json_path))
42+
43+
def _get_yaml_file(self, yaml_path: str):
44+
return yaml.load(self._open_file(yaml_path), Loader=yaml.SafeLoader)
45+
46+
def validate(self, path: str) -> bool:
47+
try:
48+
_ = validate(instance=self._get_yaml_file(path), schema=self.schema)
49+
except ValidationError as exc:
50+
raise YamlValidationError(f"error:: validation failed: {str(exc.message)}")
51+
return True
52+
53+
54+
def parse_arg(index: int) -> str:
55+
try:
56+
return sys.argv[index]
57+
except IndexError:
58+
raise NotEnoughArgsError(
59+
"Missing Args: Example usage -> validate-yaml.py <schema_path> <yaml_path>"
60+
)
61+
62+
63+
if __name__ == "__main__":
64+
schema_path = parse_arg(1)
65+
yaml_path = parse_arg(2)
66+
validator = YamlValidator(schema_path=schema_path)
67+
validator.validate(yaml_path)

0 commit comments

Comments
 (0)