-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from trade-tariff/FPO-419-automated-model-runs
FPO-419: Adds automated model build workflow
- Loading branch information
Showing
10 changed files
with
231 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env bash | ||
|
||
[[ "$TRACE" ]] && set -o xtrace | ||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
close_pr() { | ||
gh pr close "$CIRCLE_PULL_REQUEST" | ||
} | ||
|
||
delete_branch() { | ||
git push origin --delete "$CIRCLE_BRANCH" | ||
} | ||
|
||
main() { | ||
.circleci/bin/configuregit | ||
close_pr | ||
delete_branch | ||
} | ||
|
||
main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env bash | ||
|
||
[[ "$TRACE" ]] && set -o xtrace | ||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
git config --global user.email "noreply@trade-tariff.service.gov.uk" | ||
git config --global user.name "trade-tariff-bot" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#!/usr/bin/env bash | ||
|
||
[[ "$TRACE" ]] && set -o xtrace | ||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
EPOCH=$(date +%s) | ||
|
||
update_patch_version() { | ||
local raw_current_version | ||
local current_version | ||
local current_major_version | ||
local current_minor_version | ||
local current_patch_version | ||
local new_patch_version | ||
local new_version | ||
|
||
raw_current_version=$(cat search-config.toml | grep version) | ||
current_version=$(cat search-config.toml | grep version | cut -d= -f2 | tr -d "[:space:]" | tr -d '"') | ||
current_major_version=$(echo $current_version | cut -d. -f1) | ||
current_minor_version=$(echo $current_version | cut -d. -f2) | ||
current_patch_version=$(echo $current_version | cut -d. -f3) | ||
new_patch_version=$((current_patch_version + 1)) | ||
new_version=$(echo "$current_major_version.$current_minor_version.$new_patch_version") | ||
|
||
sed -i "s/$raw_current_version/version = \"$new_version\"/g" search-config.toml | ||
} | ||
|
||
get_branch_name() { | ||
echo "automated-model-run-$EPOCH" | ||
} | ||
|
||
get_model_version() { | ||
echo "$(cat search-config.toml | grep version | cut -d= -f2 | tr -d "[:space:]" | tr -d '"')" | ||
} | ||
|
||
checkout_new_branch() { | ||
git checkout -b "$(get_branch_name)" | ||
} | ||
|
||
stage_commit_and_push_changes() { | ||
git add search-config.toml | ||
git commit -m "BAU: Automated model run $EPOCH." | ||
git push origin "$(get_branch_name)" | ||
} | ||
|
||
open_pr() { | ||
local title | ||
local description | ||
local base_branch="main" | ||
local branch_name | ||
|
||
title="🔄 BAU: Automated model run updated to model version $(get_model_version)" | ||
description=$( | ||
cat <<EOF | ||
# Automated Model Run ${EPOCH} | ||
🚀 **What's happening?** | ||
This automated model run has been initiated to incorporate any new data added to the model via the training pipeline's dynamic data sources. | ||
🔔 **Note:** | ||
This pull request will be **closed automatically** once the model run is complete. | ||
Thank you for your patience! 🙌 | ||
EOF | ||
) | ||
branch_name=$(get_branch_name) | ||
|
||
gh pr create --title "$title" --body "$description" --base "$base_branch" --head "$branch_name" | ||
} | ||
|
||
tag_branch() { | ||
local tag_name | ||
local tag_description | ||
|
||
tag_name=$(get_branch_name)-$(get_model_version) | ||
tag_description="BAU: Automated model run bumping model to $(get_model_version) on $EPOCH." | ||
|
||
git tag -a $tag_name -m "$tag_description" | ||
git push origin $tag_name | ||
} | ||
|
||
main() { | ||
.circleci/bin/configuregit | ||
update_patch_version | ||
checkout_new_branch | ||
stage_commit_and_push_changes | ||
open_pr | ||
tag_branch | ||
} | ||
|
||
main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
sudo apt-get install dirmngr | ||
|
||
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo gpg --dearmor -o /usr/share/keyrings/githubcli-archive-keyring.gpg | ||
|
||
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null | ||
|
||
sudo apt update | ||
sudo apt install gh | ||
|
||
if [ -z "${GITHUB_TOKEN:-}" ]; then | ||
echo "GITHUB_TOKEN is not set" | ||
exit 1 | ||
fi | ||
|
||
echo "${GITHUB_TOKEN}" | env -u GITHUB_TOKEN gh auth login --with-token --hostname github.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
set -o noclobber | ||
|
||
get_current_head_tags() { | ||
git tag --points-at HEAD | ||
} | ||
|
||
is_automated_build() { | ||
if [[ "$(get_current_head_tags)" == *"automated-model-run"* ]]; then | ||
return 0 | ||
else | ||
return 1 | ||
fi | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env bash | ||
|
||
[[ "$TRACE" ]] && set -o xtrace | ||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
source .circleci/bin/isautomatedbuild | ||
|
||
merge_pr() { | ||
gh pr merge "$CIRCLE_PULL_REQUEST" | ||
} | ||
|
||
main() { | ||
.circleci/bin/configuregit | ||
|
||
if is_automated_build; then | ||
echo "Automated build, merging PR" | ||
|
||
merge_pr | ||
fi | ||
} | ||
|
||
main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
aws-lambda-powertools==2.28.1 | ||
jmespath==1.0.1 | ||
lingua-language-detector==2.0.2 | ||
sentence-transformers==2.2.2 | ||
sentence-transformers==2.6.1 | ||
sentry-sdk==2.8.0 | ||
toml==0.10.2 |