Skip to content

Commit

Permalink
update release workflows (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
cheukt authored May 26, 2023
1 parent bdc9048 commit c7a3f57
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 91 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,3 @@ on:
jobs:
test:
uses: viamrobotics/viam-typescript-sdk/.github/workflows/test.yml@main

publish:
needs: test
uses: viamrobotics/viam-typescript-sdk/.github/workflows/publish.yml@main
secrets:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
44 changes: 36 additions & 8 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name: NPM Publish

on:
workflow_call:
release:
types: [published]
secrets:
NPM_TOKEN:
required: true
Expand All @@ -14,17 +15,44 @@ jobs:
image: ghcr.io/viamrobotics/canon:amd64

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Check if organization member
id: is_organization_member
if: github.event_name == 'workflow_dispatch'
uses: jamessingleton/[email protected]
with:
persist-credentials: false
organization: viamrobotics
username: ${{ github.actor }}
token: ${{ secrets.GITHUB_TOKEN }}

- name: Build
- name: Cancelling - not an organization member
uses: andymckay/[email protected]
if: |
github.event_name == 'workflow_dispatch' && steps.is_organization_member.outputs.result == 'false'
- name: Download Release
uses: dsaltares/fetch-gh-release-asset@master
with:
file: "viamrobotics\\-sdk\\-.*\\.tgz"
regex: true
target: './'
version: tags/${{ github.event.release.tag_name }}

- name: Check Files
id: release_file
run: echo "path=$(ls -1 | head -1)" >> $GITHUB_OUTPUT

- name: Which Tag
id: which_tag
run: |
sudo chown -R testbot .
sudo -u testbot bash -lc 'make build'
if [[ ${{ github.event.release.tag_name }} == *"rc"* ]]; then
echo "tag=rc" >> $GITHUB_OUTPUT
else
echo "tag=latest" >> $GITHUB_OUTPUT
fi
- name: Publish
uses: JS-DevTools/npm-publish@v1
uses: JS-DevTools/npm-publish@v2
with:
token: ${{ secrets.NPM_TOKEN }}
tag: ${{ steps.which_tag.outputs.tag }}
package: ${{ steps.release_file.outputs.path }}
53 changes: 0 additions & 53 deletions .github/workflows/publish_candidate.yml

This file was deleted.

32 changes: 8 additions & 24 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,10 @@ name: Release

on:
workflow_dispatch:
inputs:
version:
description: 'The type of version bump. Select "nobump" for no version change. See https://github.com/npm/node-semver#functions'
type: choice
required: true
default: nobump
options:
- major
- minor
- patch
- premajor
- preminor
- prepatch
- prerelease
- nobump # this action is custom for this action and does not exist in npm

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

- name: Which Version
id: which_version
Expand All @@ -73,23 +57,23 @@ jobs:
uses: peter-evans/create-pull-request@v5
with:
commit-message: Bump version to ${{ steps.which_version.outputs.version }}
branch: release/${{ steps.which_version.outputs.version }}
branch: rc-${{ steps.which_version.outputs.version }}
delete-branch: true
base: main
title: ${{ steps.which_version.outputs.version }}
body: This is an auto-generated PR to merge the rc branch back into main upon successful release.

build:
needs: prepare
if: github.repository_owner == 'viamrobotics' && github.ref == 'refs/heads/main'
if: github.repository_owner == 'viamrobotics' && startsWith(github.ref, 'rc-')
runs-on: [self-hosted, x64]
container:
image: ghcr.io/viamrobotics/canon:amd64
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
ref: release/${{ needs.prepare.outputs.version }}
ref: rc-${{ needs.prepare.outputs.version }}

- name: Build + Pack
run: |
Expand All @@ -104,7 +88,7 @@ jobs:

release:
needs: [prepare, build]
if: github.repository_owner == 'viamrobotics' && github.ref == 'refs/heads/main'
if: github.repository_owner == 'viamrobotics' && startsWith(github.ref, 'rc-')
runs-on: [self-hosted, x64]
container:
image: ghcr.io/viamrobotics/canon:amd64
Expand All @@ -118,6 +102,6 @@ jobs:
tag_name: v${{ needs.prepare.outputs.version }}
files: packed/*
draft: true
prerelease: ${{ contains(inputs.version, 'pre') }}
prerelease: false
fail_on_unmatched_files: true
target_commitish: release/${{ needs.prepare.outputs.version }}
target_commitish: rc-${{ needs.prepare.outputs.version }}
132 changes: 132 additions & 0 deletions .github/workflows/release_candidate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
name: Publish Release Candidate to NPM

on:
workflow_dispatch:
inputs:
version:
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'
type: choice
required: true
default: nobump
options:
- premajor
- preminor
- prepatch
- nobump # this action is custom for this action and does not exist in npm
secrets:
NPM_TOKEN:
required: true

jobs:
prepare:
if: github.repository_owner == 'viamrobotics'
runs-on: [self-hosted, x64]
container:
image: ghcr.io/viamrobotics/canon:amd64
outputs:
rc_version: ${{ steps.which_version.outputs.rc_version }}
version: ${{ steps.which_version.outputs.version }}
steps:
- name: Check if organization member
id: is_organization_member
uses: jamessingleton/[email protected]
with:
organization: viamrobotics
username: ${{ github.actor }}
token: ${{ secrets.GITHUB_TOKEN }}

- name: Cancelling - not an organization member
uses: andymckay/[email protected]
if: steps.is_organization_member.outputs.result == 'false'

- name: Checkout Code
uses: actions/checkout@v3

- name: Build + Lint + Test
run: |
sudo chown -R testbot .
sudo -u testbot bash -lc 'make build lint test'
- name: Bump Version
id: bump_version
run: |
if [[ $(npm pkg get version) == *"rc"* ]]; then
npm version prerelease --preid=rc --no-git-tag-version
else
npm version ${{ inputs.version }} --preid=rc --no-git-tag-version
fi
if: inputs.version != 'nobump'

- name: Which Version
id: which_version
run: |
echo "SDK_RC_VERSION=$(npm pkg get version | sed 's/\"//g')" >> $GITHUB_ENV
echo "SDK_VERSION=${$(npm pkg get version | sed 's/\"//g')%-rc*}" >> $GITHUB_ENV
echo "rc_version=$(npm pkg get version | sed 's/\"//g')" >> $GITHUB_OUTPUT
echo "version=${$(npm pkg get version | sed 's/\"//g')%-rc*}" >> $GITHUB_OUTPUT
- name: Check if release exists
uses: cardinalby/[email protected]
id: release_exists
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
releaseName: v${{ steps.which_version.outputs.rc_version }}
doNotFailIfNotFound: 'true'

- name: Cancelling - release already exists
uses: andymckay/[email protected]
if: steps.release_exists.outputs.id != ''

- name: Add + Commit + Open PR
uses: peter-evans/create-pull-request@v5
with:
commit-message: Bump version to ${{ env.RC_SDK_VERSION }}
branch: rc-${{ env.SDK_VERSION }}
delete-branch: false
base: main
title: rc-${{ env.SDK_VERSION }}
body: This is an auto-generated PR to merge the rc branch back into main upon successful release.

build:
needs: prepare
if: github.repository_owner == 'viamrobotics'
runs-on: [self-hosted, x64]
container:
image: ghcr.io/viamrobotics/canon:amd64
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
ref: rc-${{ needs.prepare.outputs.version }}

- name: Build + Pack
run: |
sudo chown -R testbot .
sudo -u testbot bash -lc 'make build pack'
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: packed
path: viamrobotics-sdk-*.tgz

release:
needs: [prepare, build]
if: github.repository_owner == 'viamrobotics'
runs-on: [self-hosted, x64]
container:
image: ghcr.io/viamrobotics/canon:amd64

steps:
- uses: actions/download-artifact@v3

- name: Release
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ needs.prepare.outputs.rc_version }}
files: dist/*
draft: true
prerelease: true
fail_on_unmatched_files: true
target_commitish: rc-${{ needs.prepare.outputs.version }}

0 comments on commit c7a3f57

Please sign in to comment.