Skip to content

Commit

Permalink
fix: fix optic release workflow (#50)
Browse files Browse the repository at this point in the history
* chore: use Node 20

This required updating the npm lockfile and CI.

* update lock file

* attempt to fix lockfile

* fix lockfile again...

* try to fix workflow

* try something else...

* fix type

* update node version in release workflow

* fix: fix optic release workflow

* checkout code first

* remove quotes

* fix up artifact for release

* remove unused steps in build workflow

* nit

---------

Co-authored-by: Evan Hahn <[email protected]>
  • Loading branch information
gmaclennan and EvanHahn committed Apr 25, 2024
1 parent 2655d44 commit 8e6c3f2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 107 deletions.
107 changes: 4 additions & 103 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,84 +1,14 @@
# Run whenever code is pushed or when manually triggers from Github UI
# Run whenever code is pushed
on:
push:
workflow_dispatch:
inputs:
version:
description: '(Optional) Version name, in format v1.2.3'
required: false

name: Build & Release
name: Build

jobs:
prepare-release:
name: Prepare Release
runs-on: ubuntu-20.04
if: github.event_name == 'workflow_dispatch'
outputs:
version: ${{ steps.pkg.outputs.prop }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Use Node.js 20
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Configure git user & email
run: |
git config user.name Github Actions
git config user.email [email protected]
- name: Prepare new version
run: npx standard-version --release-as '${{ github.event.inputs.version }}'
- name: Commit changes
run: git push --follow-tags
- name: Get package version
id: pkg
uses: notiz-dev/github-action-json-property@release
with:
path: 'package.json'
prop_path: 'version'
create-release:
name: Create Release
# Run this job after prepare-release, whether or not it runs, and run on
# either a tag push or when manually triggered
if: always() && (github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')))
needs: prepare-release
outputs:
tag: ${{ steps.get_tag.outputs.tag }}
upload_url: ${{ steps.release.outputs.upload_url }}
runs-on: ubuntu-20.04
steps:
- name: Get tag name
id: get_tag
run: |
if [[ -n '${{ needs.prepare-release.outputs.version }}' ]]; then
TAG=v${{ needs.prepare-release.outputs.version }}
else
# Use bash parameter expansion to remove refs/tags/ from GITHUB_REF
TAG=${GITHUB_REF/refs\/tags\//}
fi
echo ::set-output name=tag::$TAG
- name: Create Release
id: release
uses: actions/create-release@v1
continue-on-error: true # Ignore failure if release already exists
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{ steps.get_tag.outputs.tag }}
release_name: Release ${{ steps.get_tag.outputs.tag }}
body: |
For changes see [CHANGELOG.md](CHANGELOG.md)
draft: false
prerelease: false
build:
# This step runs on every push, ensures there is an artifact for each push
name: Build
runs-on: ubuntu-20.04
if: always()
needs: [prepare-release, create-release]
outputs:
artifact: ${{ steps.filename.outputs.filename }}
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -89,13 +19,8 @@ jobs:
- name: Get version
id: version
run: |
# Use either the git tag or the git commit sha to identify the version
if [[ -n '${{ needs.create-release.outputs.tag }}' ]]; then
VERSION=${{ needs.create-release.outputs.tag }}
else
# Get a short ID to the commit used to build this version
VERSION=$(git rev-parse --short ${{ github.sha }})
fi
# Use git commit sha to identify the version
VERSION=$(git rev-parse --short ${{ github.sha }})
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
- name: Write version to metadata.json
uses: jossef/[email protected]
Expand All @@ -117,27 +42,3 @@ jobs:
with:
name: ${{ steps.filename.outputs.FILENAME }}
path: build/${{ steps.filename.outputs.FILENAME }}
upload-release:
name: Upload release
runs-on: ubuntu-20.04
# Only runs if a release has been created
needs: [build, create-release]
steps:
- name: Download artifact
id: download
uses: actions/download-artifact@v4
with:
name: ${{ needs.build.outputs.artifact }}
- name: 'Echo download path'
run: echo ${{ steps.download.outputs.download-path }}
- name: Display structure of downloaded files
run: ls -R
- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: ${{ needs.build.outputs.artifact }}
asset_name: ${{ needs.build.outputs.artifact }}
asset_content_type: application/zip
9 changes: 5 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: release
name: Release

on:
workflow_dispatch:
Expand Down Expand Up @@ -38,14 +38,15 @@ jobs:
sync-semver-tags: true
access: 'public'
# This prefix is added before the prerelease number, e.g. `v3.0.0-next.0`
prerelease-prefix: 'next'
prerelease-prefix: 'alpha'
semver: ${{ github.event.inputs.semver }}
# Prereleases are published under the `next` npm dist-tag
npm-tag: ${{ startsWith(github.event.inputs.semver, 'pre') && 'next' || 'latest' }}
# Prereleases are published under the `alpha` npm dist-tag
npm-tag: ${{ startsWith(github.event.inputs.semver, 'pre') && 'alpha' || 'latest' }}
# Don't notify linked issues
notify-linked-issues: false
# optional: set this secret in your repo config for publishing to NPM
npm-token: ${{ secrets.NPM_TOKEN }}
artifact-path: build
build-command: |
npm install
npm run build

0 comments on commit 8e6c3f2

Please sign in to comment.