Skip to content

Commit c7a3f57

Browse files
authored
update release workflows (#93)
1 parent bdc9048 commit c7a3f57

File tree

5 files changed

+176
-91
lines changed

5 files changed

+176
-91
lines changed

.github/workflows/main.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,3 @@ on:
88
jobs:
99
test:
1010
uses: viamrobotics/viam-typescript-sdk/.github/workflows/test.yml@main
11-
12-
publish:
13-
needs: test
14-
uses: viamrobotics/viam-typescript-sdk/.github/workflows/publish.yml@main
15-
secrets:
16-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/publish.yml

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
name: NPM Publish
22

33
on:
4-
workflow_call:
4+
release:
5+
types: [published]
56
secrets:
67
NPM_TOKEN:
78
required: true
@@ -14,17 +15,44 @@ jobs:
1415
image: ghcr.io/viamrobotics/canon:amd64
1516

1617
steps:
17-
- name: Checkout
18-
uses: actions/checkout@v3
18+
- name: Check if organization member
19+
id: is_organization_member
20+
if: github.event_name == 'workflow_dispatch'
21+
uses: jamessingleton/[email protected]
1922
with:
20-
persist-credentials: false
23+
organization: viamrobotics
24+
username: ${{ github.actor }}
25+
token: ${{ secrets.GITHUB_TOKEN }}
2126

22-
- name: Build
27+
- name: Cancelling - not an organization member
28+
uses: andymckay/[email protected]
29+
if: |
30+
github.event_name == 'workflow_dispatch' && steps.is_organization_member.outputs.result == 'false'
31+
32+
- name: Download Release
33+
uses: dsaltares/fetch-gh-release-asset@master
34+
with:
35+
file: "viamrobotics\\-sdk\\-.*\\.tgz"
36+
regex: true
37+
target: './'
38+
version: tags/${{ github.event.release.tag_name }}
39+
40+
- name: Check Files
41+
id: release_file
42+
run: echo "path=$(ls -1 | head -1)" >> $GITHUB_OUTPUT
43+
44+
- name: Which Tag
45+
id: which_tag
2346
run: |
24-
sudo chown -R testbot .
25-
sudo -u testbot bash -lc 'make build'
47+
if [[ ${{ github.event.release.tag_name }} == *"rc"* ]]; then
48+
echo "tag=rc" >> $GITHUB_OUTPUT
49+
else
50+
echo "tag=latest" >> $GITHUB_OUTPUT
51+
fi
2652
2753
- name: Publish
28-
uses: JS-DevTools/npm-publish@v1
54+
uses: JS-DevTools/npm-publish@v2
2955
with:
3056
token: ${{ secrets.NPM_TOKEN }}
57+
tag: ${{ steps.which_tag.outputs.tag }}
58+
package: ${{ steps.release_file.outputs.path }}

.github/workflows/publish_candidate.yml

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

.github/workflows/release.yml

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,10 @@ name: Release
22

33
on:
44
workflow_dispatch:
5-
inputs:
6-
version:
7-
description: 'The type of version bump. Select "nobump" for no version change. See https://github.com/npm/node-semver#functions'
8-
type: choice
9-
required: true
10-
default: nobump
11-
options:
12-
- major
13-
- minor
14-
- patch
15-
- premajor
16-
- preminor
17-
- prepatch
18-
- prerelease
19-
- nobump # this action is custom for this action and does not exist in npm
205

216
jobs:
227
prepare:
23-
if: github.repository_owner == 'viamrobotics' && github.ref == 'refs/heads/main'
8+
if: github.repository_owner == 'viamrobotics' && startsWith(github.ref, 'rc-')
249
runs-on: [self-hosted, x64]
2510
container:
2611
image: ghcr.io/viamrobotics/canon:amd64
@@ -48,8 +33,7 @@ jobs:
4833
sudo -u testbot bash -lc 'make build lint test'
4934
5035
- name: Bump Version
51-
run: npm version ${{ inputs.version }} --preid=pre --no-git-tag-version
52-
if: inputs.version != 'nobump'
36+
run: npm version ${$(npm pkg get version | sed 's/\"//g')%-rc*} --no-git-tag-version
5337

5438
- name: Which Version
5539
id: which_version
@@ -73,23 +57,23 @@ jobs:
7357
uses: peter-evans/create-pull-request@v5
7458
with:
7559
commit-message: Bump version to ${{ steps.which_version.outputs.version }}
76-
branch: release/${{ steps.which_version.outputs.version }}
60+
branch: rc-${{ steps.which_version.outputs.version }}
7761
delete-branch: true
7862
base: main
7963
title: ${{ steps.which_version.outputs.version }}
8064
body: This is an auto-generated PR to merge the rc branch back into main upon successful release.
8165

8266
build:
8367
needs: prepare
84-
if: github.repository_owner == 'viamrobotics' && github.ref == 'refs/heads/main'
68+
if: github.repository_owner == 'viamrobotics' && startsWith(github.ref, 'rc-')
8569
runs-on: [self-hosted, x64]
8670
container:
8771
image: ghcr.io/viamrobotics/canon:amd64
8872
steps:
8973
- name: Checkout Code
9074
uses: actions/checkout@v3
9175
with:
92-
ref: release/${{ needs.prepare.outputs.version }}
76+
ref: rc-${{ needs.prepare.outputs.version }}
9377

9478
- name: Build + Pack
9579
run: |
@@ -104,7 +88,7 @@ jobs:
10488

10589
release:
10690
needs: [prepare, build]
107-
if: github.repository_owner == 'viamrobotics' && github.ref == 'refs/heads/main'
91+
if: github.repository_owner == 'viamrobotics' && startsWith(github.ref, 'rc-')
10892
runs-on: [self-hosted, x64]
10993
container:
11094
image: ghcr.io/viamrobotics/canon:amd64
@@ -118,6 +102,6 @@ jobs:
118102
tag_name: v${{ needs.prepare.outputs.version }}
119103
files: packed/*
120104
draft: true
121-
prerelease: ${{ contains(inputs.version, 'pre') }}
105+
prerelease: false
122106
fail_on_unmatched_files: true
123-
target_commitish: release/${{ needs.prepare.outputs.version }}
107+
target_commitish: rc-${{ needs.prepare.outputs.version }}
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
name: Publish Release Candidate to NPM
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'The type of version bump. Select "nobump" for no version change. `rc` version bumps will happen automatically, so select the type of version bump for the final release. See https://github.com/npm/node-semver#functions'
8+
type: choice
9+
required: true
10+
default: nobump
11+
options:
12+
- premajor
13+
- preminor
14+
- prepatch
15+
- nobump # this action is custom for this action and does not exist in npm
16+
secrets:
17+
NPM_TOKEN:
18+
required: true
19+
20+
jobs:
21+
prepare:
22+
if: github.repository_owner == 'viamrobotics'
23+
runs-on: [self-hosted, x64]
24+
container:
25+
image: ghcr.io/viamrobotics/canon:amd64
26+
outputs:
27+
rc_version: ${{ steps.which_version.outputs.rc_version }}
28+
version: ${{ steps.which_version.outputs.version }}
29+
steps:
30+
- name: Check if organization member
31+
id: is_organization_member
32+
uses: jamessingleton/[email protected]
33+
with:
34+
organization: viamrobotics
35+
username: ${{ github.actor }}
36+
token: ${{ secrets.GITHUB_TOKEN }}
37+
38+
- name: Cancelling - not an organization member
39+
uses: andymckay/[email protected]
40+
if: steps.is_organization_member.outputs.result == 'false'
41+
42+
- name: Checkout Code
43+
uses: actions/checkout@v3
44+
45+
- name: Build + Lint + Test
46+
run: |
47+
sudo chown -R testbot .
48+
sudo -u testbot bash -lc 'make build lint test'
49+
50+
- name: Bump Version
51+
id: bump_version
52+
run: |
53+
if [[ $(npm pkg get version) == *"rc"* ]]; then
54+
npm version prerelease --preid=rc --no-git-tag-version
55+
else
56+
npm version ${{ inputs.version }} --preid=rc --no-git-tag-version
57+
fi
58+
if: inputs.version != 'nobump'
59+
60+
- name: Which Version
61+
id: which_version
62+
run: |
63+
echo "SDK_RC_VERSION=$(npm pkg get version | sed 's/\"//g')" >> $GITHUB_ENV
64+
echo "SDK_VERSION=${$(npm pkg get version | sed 's/\"//g')%-rc*}" >> $GITHUB_ENV
65+
echo "rc_version=$(npm pkg get version | sed 's/\"//g')" >> $GITHUB_OUTPUT
66+
echo "version=${$(npm pkg get version | sed 's/\"//g')%-rc*}" >> $GITHUB_OUTPUT
67+
68+
- name: Check if release exists
69+
uses: cardinalby/[email protected]
70+
id: release_exists
71+
env:
72+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
73+
with:
74+
releaseName: v${{ steps.which_version.outputs.rc_version }}
75+
doNotFailIfNotFound: 'true'
76+
77+
- name: Cancelling - release already exists
78+
uses: andymckay/[email protected]
79+
if: steps.release_exists.outputs.id != ''
80+
81+
- name: Add + Commit + Open PR
82+
uses: peter-evans/create-pull-request@v5
83+
with:
84+
commit-message: Bump version to ${{ env.RC_SDK_VERSION }}
85+
branch: rc-${{ env.SDK_VERSION }}
86+
delete-branch: false
87+
base: main
88+
title: rc-${{ env.SDK_VERSION }}
89+
body: This is an auto-generated PR to merge the rc branch back into main upon successful release.
90+
91+
build:
92+
needs: prepare
93+
if: github.repository_owner == 'viamrobotics'
94+
runs-on: [self-hosted, x64]
95+
container:
96+
image: ghcr.io/viamrobotics/canon:amd64
97+
steps:
98+
- name: Checkout Code
99+
uses: actions/checkout@v3
100+
with:
101+
ref: rc-${{ needs.prepare.outputs.version }}
102+
103+
- name: Build + Pack
104+
run: |
105+
sudo chown -R testbot .
106+
sudo -u testbot bash -lc 'make build pack'
107+
108+
- name: Upload artifacts
109+
uses: actions/upload-artifact@v3
110+
with:
111+
name: packed
112+
path: viamrobotics-sdk-*.tgz
113+
114+
release:
115+
needs: [prepare, build]
116+
if: github.repository_owner == 'viamrobotics'
117+
runs-on: [self-hosted, x64]
118+
container:
119+
image: ghcr.io/viamrobotics/canon:amd64
120+
121+
steps:
122+
- uses: actions/download-artifact@v3
123+
124+
- name: Release
125+
uses: softprops/action-gh-release@v1
126+
with:
127+
tag_name: v${{ needs.prepare.outputs.rc_version }}
128+
files: dist/*
129+
draft: true
130+
prerelease: true
131+
fail_on_unmatched_files: true
132+
target_commitish: rc-${{ needs.prepare.outputs.version }}

0 commit comments

Comments
 (0)