Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
rcdailey committed Oct 1, 2023
1 parent a482538 commit 54d6c69
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 1 deletion.
21 changes: 21 additions & 0 deletions .github/workflows/check-trash-ids.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Check Trash IDs

on:
pull_request:

jobs:
check_trash_ids:
name: Check Trash IDs
runs-on: ubuntu-latest
steps:
- name: Checkout Config Repo
uses: actions/checkout@v3

- name: Checkout Trash Repo
uses: actions/checkout@v3
with:
repository: TRaSH-Guides/Guides
path: trash

- name: Check Trash IDs
run: pwsh ci/CheckInvalidTrashIds.ps1 trash .
62 changes: 62 additions & 0 deletions ci/CheckInvalidTrashIds.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string[]] $PathToTrashRepo,

[Parameter(Mandatory = $true)]
[string] $PathToConfigRepo
)

$exitCode = 0

function GetTrashIds($path) {
return Get-ChildItem -Recurse $path -Include "*.json"
| Get-Content -Raw
| ConvertFrom-Json
| Select-Object -ExpandProperty trash_id
}

function OutputError($file, $line, $message) {
$errorDetails = $(
"file=$file"
"line=$line"
"title=Trash ID Validation Failure"
)

"::error $($errorDetails -join ',')::$message"
$script:exitCode = 1
}

function CheckTrashIdCorrect($yamlDir, $shouldBeIn, $shouldNotBeIn) {
$yamlFiles = Get-ChildItem -Recurse "$yamlDir" -Include "*.yml"

foreach ($file in $yamlFiles) {
"Processing $file"
$lines = Get-Content $file

for ($i = 0; $i -lt $lines.Count; $i++) {
$match = $lines[$i] | Select-String -Pattern ' +- ([a-z0-9]+) +# +.+'
if (-not $match.Matches.Success) {
continue
}

$trashId = $match.Matches.Groups[1]
$lineNumber = $i + 1

if ($trashId -in $shouldNotBeIn) {
OutputError $file $lineNumber "$trashId is from the wrong service"
}
elseif ($trashId -notin $shouldBeIn) {
OutputError $file $lineNumber "$trashId is not in the guide"
}
}
}
}

$radarrTrashIds = GetTrashIds "$PathToTrashRepo/docs/json/radarr/cf"
$sonarrTrashIds = GetTrashIds "$PathToTrashRepo/docs/json/sonarr/cf"

CheckTrashIdCorrect "$PathToConfigRepo/sonarr" $sonarrTrashIds $radarrTrashIds
CheckTrashIdCorrect "$PathToConfigRepo/radarr" $radarrTrashIds $sonarrTrashIds

exit $exitCode
10 changes: 10 additions & 0 deletions pull-request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"pull_request": {
"head": {
"ref": "validate-dates"
},
"base": {
"ref": "master"
}
}
}
2 changes: 1 addition & 1 deletion sonarr/templates/french-web-2160p-multi-v4.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ sonarr:
- 1f733af03141f068a540eec352589a89 # DV HLG
- 27954b0a80aab882522a88a4d9eae1cd # DV SDR
- a3d82cbef5039f8d295478d28a887159 # HDR10+
- 3497799d29a085e2ac2df9d468413c94 # HDR10
- 3497799d29a085e2acz2df9d468413c94 # HDR10

Check failure on line 38 in sonarr/templates/french-web-2160p-multi-v4.yml

View workflow job for this annotation

GitHub Actions / Check Trash IDs

Trash ID Validation Failure

3497799d29a085e2acz2df9d468413c94 is not in the guide
- 3e2c4e748b64a1a1118e0ea3f4cf6875 # HDR
- bb019e1cd00f304f80971c965de064dc # HDR (undefined)
- 2a7e3be05d3861d6df7171ec74cad727 # PQ
Expand Down

0 comments on commit 54d6c69

Please sign in to comment.