11name : Publish
22
33on :
4- push :
5- branches :
6- - master
7- tags :
8- - " v*"
9- workflow_dispatch :
4+ pull_request :
5+ types : [closed]
6+
7+ permissions :
8+ contents : write
109
1110jobs :
1211 build :
@@ -19,33 +18,64 @@ jobs:
1918 - run : npm install
2019 - run : npm test
2120
22- publish-npm :
23- if : startsWith(github.ref , 'refs/tags/v ')
21+ publish :
22+ if : github.event.pull_request.merged && startsWith(github.event.pull_request.title , 'chore(master): ')
2423 needs : build
2524 runs-on : ubuntu-latest
26-
2725 steps :
2826 - uses : actions/checkout@v3
29- - uses : actions/setup-node@v3
27+ with :
28+ ref : ${{ github.event.pull_request.merge_commit_sha }}
29+ token : ${{ secrets.GITHUB_TOKEN }}
30+ - name : Extract version
31+ id : extract_version
32+ run : |
33+ PR_TITLE="${{ github.event.pull_request.title }}"
34+ VERSION=$(echo "$PR_TITLE" | grep -oP '(?<=release ).*$')
35+ echo "::set-output name=version::$VERSION"
36+ - name : Update versions
37+ run : |
38+ version="${{ steps.extract_version.outputs.version }}"
39+ repo_name="${{ github.repository }}"
40+ repo_name="${repo_name##*/}"
41+
42+ git config user.name github-actions[bot]
43+ git config user.email github-actions[bot]@users.noreply.github.com
44+ git fetch origin master
45+ git checkout master
46+
47+ sed -i "s/\"version\": \"[^\"]*\"/\"version\": \"$version\"/g" package.json
48+ sed -i "s/version = \"[^\"]*\"/version = \"$version\"/g" Cargo.toml
49+ sed -i "s/$repo_name = \"[^\"]*\"/$repo_name = \"$version\"/g" bindings/rust/README.md
50+
51+ git add package.json Cargo.toml bindings/rust/README.md
52+ git commit -m "chore(manifests): bump version to $version"
53+ git push https://${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git HEAD:master
54+ - name : Setup Node.js
55+ uses : actions/setup-node@v3
3056 with :
3157 node-version : 16
3258 registry-url : https://registry.npmjs.org/
33- - run : npm install
3459 - run : npm publish
3560 env :
3661 NODE_AUTH_TOKEN : ${{secrets.NPM_TOKEN}}
37-
38- publish-crates :
39- if : startsWith(github.ref, 'refs/tags/v')
40- needs : build
41- runs-on : ubuntu-latest
42- steps :
43- - uses : actions/checkout@v3
44- - uses : actions-rs/toolchain@v1
62+ - name : Setup Rust
63+ uses : actions-rs/toolchain@v1
4564 with :
4665 profile : minimal
4766 toolchain : stable
4867 override : true
49- - uses : katyo/publish-crates@v2
68+ - name : Publish to Crates.io
69+ uses : katyo/publish-crates@v2
5070 with :
5171 registry-token : ${{ secrets.CARGO_REGISTRY_TOKEN }}
72+ - uses : actions/checkout@v3
73+ - name : Tag stable versions
74+ run : |
75+ git config user.name github-actions[bot]
76+ git config user.email github-actions[bot]@users.noreply.github.com
77+ git remote add gh-token "https://${{ secrets.GITHUB_TOKEN }}@github.com/google-github-actions/release-please-action.git"
78+ git tag -d stable || true
79+ git push origin :stable || true
80+ git tag -a stable -m "Last Stable Release"
81+ git push origin stable
0 commit comments