@@ -22,70 +22,70 @@ jobs:
2222 steps :
2323 - name : Get GitHub App token
2424 id : get_token
25- uses : actions/create-github-app-token@v1
25+ uses : actions/create-github-app-token@c1a285145b9d317df6ced56c09f525b5c2b6f755 # v1.11.1
2626 with :
2727 app-id : ${{ secrets.PIPELINE_GITHUB_APP_ID }}
2828 private-key : ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
2929
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
5232 with :
5333 token : ${{ steps.get_token.outputs.token }}
34+ ref : ${{ github.event.pull_request.base.ref }}
35+ fetch-depth : 0
5436
55- - 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
5643 run : |
57- git config user.name "${GIT_AUTHOR_NAME}"
58- git config user.email "${GIT_AUTHOR_EMAIL}"
44+ CHANGED_VERSION_GO_FILES=$(git diff --diff-filter=MACR --name-only $BASE_SHA...$HEAD_SHA \
45+ | grep -E 'version\.go$' \
46+ | xargs dirname \
47+ | sort \
48+ | uniq)
5949
60- - name : Bump version
61- run : |
62- git switch -c "${POST_RELEASE_BRANCH}"
63- VERSION=$(sed -n 's/const Version = "\(.*\)"/\1/p' version.go | awk -F. '{OFS="."; $NF+=1; print $0 "+dev"}')
64- sed -i 's/".*"/"'$VERSION'"/' version.go
65- git commit -a -m "Post release bump"
66- git push -f --set-upstream origin "${POST_RELEASE_BRANCH}"
67- env :
68- POST_RELEASE_BRANCH : post-${{ github.head_ref }}
50+ declare -A versions
51+ for package in $CHANGED_PACKAGE_JSON_FILES; do
52+ base_version=$(git show $BASE_SHA:$package/version.go | grep "Version =" | sed 's/.*"\(.*\)".*/\1/')
53+ head_version=$(git show $HEAD_SHA:$package/version.go | grep "Version =" | sed 's/.*"\(.*\)".*/\1/')
6954
70- - name : Create PR
71- uses : actions/github-script@v6
72- env :
73- POST_RELEASE_BRANCH : post-${{ github.head_ref }}
74- BASE : master
75- with :
76- github-token : ${{ steps.get_token.outputs.token }}
77- script : |
78- const { data: pr } = await github.rest.pulls.create({
79- owner: context.repo.owner,
80- repo: context.repo.repo,
81- head: process.env.POST_RELEASE_BRANCH,
82- base: process.env.BASE,
83- title: "Post release",
84- body: "Bump to dev version",
85- });
86- await github.rest.issues.addLabels({
87- issue_number: pr.number,
88- owner: context.repo.owner,
89- repo: context.repo.repo,
90- labels: ["changelog/no-changelog"],
91- });
55+ if [ "$base_version" != "$head_version" ]; then
56+ versions[$package]=$head_version
57+ fi
58+ done
59+
60+ for package in "${!versions[@]}"; do
61+ echo "Releasing $package at version ${versions[$package]}"
62+
63+ # Build the tag name
64+ if [[ "$package" == "." ]]; then
65+ # If the package is the root, use the version as the tag name
66+ tag_name="v${versions[$package]}"
67+ else
68+ # If the package is not the root, use the package name and version as the tag name
69+ tag_name="$package/${versions[$package]}"
70+ fi
71+
72+ # Get the changelog entries since last release
73+ # TODO: Implement this
74+ # changelog_content=$(git diff $BASE_REF...$HEAD_REF -- $package/CHANGELOG.md | grep -A 1000 "^+##" | grep -v "^+++" | sed 's/^+//')
75+
76+ is_prerelease=$(echo $package | grep -q "beta" && echo true || echo false)
77+ # Create the tag
78+ gh api repos/{owner}/{repo}/git/refs \
79+ -f ref="refs/tags/$tag_name" \
80+ -f sha=$HEAD_SHA
81+
82+ # Create the release
83+ gh api repos/{owner}/{repo}/releases --input - << EOF
84+ {
85+ "tag_name": "$tag_name",
86+ "name": "$tag_name",
87+ "body": "See $package/CHANGELOG.md for details",
88+ "prerelease": $is_prerelease
89+ }
90+ EOF
91+ done
0 commit comments