Skip to content
Closed
Changes from all commits
Commits
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
25 changes: 18 additions & 7 deletions scripts/write-config-to-target-artefact.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#! /bin/bash

VERSION=$(gh pr view $TARGET_PR -c --json comments -q "[.comments[] | select(.author.login == \"gu-scala-library-release\")][-1].body" | grep "\-PREVIEW")

if [[ -z "$VERSION" ]]; then
Expand All @@ -15,36 +17,45 @@ echo "Found version: $VERSION"

set -e

PR_DETAILS=$(gh pr view $TARGET_PR --json number,headRepository)
PULL_REQUEST_SLUG=$(gh pr view "$TARGET_PR" --json url | jq -r ".url" | cut -d/ -f 4-)
REPO_ID=$(echo "$PULL_REQUEST_SLUG" | cut -d/ -f -2)

TAG_URL=$(gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/guardian/redirect-resolver/git/ref/tags/v$VERSION \
"/repos/$REPO_ID/git/ref/tags/v$VERSION" \
-q ".object.url" | sed "s/https:\/\/api.github.com\///")

echo "Tag url: $TAG_URL"

ARTIFACT_PATH=$(gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
$TAG_URL \
-q ".message" | grep ".pom$" | head -n 1 | cut -d" " -f3)

echo "Artifact path: $ARTIFACT_PATH"

POM=$(curl https://repo1.maven.org/maven2/$(echo $ARTIFACT_PATH | cut -d" " -f1))

echo "POM ... is large"

GROUP_ID=$(echo $POM | xq -x /project/groupId)
ARTIFACT_ID=$(echo $POM | xq -x /project/artifactId | rev | cut -d"_" -f2- | rev)
TARGET_ARTIFACT="$GROUP_ID:$ARTIFACT_ID:$VERSION"
GROUPING_NAME=$(gh pr view $TARGET_PR --json url | jq -r ".url" | cut -d/ -f 4-)


echo "Grouping name: $PULL_REQUEST_SLUG"

cat << EOF > targeted-scala-steward.conf
updates.allow = [{ groupId = "$GROUP_ID", artifactId = "$ARTIFACT_ID", version = "$VERSION" }]
commits.message = "[TEST - please ignore]: Update \${artifactName} from \${currentVersion} to \${nextVersion}"
commits.message = "Update \${artifactName} from \${currentVersion} to \${nextVersion}"
pullRequests.draft = true
pullRequests.grouping = [{
name = "$GROUPING_NAME",
title = "[TEST - please ignore]: Update $TARGET_ARTIFACT",
name = "$PULL_REQUEST_SLUG",
title = "Update \`$GROUP_ID:$ARTIFACT_ID\` to \`$VERSION\`",
filter = [{"group" = "*"}]
}]
pullRequests.customLabels = ["targeted-update"]
updates.allowPreReleases = [{ groupId = "$GROUP_ID" }]
EOF
cat targeted-scala-steward.conf