File: update-distribution-scripts.sh

package info (click to toggle)
crystal 1.14.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 24,384 kB
  • sloc: javascript: 6,400; sh: 695; makefile: 269; ansic: 121; python: 105; cpp: 77; xml: 32
file content (60 lines) | stat: -rwxr-xr-x 2,039 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env sh
#
# This helper updates the reference of [distribution-scripts](https://github.com/crystal-lang/distribution-scripts),
# pushes the change to GitHub and creates a pull request.
#
# Usage:
#
#    scripts/update-distribution_scripts.sh [REF [BRANCH]]
#
# Parameters:
# * REF: Git commit SHA in distribution-scripts (default: HEAD)
# * BRANCH: Branch name for CI branch in crystal (default: ci/update-distribution-scripts)
#
# Requirements:
# * packages: git gh sed
# * Working directory should be in a checked out work tree of `crystal-lang/crystal`.
#
# * The default value for reference is the current HEAD of https://github.com/crystal-lang/distribution-scripts.

set -eu

DISTRIBUTION_SCRIPTS_WORK_DIR=${DISTRIBUTION_SCRIPTS_WORK_DIR:-../distribution-scripts/.git}
GIT_DS="git --git-dir=$DISTRIBUTION_SCRIPTS_WORK_DIR"

$GIT_DS fetch origin master

if [ "${1:-"HEAD"}" = "HEAD" ]; then
  reference=$($GIT_DS rev-list origin/master | head -1)
else
  reference=${1}
fi

branch="${2:-"ci/update-distribution-scripts"}"

git switch -C "$branch" master

old_reference=$(sed -n "/distribution-scripts-version:/{n;n;n;p}" .circleci/config.yml | grep -o -P '(?<=default: ")[^"]+')
echo $old_reference..$reference

sed -i -E "/distribution-scripts-version:/{n;n;n;s/default: \".*\"/default: \"$reference\"/}" .circleci/config.yml

git add .circleci/config.yml

message="Updates \`distribution-scripts\` dependency to https://github.com/crystal-lang/distribution-scripts/commit/$reference"
log=$($GIT_DS log $old_reference..$reference --format="%s" | sed "s/.*(/crystal-lang\/distribution-scripts/;s/^/* /;s/)$//")
message=$(printf "%s\n\nThis includes the following changes:\n\n%s" "$message" "$log")

git commit -m "Update distribution-scripts" -m "$message"

git show

git push -u upstream "$branch"

# Confirm creating pull request
echo "Create pull request for branch $branch? [y/N]"
read -r REPLY

if [ "$REPLY" = "y" ]; then
  gh pr create -R crystal-lang/crystal --fill --label "topic:infrastructure" --assignee "@me"
fi