chore(changesets): version packages #124
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CD | |
on: | |
push: | |
branches: | |
- main | |
concurrency: ${{ github.workflow }}-${{ github.ref }} | |
jobs: | |
release: | |
# don't run on forks | |
if: ${{ github.repository_owner == 'SmartThingsCommunity' }} | |
name: Release | |
runs-on: ubuntu-latest | |
outputs: | |
cli-released: ${{ steps.cli-release.outputs.published }} | |
cli-version: ${{ steps.cli-metadata.outputs.version }} | |
cli-tag: ${{ steps.cli-metadata.outputs.tag }} | |
steps: | |
- name: Checkout Repo | |
uses: actions/checkout@v3 | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 18.5.0 | |
- name: Install Dependencies | |
run: npm ci | |
- name: Create Release Pull Request or Publish to npm | |
id: changesets | |
uses: changesets/action@v1 | |
with: | |
version: npm run version | |
publish: npm run release | |
commit: "chore(changesets): version packages" | |
title: "chore(changesets): version packages" | |
createGithubReleases: false | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | |
# decouple Github Release from library-only publishing | |
- name: Check if CLI Published | |
id: cli-release | |
run: echo "published=$(echo '${{ steps.changesets.outputs.publishedPackages }}' | jq 'any(.name == "@smartthings/cli")')" >> $GITHUB_OUTPUT | |
- name: Derive Required Metadata | |
id: cli-metadata | |
if: steps.cli-release.outputs.published == 'true' | |
run: | # derive latest info from changesets output | |
PUBLISHED_PACKAGE=$(echo '${{ steps.changesets.outputs.publishedPackages }}' | jq 'map(select(.name == "@smartthings/cli")) | .[]') | |
echo "tag=$(echo $PUBLISHED_PACKAGE | jq --raw-output '.name + "@" + .version')" >> $GITHUB_OUTPUT | |
echo "version=$(echo $PUBLISHED_PACKAGE | jq --raw-output '.version')" >> $GITHUB_OUTPUT | |
package: | |
name: Package CLI | |
runs-on: ubuntu-latest | |
steps: | |
- name: Install and Setup QEMU | |
run: | | |
sudo apt-get update | |
sudo apt-get install qemu binfmt-support qemu-user-static | |
# see https://github.com/vercel/pkg/issues/1251#issuecomment-1024832725 | |
- name: Download and Install ldid Codesign Utility | |
run: | | |
wget https://github.com/jesec/ldid-static/releases/download/v2.1.4/ldid-amd64 | |
chmod +x ldid-amd64 | |
sudo mv ldid-amd64 /usr/local/bin/ldid | |
- name: Checkout Repo | |
uses: actions/checkout@v3 | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 18.5.0 | |
- run: npm ci | |
- run: npm run build | |
- name: Package CLI | |
run: npm run package | |
# maintain executable file permissions | |
# see https://github.com/actions/upload-artifact/issues/38 | |
- name: Tar files | |
run: tar -cvf dist_bin.tar packages/cli/dist_bin/ | |
- name: Upload Artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: dist_bin | |
path: dist_bin.tar | |
functional-test: | |
needs: package | |
name: Functional Tests | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [ubuntu-latest, macos-latest, windows-latest] | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Download Artifacts | |
uses: actions/download-artifact@v3 | |
with: | |
name: dist_bin | |
- name: Extract Artifacts | |
run: tar -xvf dist_bin.tar | |
- uses: actions/setup-python@v4 | |
with: | |
python-version: '3.11.5' | |
cache: 'pip' | |
# make sure 'smartthings' is available to child processes | |
- name: Set Windows Path | |
if: runner.os == 'Windows' | |
run: Add-Content $env:GITHUB_PATH "${{ github.workspace }}\packages\cli\dist_bin\win\x64" | |
- name: Set macOS Path | |
if: runner.os == 'macOS' | |
run: echo "$GITHUB_WORKSPACE/packages/cli/dist_bin/macos/x64" >> $GITHUB_PATH | |
- name: Set Linux Path | |
if: runner.os == 'Linux' | |
run: echo "$GITHUB_WORKSPACE/packages/cli/dist_bin/linux/x64" >> $GITHUB_PATH | |
- name: Install Dependencies and Run Tests | |
run: | | |
python -m pip install --force-reinstall -v pip==23.3.1 | |
pip install -r requirements.txt | |
pytest | |
working-directory: packages/cli/functional-tests | |
github-release: | |
needs: [release, package] | |
if: needs.release.outputs.cli-released == 'true' | |
name: Create Github Release | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repo | |
uses: actions/checkout@v3 | |
- name: Download Artifacts | |
uses: actions/download-artifact@v3 | |
with: | |
name: dist_bin | |
- name: Extract Artifacts | |
run: tar -xvf dist_bin.tar | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 18.5.0 | |
- run: npm ci | |
# hack since Github auto generated notes aren't working right now | |
- name: Generate Github Release Notes | |
run: node generate-release-notes.mjs ${{ needs.release.outputs.cli-version }} | |
- name: Create Github Release | |
uses: softprops/action-gh-release@v1 | |
with: | |
name: ${{ needs.release.outputs.cli-version }} | |
body_path: ${{ github.workspace }}/RELEASE_NOTES.txt | |
tag_name: ${{ needs.release.outputs.cli-tag }} | |
prerelease: false | |
files: 'packages/cli/dist_bin/**/*.@(tar.gz|zip)' | |
homebrew-formula: | |
needs: [release, github-release] | |
if: needs.release.outputs.cli-released == 'true' | |
name: Bump Homebrew Formula | |
runs-on: macos-latest | |
steps: | |
- name: Checkout Repo | |
uses: actions/checkout@v3 | |
- name: Configure Git Identity | |
uses: Homebrew/actions/git-user-config@master | |
with: | |
username: smartthingspi | |
- name: Tap Formula Repo | |
run: brew tap smartthingscommunity/smartthings | |
- name: Bump Formula | |
uses: Homebrew/actions/bump-formulae@master | |
with: | |
token: ${{ secrets.HOMEBREW_COMMITTER_TOKEN }} | |
formulae: smartthingscommunity/smartthings/smartthings | |
windows-installer: | |
needs: [release, package, github-release] | |
if: needs.release.outputs.cli-released == 'true' | |
name: Release Windows Installer | |
# ensure WiX Toolset is installed on image before updating runner | |
# ex: https://github.com/actions/virtual-environments/blob/b87bdfb146bdd41a98f33fc9572a961e9a60e9dd/images/win/Windows2022-Readme.md | |
runs-on: windows-2022 | |
steps: | |
- name: Print needs.release.outputs.cli-version | |
run: Write-Output ${{ needs.release.outputs.cli-version }} | |
# remove any pre-release labels since WiX doesn't support them | |
- name: Sanitize CLI Version String | |
id: safe-semver | |
run: echo "version=$('${{ needs.release.outputs.cli-version }}'.Split('-') | Select-Object -Index 0)" >> $env:GITHUB_OUTPUT | |
- name: Print steps.safe-semver.outputs.version | |
run: Write-Output ${{ steps.safe-semver.outputs.version }} | |
- name: Checkout Repo | |
uses: actions/checkout@v3 | |
- name: Download Artifacts | |
uses: actions/download-artifact@v3 | |
with: | |
name: dist_bin | |
- name: Extract Artifacts | |
run: tar -xvf dist_bin.tar | |
- run: mv packages\cli\dist_bin\win\x64\smartthings.exe packages\cli\wix | |
# https://github.community/t/set-path-for-wix-toolset-in-windows-runner/154708/2 | |
# https://stackoverflow.com/a/71579543 | |
- name: Add WiX Toolset to Path | |
run: Add-Content $env:GITHUB_PATH "C:\Program Files (x86)\WiX Toolset v3.11\bin" | |
- name: Compile WiX file | |
run: candle.exe smartthings.wxs -ext WixUIExtension | |
working-directory: packages\cli\wix | |
env: | |
SMARTTHINGS_SEMVER: ${{ steps.safe-semver.outputs.version }} | |
# must be absolute path or relative to .wxs file | |
SMARTTHINGS_BINARY_PATH: .\smartthings.exe | |
- name: Build .msi | |
run: light.exe -out smartthings.msi smartthings.wixobj -ext WixUIExtension | |
working-directory: packages\cli\wix | |
- name: Add .msi Artifact to Github Release | |
uses: softprops/action-gh-release@v1 | |
with: | |
tag_name: ${{ needs.release.outputs.cli-tag }} | |
files: packages/cli/wix/smartthings.msi |