|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# Open pull request with release notes against sssd.io |
| 4 | + |
| 5 | +set -e -o pipefail |
| 6 | + |
| 7 | +# Usage |
| 8 | +if [ "$#" -ne 4 ]; then |
| 9 | + echo "Usage: $0 <version> <path-to-rn> <fork-user> <fork-token>" >&2 |
| 10 | + exit 1 |
| 11 | +fi |
| 12 | + |
| 13 | +# Create working directory |
| 14 | +scriptdir=`realpath \`dirname "$0"\`` |
| 15 | +wd=`mktemp -d` |
| 16 | +trap 'rm -rf "$wd"' EXIT |
| 17 | + |
| 18 | +# Initial setup |
| 19 | +VERSION=$1 |
| 20 | +PATH_TO_RN=$2 |
| 21 | +FORK_USER=$3 |
| 22 | +FORK_TOKEN=$4 |
| 23 | + |
| 24 | +GITHUB_REPOSITORY="SSSD/sssd.io" |
| 25 | +OWNER=`echo "$GITHUB_REPOSITORY" | cut -d / -f 1` |
| 26 | +REPOSITORY=`echo "$GITHUB_REPOSITORY" | cut -d / -f 2` |
| 27 | +TARGET="master" |
| 28 | +RN_BRANCH_NAME="$OWNER-$REPOSITORY-relnotes-$VERSION" |
| 29 | + |
| 30 | +echo "GitHub Repository: $OWNER/$REPOSITORY" |
| 31 | +echo "Target Branch: $TARGET" |
| 32 | +echo "Release Notes Branch: $RN_BRANCH_NAME" |
| 33 | +echo "" |
| 34 | +echo "Action Directory: $scriptdir" |
| 35 | +echo "Working Directory: $wd" |
| 36 | +echo "" |
| 37 | + |
| 38 | +pushd "$wd" |
| 39 | +set -x |
| 40 | + |
| 41 | +# Login with token to GitHub CLI, GH_TOKEN variable is used in GitHub Actions |
| 42 | +set +x |
| 43 | +if [ -z "$GH_TOKEN" ]; then |
| 44 | + echo $FORK_TOKEN > .token |
| 45 | + gh auth login --with-token < .token |
| 46 | + rm -f .token |
| 47 | +fi |
| 48 | +set -x |
| 49 | + |
| 50 | +# Clone repository and fetch the pull request |
| 51 | +git clone "https://github.com/$OWNER/$REPOSITORY.git" . |
| 52 | +git remote add "$FORK_USER" "https://$FORK_USER:$FORK_TOKEN@github.com/$FORK_USER/$REPOSITORY.git" |
| 53 | +git checkout "$TARGET" |
| 54 | +gh repo set-default "$GITHUB_REPOSITORY" |
| 55 | + |
| 56 | +# Create new branch that we will work on |
| 57 | +git checkout -b "$RN_BRANCH_NAME" "$TARGET" |
| 58 | + |
| 59 | +# Copy release notes and update releases.rst |
| 60 | +# Insert new release before the first occurrence of ".. release::" |
| 61 | +cp -f "$PATH_TO_RN" "./src/release-notes/sssd-$VERSION.rst" |
| 62 | +TODAY=$(date +%Y-%m-%d) |
| 63 | +RELEASES_FILE="./src/releases.rst" |
| 64 | +NEW_RELEASE=$(cat <<EOF |
| 65 | + .. release:: sssd-$VERSION |
| 66 | + :date: $TODAY |
| 67 | + :download: https://github.com/SSSD/sssd/releases/tag/$VERSION |
| 68 | +EOF |
| 69 | +) |
| 70 | + |
| 71 | +awk -i inplace -v new="$NEW_RELEASE" \ |
| 72 | + '/^[[:space:]]*\.\. release::/ && !done {print new "\n"; done=1} {print}' \ |
| 73 | + "$RELEASES_FILE" |
| 74 | + |
| 75 | +# Commit changes |
| 76 | +git add --all |
| 77 | +git commit -S -a -m "Release sssd-$VERSION" |
| 78 | + |
| 79 | +# Push backport to remote |
| 80 | +git push --set-upstream "$FORK_USER" "$RN_BRANCH_NAME" --force |
| 81 | + |
| 82 | +# Prepare pull request message |
| 83 | +BODY_FILE="/tmp/relnotes-message" |
| 84 | +cat > "$BODY_FILE" <<EOF |
| 85 | +These are automatically generated release notes for sssd-$VERSION. |
| 86 | +
|
| 87 | +Please review and edit the notes before merging. |
| 88 | +
|
| 89 | +**You can push changes to this pull request** |
| 90 | +
|
| 91 | +\`\`\` |
| 92 | +git remote add $FORK_USER git@github.com:$FORK_USER/$REPOSITORY.git |
| 93 | +git fetch $FORK_USER refs/heads/$RN_BRANCH_NAME |
| 94 | +git checkout $RN_BRANCH_NAME |
| 95 | +git push $FORK_USER $RN_BRANCH_NAME --force |
| 96 | +\`\`\` |
| 97 | +EOF |
| 98 | + |
| 99 | +gh pr create \ |
| 100 | + --draft \ |
| 101 | + --base "$TARGET" \ |
| 102 | + --body-file "$BODY_FILE" \ |
| 103 | + --head "$FORK_USER:$RN_BRANCH_NAME" \ |
| 104 | + --title "Release sssd-$VERSION" |
0 commit comments