Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ABL scripts to use CORGI #2235

Merged
merged 28 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
6fc8934
Add script to parse CORGI ABL; update import tests
TylerZeroMaster Mar 4, 2024
aca375e
Update update-content script to use new transformation
TylerZeroMaster Mar 4, 2024
1e4bb05
Improve test data for validate-abl-import
TylerZeroMaster May 9, 2024
65454d7
Show error if fetching ABL fails
TylerZeroMaster May 9, 2024
57966b0
Update ABL transformation script to read input from files
TylerZeroMaster May 13, 2024
03e584a
Update concourse update-content script
TylerZeroMaster May 13, 2024
a5de2e8
Update existing ABL test data to include configured books object
TylerZeroMaster May 13, 2024
485af50
Test abl output given abl and configured books as input
TylerZeroMaster May 13, 2024
ce42f43
Use some real ABL data for tests
TylerZeroMaster May 13, 2024
0eee5fb
Add additional input validation to abl transformation
TylerZeroMaster May 13, 2024
4367131
Fix compile error caused by jq version difference
TylerZeroMaster May 16, 2024
e3ac1df
Merge branch 'main' into corgi-abl
staxly[bot] Jun 13, 2024
025c7df
Merge branch 'main' into corgi-abl
staxly[bot] Jun 14, 2024
ba7aab9
Merge branch 'main' into corgi-abl
staxly[bot] Jun 14, 2024
bd0f689
Merge branch 'main' into corgi-abl
staxly[bot] Jun 17, 2024
ca1e50c
Merge branch 'main' into corgi-abl
staxly[bot] Jun 26, 2024
898a747
Merge branch 'main' into corgi-abl
staxly[bot] Jun 27, 2024
461bde3
Merge branch 'main' into corgi-abl
staxly[bot] Jun 27, 2024
d000cff
Merge branch 'main' into corgi-abl
staxly[bot] Jun 27, 2024
f31d3fe
Merge branch 'main' into corgi-abl
staxly[bot] Jun 28, 2024
1e31114
Merge branch 'main' into corgi-abl
staxly[bot] Jul 2, 2024
6b45b67
Merge branch 'main' into corgi-abl
staxly[bot] Jul 8, 2024
4120791
Merge branch 'main' into corgi-abl
staxly[bot] Jul 10, 2024
72e6ab4
Merge branch 'main' into corgi-abl
staxly[bot] Jul 10, 2024
9c0251c
Merge branch 'main' into corgi-abl
staxly[bot] Jul 10, 2024
3d0bcb9
Merge branch 'main' into corgi-abl
staxly[bot] Jul 16, 2024
993fee0
Merge branch 'main' into corgi-abl
staxly[bot] Jul 16, 2024
9124b5d
Merge branch 'main' into corgi-abl
staxly[bot] Jul 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions concourse/update-content/script.bash
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,23 @@ fi
# this is here so the creds don't get pasted to the output
set -e; if [ -n "$DEBUG" ]; then set -x; fi

approved_books_default_branch=$(curl -s https://api.github.com/repos/openstax/content-manager-approved-books | jq -r .default_branch)
rex_default_branch=$(curl -s https://api.github.com/repos/openstax/rex-web | jq -r .default_branch)

data=$(curl -sL "https://github.com/openstax/content-manager-approved-books/raw/$approved_books_default_branch/approved-book-list.json")
# consumer: Limit entries to those where consumer == <consumer>
# code_version: Limit entries to those where code_version <= <code_version>
archive_version="$(jq -r '.REACT_APP_ARCHIVE' "src/config.archive-url.json")"
search="consumer=REX&code_version=$archive_version"
abl_url="https://corgi.ce.openstax.org/api/abl/?$search"

# script will return a JSON object with book ids and new versions only for books that doesn't mach current config
book_ids_and_versions=$(node script/entry.js transform-approved-books-data --data "$data")
data="$(curl -sL --fail --show-error "$abl_url")"
configured_books="$(cat src/config.books.json)"

# If there is an error, print it and exit with status 1
echo "$data" | jq '.detail? | halt_error(1)'

book_ids_and_versions="$(
bash script/transform-approved-books-data.bash "$data" "$configured_books"
)"
book_entries=$(echo "$book_ids_and_versions" | jq -c 'to_entries | .[]')

git remote set-branches origin 'update-content-*'
Expand Down
29 changes: 29 additions & 0 deletions script/transform-approved-books-data.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash

set -e

data="$1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not sure it really matters, but this seems like a lot to be putting in the arguments. maybe it could read data from stdin and configured_books from a given file path?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a good point. I originally used inputs like this to separate fetching from transformation and the errors that could occur in each process. I updated the transformation script to read input from 2 files and do some additional checks on the input.

data="${data:?}"
configured_books="$2"
configured_books="${configured_books:?}"

# shellcheck disable=SC2016
new_version_filter='[
# Get the newest version of each book
$corgi_abl | group_by(.uuid) | .[] | sort_by(.commited_at) | .[-1] |

# Store information about the entry (uuid and short sha)
.uuid as $uuid |
(.commit_sha | .[0:7]) as $commit_sha |

# Select entries that do not match configured books
select($configured_books | .[$uuid] | .defaultVersion != $commit_sha) |
{ key: .uuid, value: $commit_sha }
] | from_entries'

jq \
--null-input \
--compact-output \
--argjson configured_books "$configured_books" \
--argjson corgi_abl "$data" \
"$new_version_filter"
314 changes: 0 additions & 314 deletions script/transform-approved-books-data.ts

This file was deleted.

4 changes: 3 additions & 1 deletion script/validate-abl-import/test.bash
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ for input_file in "$my_dir"/*.input.json; do
# Actual test goes here
# -------------------------
json=$(cat "$input_file")
node "$my_dir/../entry.js" transform-approved-books-data --data "$json" > "$output_file"
configured_books="{}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't there be tests that exercise the logic of diffing the books against the existing config?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick review! Yes, that completely slipped my mind. I added some additional test data for this. The smaller of the new data sets demonstrates what occurs when new versions are present, the other uses some real data to demonstrate that there are no new entries when all ABL versions are already present.


bash "$my_dir/../transform-approved-books-data.bash" \
"$json" "$configured_books" > "$output_file"

diff "$snapshot_file" "$output_file"

Expand Down
Loading
Loading