Skip to content

Commit 146ebc3

Browse files
raboofassignUser
andauthored
refactor(gateway): migrate to ruyaml (#169)
* Run tests for PRs There are some specific tests for the stash action in `.github/workflows/stash-action-test.yml`. These might test particular scenario's, but we should also run the 'default' testset that includes the gateway tests * gateway: migrate to ruyaml in preparation of supporting tag comments * Update .github/workflows/test.yml Signed-off-by: Jacob Wujciak-Jens <jacob@wujciak.de> * tweak test workflow * fix job name --------- Signed-off-by: Jacob Wujciak-Jens <jacob@wujciak.de> Co-authored-by: Jacob Wujciak-Jens <jacob@wujciak.de>
1 parent 3222bfc commit 146ebc3

5 files changed

Lines changed: 203 additions & 15 deletions

File tree

.github/workflows/pytest.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
#
18+
name: pytest
19+
20+
on:
21+
pull_request:
22+
branches: [main]
23+
24+
permissions:
25+
contents: read
26+
27+
jobs:
28+
test:
29+
runs-on: ubuntu-latest
30+
steps:
31+
- uses: actions/checkout@v4
32+
with:
33+
persist-credentials: false
34+
35+
- name: Set up Python environment
36+
uses: actions/setup-python@v5
37+
38+
- name: Install dependencies
39+
run: |
40+
pip install pytest ruyaml
41+
42+
- name: Run tests
43+
run: |
44+
pytest
45+
env:
46+
GH_TOKEN: ${{ github.token }}

gateway/gateway.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
from pathlib import Path
44
from typing import Dict, NotRequired, TypedDict
55

6-
import yaml
7-
6+
import ruyaml
87

98
class RefDetails(TypedDict):
109
"""
@@ -50,19 +49,11 @@ def load_yaml(path: Path) -> dict:
5049
dict: Parsed YAML content
5150
"""
5251
with open(path, "r") as file:
53-
actions = yaml.safe_load(file)
52+
yaml = ruyaml.YAML()
53+
actions = yaml.load(file)
5454
return actions
5555

5656

57-
class IndentDumper(yaml.Dumper):
58-
"""
59-
Custom YAML dumper that maintains indentation for improved readability.
60-
"""
61-
62-
def increase_indent(self, flow=False, indentless=False):
63-
return super(IndentDumper, self).increase_indent(flow, False)
64-
65-
6657
def write_yaml(path: Path, yaml_dict: dict | list):
6758
"""
6859
Write data as YAML to a file using custom indentation.
@@ -72,7 +63,8 @@ def write_yaml(path: Path, yaml_dict: dict | list):
7263
yaml_dict: Data to write as YAML
7364
"""
7465
with open(path, "w") as file:
75-
yaml.dump(yaml_dict, file, Dumper=IndentDumper, sort_keys=False)
66+
yaml = ruyaml.YAML()
67+
yaml.dump(yaml_dict, file)
7668

7769

7870
def write_str(path: Path, content: str):

gateway/test_dummy.yml

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
name: Dummy Workflow
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
dummy:
8+
if: false
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: 1Password/load-secrets-action@581a835fb51b8e7ec56b71cf2ffddd7e68bb25e0
12+
- uses: ana06/get-changed-files@v2.3.0
13+
- uses: DavidAnson/markdownlint-cli2-action@b4c9feab76d8025d1e83c653fa3990936df0e6c8 # v16
14+
- uses: JamesIves/github-pages-deploy-action@881db5376404c5c8d621010bcbec0310b58d5e29 # v4.6.8
15+
- uses: JustinBeckwith/linkinator-action@3d5ba091319fa7b0ac14703761eebb7d100e6f6d
16+
- uses: JustinBeckwith/linkinator-action@v1.11.0
17+
- uses: Kesin11/actions-timeline@427ee2cf860166e404d0d69b4f2b24012bb7af4f
18+
- uses: Madrapps/jacoco-report@fd4800e8a81e21bdf373438e5918b975df041d15
19+
- uses: VirtusLab/scala-cli-setup@ca54569bf13a29cd648721038a89c47c7921c060
20+
- uses: VirtusLab/scala-cli-setup@6fc878be89f1990f6599f4f6a2e52a252e54d9f9
21+
- uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b
22+
- uses: actions/setup-go@v5
23+
- uses: addnab/docker-run-action@4f65fabd2431ebc8d299f8e5a018d79a769ae185
24+
- uses: addnab/docker-run-action@v3
25+
- uses: amondnet/vercel-action@225d234cfe5340ca1f9a6cd158338126b5b6845f
26+
- uses: amondnet/vercel-action@v25.1.1
27+
- uses: aws-actions/configure-aws-credentials@ececac1a45f3b08a01d2dd070d28d111c5fe6722
28+
- uses: aws-actions/configure-aws-credentials@v4.1.0
29+
- uses: azure/setup-helm@5119fcb9089d432beecbf79bb2c7915207344b78
30+
- uses: azure/setup-helm@v3
31+
- uses: betahuhn/repo-file-sync-action@8b92be3375cf1d1b0cd579af488a9255572e4619
32+
- uses: betahuhn/repo-file-sync-action@v1
33+
- uses: bnjbvr/cargo-machete@5eaad10acf89fb0c6a31d9b197a2d48ba762d28e
34+
- uses: bnjbvr/cargo-machete@v0.7.0
35+
- uses: browser-actions/setup-firefox@5b19b18df8c293aae9e77f0a936e9fdc358f543a
36+
- uses: browser-actions/setup-firefox@v1
37+
- uses: browser-actions/setup-geckodriver@5ef1526ed36211ab6cb531ec1cfb11f924ca2dee
38+
- uses: burnett01/rsync-deployments@0dc935cdecc5f5e571865e60d2a6cdc673704823
39+
- uses: burnett01/rsync-deployments@5.2
40+
- uses: carloscastrojumo/github-cherry-pick-action@a145da1b8142e752d3cbc11aaaa46a535690f0c5
41+
- uses: carloscastrojumo/github-cherry-pick-action@v1.0.9
42+
- uses: carloscastrojumo/github-cherry-pick-action@503773289f4a459069c832dc628826685b75b4b3
43+
- uses: carloscastrojumo/github-cherry-pick-action@v1.0.10
44+
- uses: commit-check/commit-check-action@8d507e12899a9feb405c3ed546252ff9508724e0
45+
- uses: coursier/cache-action@4e2615869d13561d626ed48655e1a39e5b192b3c
46+
- uses: coursier/setup-action@039f736548afa5411c1382f40a5bd9c2d30e0383
47+
- uses: cpp-linter/cpp-linter-action@e3fcb174b19d50de4eae1b46896698a1dd48b094
48+
- uses: cpp-linter/cpp-linter-action@v2.13.3
49+
- uses: crazy-max/ghaction-import-gpg@111c56156bcc6918c056dbef52164cfa583dc549
50+
- uses: crazy-max/ghaction-setup-docker@b60f85385d03ac8acfca6d9996982511d8620a19
51+
- uses: crazy-max/ghaction-setup-docker@v4
52+
- uses: damccorm/tag-ur-it@6fa72bbf1a2ea157b533d7e7abeafdb5855dbea5
53+
- uses: dawidd6/action-send-mail@4226df7daafa6fc901a43789c49bf7ab309066e7
54+
- uses: dawidd6/action-send-mail@v3
55+
- uses: docker://jekyll/jekyll@sha256:400b8d1569f118bca8a3a09a25f32803b00a55d1ea241feaf5f904d66ca9c625
56+
- uses: docker://jekyll/jekyll@*
57+
- uses: dominikh/staticcheck-action@4ec9a0dff54be2642bc76581598ba433fd8d4967
58+
- uses: dominikh/staticcheck-action@v1.1.0
59+
- uses: dorny/paths-filter@v3.0.2
60+
- uses: google-github-actions/setup-gcloud@77e7a554d41e2ee56fc945c52dfd3f33d12def9a
61+
- uses: graalvm/setup-graalvm@01ed653ac833fe80569f1ef9f25585ba2811baab
62+
- uses: graalvm/setup-graalvm@v1
63+
- uses: gradle/wrapper-validation-action@v3.5.0
64+
- uses: hadolint/hadolint-action@f988afea3da57ee48710a9795b6bb677cc901183
65+
- uses: hadolint/hadolint-action@v2.1.0
66+
- uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd
67+
- uses: hashicorp/setup-terraform@v3
68+
- uses: helm/chart-releaser-action@fc23f249f75decd5edf254c6b4401532cef093c3
69+
- uses: helm/chart-releaser-action@v1.4.0
70+
- uses: helm/chart-testing-action@e6669bcd63d7cb57cb4380c33043eebe5d111992
71+
- uses: helm/chart-testing-action@v2.6.1
72+
- uses: helm/chart-testing-action@0d28d3144d3a25ea2cc349d6e59901c4ff469b3b
73+
- uses: helm/chart-testing-action@v2.7.0
74+
- uses: helm/kind-action@0025e74a8c7512023d06dc019c617aa3cf561fde
75+
- uses: helm/kind-action@v1.10.0
76+
- uses: ilammy/setup-nasm@e77cc62a22a374a4d0668286007cc3e3b4c17760
77+
- uses: ilammy/setup-nasm@v1
78+
- uses: jasonetco/create-an-issue@1b14a70e4d8dc185e5cc76d3bec9eab20257b2c5
79+
- uses: jasonetco/create-an-issue@v2
80+
- uses: jrouly/scalafmt-native-action@14620cde093e5ff6bfbbecd4f638370024287b9d
81+
- uses: jwgmeligmeyling/pmd-github-action@322e346bd76a0757c4d54ff9209e245965aa066d
82+
- uses: korandoru/setup-zig@92b649f4723a14798d8b3cf3b6168edb65d5b04e
83+
- uses: korandoru/setup-zig@v1
84+
- uses: leafo/gh-actions-luarocks@e65774a6386cb4f24e293dca7fc4ff89165b64c5
85+
- uses: ludeeus/action-shellcheck@1.1.0
86+
- uses: ludeeus/action-shellcheck@94e0aab03ca135d11a35e5bfc14e6746dc56e7e9
87+
- uses: manusa/actions-setup-minikube@b589f2d61bf96695c546929c72b38563e856059d
88+
- uses: mozilla-actions/sccache-action@2e7f9ec7921547d4b46598398ca573513895d0bd
89+
- uses: mozilla-actions/sccache-action@v0.0.4
90+
- uses: mozilla-actions/sccache-action@7d986dd989559c6ecdb630a3fd2557667be217ad
91+
- uses: mozilla-actions/sccache-action@v0.0.9
92+
- uses: mukunku/tag-exists-action@bdad1eaa119ce71b150b952c97351c75025c06a9
93+
- uses: mukunku/tag-exists-action@v1.6.0
94+
- uses: ncipollo/release-action@1e3e9c6637e5566e185b7ab66f187539c5a76da7
95+
- uses: neofinancial/ticket-check-action@609d901d5130a4bbd7d9f62931082ed67f855891
96+
- uses: neofinancial/ticket-check-action@v2.0.0
97+
- uses: nwtgck/actions-netlify@ac1cb16858bada08a9c71a81240a85cfc3f72913
98+
- uses: nwtgck/actions-netlify@v1.2
99+
- uses: opentofu/setup-opentofu@592200bd4b9bbf4772ace78f887668b1aee8f716
100+
- uses: opentofu/setup-opentofu@v1
101+
- uses: orhun/git-cliff-action@4a4a951bc43fafe41cd2348d181853f52356bee7
102+
- uses: orhun/git-cliff-action@v4
103+
- uses: packetcoders/action-setup-cache-python-poetry@a3f2e6ed12462e038bc14270d139e373bf5ac564
104+
- uses: packetcoders/action-setup-cache-python-poetry@v1.1.0
105+
- uses: pdm-project/setup-pdm@483717a073bdef51804a58dac17d043a4183c384
106+
- uses: pdm-project/setup-pdm@v4
107+
- uses: peter-evans/close-issue@1373cadf1f0c96c1420bc000cfba2273ea307fd1
108+
- uses: peter-evans/close-issue@v2
109+
- uses: peter-evans/create-or-update-comment@c9fcb64660bc90ec1cc535646af190c992007c32
110+
- uses: phoenix-actions/test-reporting@f957cd93fc2d848d556fa0d03c57bc79127b6b5e
111+
- uses: phoenix-actions/test-reporting@v15
112+
- uses: pmd/pmd-github-action@967a81f8b657c87f7c3e96b62301cb1a48efef29
113+
- uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd
114+
- uses: pre-commit/action@v3.0.1
115+
- uses: pypa/cibuildwheel@0f04e96e2f58e63b8b03886c1db16a507f2199bf
116+
- uses: pypa/cibuildwheel@v2.12.0
117+
- uses: sbt/setup-sbt@26ab4b0fa1c47fa62fc1f6e51823a658fb6c760c
118+
- uses: scacap/action-surefire-report@1a128e49c0585bc0b8e38e541ac3b6e35a5bc727
119+
- uses: scala-steward-org/scala-steward-action@5021652c555c5724af574758b78ea5be49640007
120+
- uses: scalacenter/sbt-dependency-submission@64084844d2b0a9b6c3765f33acde2fbe3f5ae7d3
121+
- uses: seanmiddleditch/gha-setup-ninja@8b297075da4cd2a5f1fd21fe011b499edf06e9d2
122+
- uses: seanmiddleditch/gha-setup-ninja@v4
123+
- uses: snok/install-poetry@76e04a911780d5b312d89783f7b1cd627778900a
124+
- uses: snok/install-poetry@v1
125+
- uses: untitaker/hyperlink@0.1.21
126+
- uses: untitaker/hyperlink@d277930ba480c61cd3dd1a0caf0d18acfed294a6
127+
- uses: uraimo/run-on-arch-action@ac33288c3728ca72563c97b8b88dda5a65a84448
128+
- uses: uraimo/run-on-arch-action@v2
129+
- uses: vimtor/action-zip@5f1c4aa587ea41db1110df6a99981dbe19cee310
130+
- uses: vimtor/action-zip@v1
131+
- uses: slackapi/slack-github-action@485a9d42d3a73031f12ec201c457e2162c45d02d
132+
- uses: slackapi/slack-github-action@v2.0.0

gateway/test_gateway.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
11
import datetime
22

3+
import filecmp
34
from gateway import *
45

56

7+
def test_load_yaml():
8+
this_dir = os.path.dirname(os.path.realpath(__file__))
9+
parsed = load_yaml(this_dir + "/test_dummy.yml")
10+
comment = parsed['jobs']['dummy']['steps'][3].ca.items['uses'][2].value
11+
assert comment == "# v4.6.8\n"
12+
13+
def test_roundtrip_yaml():
14+
this_dir = os.path.dirname(os.path.realpath(__file__))
15+
infile = this_dir + "/test_dummy.yml"
16+
parsed = load_yaml(infile)
17+
outfile = this_dir + "/test_out_dummy.yml"
18+
write_yaml(outfile, parsed)
19+
assert filecmp.cmp(infile, outfile, shallow=False)
20+
21+
622
def test_update_refs():
723
steps = [
824
{"uses": "actions/setup-go@v5"},
@@ -38,7 +54,7 @@ def test_update_refs():
3854
},
3955
"dorny/paths-filter": {
4056
"0bc4621a3135347011ad047f9ecf449bf72ce2bd": {
41-
"expires_at": calculate_expiry()
57+
"expires_at": calculate_expiry(12)
4258
},
4359
"de90cc6fb38fc0963ad72b210f1f284cd68cea36": {
4460
"expires_at": datetime.date(2100, 1, 1),

stash/restore/test_get_stash.py

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

1515
import unittest
1616
import json
17+
import os
1718

1819
from get_stash import ensure_json, gh_api, jq
1920

@@ -23,7 +24,8 @@ def test_jq(self):
2324
self.assertEqual(jq('{"a": 1}', ".a", ["-j"]).stdout, "1")
2425

2526
def test_jq_file(self):
26-
self.assertEqual(jq("test.json", ".a").stdout, "1\n")
27+
this_dir = os.path.dirname(os.path.realpath(__file__))
28+
self.assertEqual(jq(this_dir + "/test.json", ".a").stdout, "1\n")
2729

2830
def test_jq_error(self):
2931
with self.assertRaises(ValueError):

0 commit comments

Comments
 (0)