Skip to content

Commit ed199c3

Browse files
committed
Add new release workflow
1 parent 88999b1 commit ed199c3

File tree

5 files changed

+86
-237
lines changed

5 files changed

+86
-237
lines changed

.github/workflows/prepare_release.yml

Lines changed: 0 additions & 113 deletions
This file was deleted.

.github/workflows/prerelease.yml

Lines changed: 0 additions & 21 deletions
This file was deleted.

.github/workflows/publish.yml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,36 @@ permissions:
55

66
on:
77
release:
8-
types: [released]
8+
types:
9+
- prereleased
10+
- released
911
jobs:
1012
build:
1113
runs-on: ubuntu-latest
1214
steps:
13-
- uses: actions/checkout@v3
15+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
16+
with:
17+
fetch-depth: 1
1418
- uses: actions/setup-node@v3
1519
with:
16-
node-version: 16
20+
node-version: 18
1721
- run: yarn
18-
- run: yarn publish --tag=latest
22+
- run: |
23+
# Get tag name from event
24+
tag_name="${{ github.event.release.tag_name }}"
25+
26+
cmd="yarn publish"
27+
if [ "${{ github.event.release.prerelease }}" == "true" ]; then
28+
cmd+=" --tag=beta"
29+
else
30+
cmd+=" --tag=latest"
31+
fi
32+
33+
if [[ "$tag_name" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
34+
eval $cmd
35+
else
36+
cd $(echo $tag_name | rev | cut -d'/' -f2- | rev)
37+
eval $cmd
38+
fi
1939
env:
2040
NPM_AUTH_TOKEN: ${{ secrets.YARN_NPM_AUTH_TOKEN }}

.github/workflows/release.yml

Lines changed: 62 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ on:
1313
types: [closed]
1414
branches:
1515
- master
16+
- v2
1617

1718
jobs:
1819
create_release:
@@ -22,77 +23,77 @@ jobs:
2223
steps:
2324
- name: Get GitHub App token
2425
id: get_token
25-
uses: actions/create-github-app-token@v1
26+
uses: actions/create-github-app-token@c1a285145b9d317df6ced56c09f525b5c2b6f755 #v1.11.1
2627
with:
2728
app-id: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
2829
private-key: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
2930

30-
- name: Create release
31-
uses: actions/github-script@v6
32-
env:
33-
RELEASE_BRANCH: ${{ github.head_ref }}
31+
- name: Checkout ${{ github.base_ref }}
32+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3433
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-
});
34+
fetch-depth: 1
35+
token: ${{ steps.get_token.outputs.token }}
36+
ref: ${{ github.event.pull_request.base.ref }}
5037

51-
- uses: actions/checkout@v3
38+
- name: Checkout ${{ github.head_ref }}
39+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
5240
with:
53-
fetch-depth: 0
41+
fetch-depth: 1
5442
token: ${{ steps.get_token.outputs.token }}
43+
ref: ${{ github.event.pull_request.head.ref }}
5544

56-
- name: Setup Git
45+
- name: Release packages
46+
env:
47+
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
48+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
49+
GH_TOKEN: ${{ steps.get_token.outputs.token }}
50+
shell: bash
5751
run: |
58-
git config user.name "${GIT_AUTHOR_NAME}"
59-
git config user.email "${GIT_AUTHOR_EMAIL}"
52+
CHANGED_PACKAGE_JSON_FILES=$(git diff --name-only $BASE_SHA...$HEAD_SHA \
53+
| grep -E 'package\.json$' \
54+
| xargs dirname \
55+
| sort \
56+
| uniq)
6057
61-
- name: Set up Node
62-
uses: actions/setup-node@v3
63-
with:
64-
node-version: 16
65-
cache: 'yarn'
58+
declare -A versions
59+
for package in $CHANGED_PACKAGE_JSON_FILES; do
60+
base_version=$(git show $BASE_SHA:$package/package.json | jq -r .version)
61+
head_version=$(git show $HEAD_SHA:$package/package.json | jq -r .version)
6662
67-
- name: Bump version
68-
run: |
69-
git switch -c "${POST_RELEASE_BRANCH}"
70-
# TODO remove beta after 1.0.0 release
71-
npm version --no-git-tag-version --preid beta prerelease
72-
git commit -a -m "Bump version"
73-
git push -f --set-upstream origin "${POST_RELEASE_BRANCH}"
74-
env:
75-
POST_RELEASE_BRANCH: post-${{ github.head_ref }}
63+
if [ "$base_version" != "$head_version" ]; then
64+
versions[$package]=$head_version
65+
fi
66+
done
7667
77-
- name: Create PR
78-
uses: actions/github-script@v6
79-
env:
80-
POST_RELEASE_BRANCH: post-${{ github.head_ref }}
81-
BASE: master
82-
with:
83-
github-token: ${{ steps.get_token.outputs.token }}
84-
script: |
85-
const { data: pr } = await github.rest.pulls.create({
86-
owner: context.repo.owner,
87-
repo: context.repo.repo,
88-
head: process.env.POST_RELEASE_BRANCH,
89-
base: process.env.BASE,
90-
title: "Post release",
91-
body: "Bump to dev version",
92-
});
93-
await github.rest.issues.addLabels({
94-
issue_number: pr.number,
95-
owner: context.repo.owner,
96-
repo: context.repo.repo,
97-
labels: ["changelog/no-changelog"],
98-
});
68+
for package in "${!versions[@]}"; do
69+
echo "Releasing $package at version ${versions[$package]}"
70+
71+
# Build the tag name
72+
if [[ "$package" == "." ]]; then
73+
# If the package is the root, use the version as the tag name
74+
tag_name="v${versions[$package]}"
75+
else
76+
# If the package is not the root, use the package name and version as the tag name
77+
tag_name="$package/${versions[$package]}"
78+
fi
79+
80+
# Get the changelog entries since last release
81+
# TODO: Implement this
82+
# changelog_content=$(git diff $BASE_REF...$HEAD_REF -- $package/CHANGELOG.md | grep -A 1000 "^+##" | grep -v "^+++" | sed 's/^+//')
83+
84+
is_prerelease=$(echo $package | grep -q "beta" && echo true || echo false)
85+
# Create the tag
86+
gh api repos/{owner}/{repo}/git/refs \
87+
-f ref="refs/tags/$tag_name" \
88+
-f sha=$HEAD_SHA
89+
90+
# Create the release
91+
gh api repos/{owner}/{repo}/releases --input - << EOF
92+
{
93+
"tag_name": "$tag_name",
94+
"name": "$tag_name",
95+
"body": "See $package/CHANGELOG.md for details",
96+
"prerelease": $is_prerelease
97+
}
98+
EOF
99+
done

RELEASING.md

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)