@@ -22,75 +22,71 @@ jobs:
22
22
steps :
23
23
- name : Get GitHub App token
24
24
id : get_token
25
- uses : actions/create-github-app-token@v1
25
+ uses : actions/create-github-app-token@c1a285145b9d317df6ced56c09f525b5c2b6f755 # v1.11.1
26
26
with :
27
27
app-id : ${{ secrets.PIPELINE_GITHUB_APP_ID }}
28
28
private-key : ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
29
29
30
- - name : Create release
31
- uses : actions/github-script@v6
32
- env :
33
- RELEASE_BRANCH : ${{ github.head_ref }}
34
- with :
35
- github-token : ${{ steps.get_token.outputs.token }}
36
- script : |
37
- const tagName = `v${process.env.RELEASE_BRANCH.split("/")[1]}`;
38
- await github.rest.git.createRef({
39
- owner: context.repo.owner,
40
- repo: context.repo.repo,
41
- ref: `refs/tags/${tagName}`,
42
- sha: context.payload.pull_request.merge_commit_sha,
43
- });
44
- await github.rest.repos.createRelease({
45
- owner: context.repo.owner,
46
- repo: context.repo.repo,
47
- generate_release_notes: true,
48
- tag_name: tagName,
49
- });
50
-
51
- - uses : actions/checkout@v3
30
+ - name : Checkout ${{ github.event.pull_request.base.ref }}
31
+ uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
52
32
with :
53
- fetch-depth : 0
54
33
token : ${{ steps.get_token.outputs.token }}
34
+ ref : ${{ github.event.pull_request.base.ref }}
35
+ fetch-depth : 0
55
36
56
- - name : Setup Git
37
+ - name : Release packages
38
+ env :
39
+ HEAD_SHA : ${{ github.event.pull_request.head.sha }}
40
+ BASE_SHA : ${{ github.event.pull_request.base.sha }}
41
+ GH_TOKEN : ${{ steps.get_token.outputs.token }}
42
+ shell : bash
57
43
run : |
58
- git config user.name "${GIT_AUTHOR_NAME}"
59
- git config user.email "${GIT_AUTHOR_EMAIL}"
44
+ CHANGED_VERSION_RB_FILES=$(git diff --diff-filter=MACR --name-only $BASE_SHA...$HEAD_SHA \
45
+ | grep -E 'version\.rb$' \
46
+ | xargs dirname | xargs dirname | xargs dirname \
47
+ | sort \
48
+ | uniq)
60
49
61
- - name : Set up Ruby 2.7
62
- uses : ruby/setup-ruby@v1
63
- with :
64
- ruby-version : 2.7
50
+ declare -A versions
51
+ for package in $CHANGED_VERSION_RB_FILES; do
52
+ version_dir=$(find $package/lib/*/version.rb -name "version.rb" | head -n 1)
53
+ base_version=$(git show $BASE_SHA:$version_dir | grep "VERSION =" | sed "s/.*'\(.*\)'.*/\1/")
54
+ head_version=$(git show $HEAD_SHA:$version_dir | grep "VERSION =" | sed "s/.*'\(.*\)'.*/\1/")
65
55
66
- - name : Bump Gem version
67
- run : |
68
- git switch -c "${POST_RELEASE_BRANCH}"
69
- bundle install
70
- bundle exec gem bump -v dev
71
- git push -f --set-upstream origin "${POST_RELEASE_BRANCH}"
72
- env :
73
- POST_RELEASE_BRANCH : post-${{ github.head_ref }}
56
+ if [ "$base_version" != "$head_version" ]; then
57
+ versions[$package]=$head_version
58
+ fi
59
+ done
74
60
75
- - name : Create PR
76
- uses : actions/github-script@v6
77
- env :
78
- POST_RELEASE_BRANCH : post-${{ github.head_ref }}
79
- BASE : master
80
- with :
81
- github-token : ${{ steps.get_token.outputs.token }}
82
- script : |
83
- const { data: pr } = await github.rest.pulls.create({
84
- owner: context.repo.owner,
85
- repo: context.repo.repo,
86
- head: process.env.POST_RELEASE_BRANCH,
87
- base: process.env.BASE,
88
- title: "Post release",
89
- body: "Bump to dev version",
90
- });
91
- await github.rest.issues.addLabels({
92
- issue_number: pr.number,
93
- owner: context.repo.owner,
94
- repo: context.repo.repo,
95
- labels: ["changelog/no-changelog"],
96
- });
61
+ for package in "${!versions[@]}"; do
62
+ echo "Releasing $package at version ${versions[$package]}"
63
+
64
+ # Build the tag name
65
+ if [[ "$package" == "." ]]; then
66
+ # If the package is the root, use the version as the tag name
67
+ tag_name="v${versions[$package]}"
68
+ else
69
+ # If the package is not the root, use the package name and version as the tag name
70
+ tag_name="$package/${versions[$package]}"
71
+ fi
72
+
73
+ # Get the changelog entries since last release
74
+ # TODO: Implement this
75
+ # changelog_content=$(git diff $BASE_REF...$HEAD_REF -- $package/CHANGELOG.md | grep -A 1000 "^+##" | grep -v "^+++" | sed 's/^+//')
76
+
77
+ is_prerelease=$(echo $package | grep -q "beta" && echo true || echo false)
78
+ # Create the tag
79
+ gh api repos/{owner}/{repo}/git/refs \
80
+ -f ref="refs/tags/$tag_name" \
81
+ -f sha=$HEAD_SHA
82
+
83
+ # Create the release
84
+ gh api repos/{owner}/{repo}/releases --input - << EOF
85
+ {
86
+ "tag_name": "$tag_name",
87
+ "name": "$tag_name",
88
+ "body": "See $package/CHANGELOG.md for details",
89
+ "prerelease": $is_prerelease
90
+ }
91
+ EOF
92
+ done
0 commit comments