-
Notifications
You must be signed in to change notification settings - Fork 356
/
Copy pathrelease
executable file
·93 lines (56 loc) · 3.34 KB
/
release
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/sh
# Tag and push a release.
set -e
# check that gh is installed and logged in
gh auth status -h github.com
# Make sure we're in the project root.
cd $(dirname "$0")/..
# Make sure the darn thing works
bundle update
# Build a new gem archive.
rm -rf github-pages-*.gem
gem build -q github-pages.gemspec
# Make sure we're on the master branch.
(git branch | grep -q 'master') || {
echo "Only release from the master branch."
exit 1
}
# Figure out what version we're releasing.
tag=v`ls github-pages-*.gem | sed 's/^github-pages-\(.*\)\.gem$/\1/'`
# Make sure we haven't released this version before.
git fetch -t origin
(git tag -l | grep -q "$tag") && {
echo "Whoops, there's already a '${tag}' tag."
exit 1
}
# Tag it and bag it.
gem push github-pages-*.gem && git tag "$tag" &&
git push origin master && git push origin "$tag"
# create a new release on github
gh release create "$tag" --notes "Automated release for $tag"
# create a tmp folder
mkdir -p tmp
#for each dependent repo, create a new branch an a blank pr.
# first get the sha of main for each repo
gh_pages_sha=`gh api repos/github/pages/git/refs/heads/master | jq '. | .object.sha'`
jekyll_sha=`gh api repos/actions/jekyll-build-pages/git/refs/heads/main | jq '. | .object.sha'`
# then create the branches
gh api repos/github/pages/git/refs -F "sha"="$gh_pages_sha" -F "ref"="refs/heads/pages-gem-release-$tag"
gh api repos/github/pages/git/refs -F "sha"="$jekyll_sha" -F "ref"="refs/heads/pages-gem-release-$tag"
#then we need the tree object so we can create a commit using the api
gh_pages_tree=`gh api repos/github/pages/git/commits/$gh_pages_sha | jq '. | .tree.sha'`
jekyll_tree=`gh api repos/github/actions/jekyll-build-pages/commits/$jekyll_sha | jq '. | .tree.sha'`
# create the input file for the commit. We have to do this because the F flag doesn't support arrays
echo "{\"tree\": \"$gh_pages_tree\", \"parents\": [\"$gh_pages_sha\"], \"message\": \"automated commit for pr creation\"}" > tmp/h_pages_commit_input.json
echo "{\"tree\": \"$jekyll_tree\", \"parents\": [\"$jekyll_sha\"], \"message\": \"automated commit for pr creation\"}" > tmp/jekyll_commit_input.json
# create the commit
new_gh_pages_sha=`gh api repos/github/pages/git/commits --input tmp/gh_pages_commit_input.json | jq '. | .sha'`
new_jekyll_sha=`gh api repos/actions/jekyll-build-pages/git/commits --input tmp/jekyll_commit_input.json | jq '. | .sha'`
# associate the commit with the branch
gh api repos/github/pages/git/refs/heads/pages-gem-release-$tag -F "sha"="$new_gh_pages_sha" -F "ref"="refs/heads/pages-gem-release-$tag" -F "force"="true"
gh api repos/actions/jekyll-build-pages/git/refs/heads/pages-gem-release-$tag -F "sha"="$new_jekyll_sha" -F "ref"="refs/heads/pages-gem-release-$tag" -F "force"="true"
# create pull requests in downstream repos
gh pr create --base "master" --head "pages-gem-release-$tag" --title "Bump pages-gem version to $tag" --assignee "@me" --body "Bump pages-gem version to $tag. You must manually make those changes and commit to this branch" --repo "github/pages"
gh pr create --base "main" --head "pages-gem-release-$tag" --title "Bump pages-gem version to $tag" --assignee "@me" --body "Bump pages-gem version to $tag. You must manually make those changes and commit to this branch" --repo "actions/jekyll-build-pages"
# clean up the input file for the commit
rm tmp/*