Skip to content

Commit

Permalink
update workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
dale0525 committed Dec 26, 2023
1 parent 17179fe commit d968303
Showing 1 changed file with 39 additions and 72 deletions.
111 changes: 39 additions & 72 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,80 +1,47 @@
name: Release Workflow

on:
push:
branches:
- main

permissions:
contents: write
pull-requests: write

name: release-please
jobs:
release-please:
release:
runs-on: ubuntu-latest
steps:
# Create release
- name: Create release
uses: google-github-actions/release-please-action@v4
id: release
with:
release-type: node
token: ${{ secrets.GH_TOKEN }}

# Checkout
- name: Checkout
if: ${{ steps.release.outputs.release_created }}
uses: actions/checkout@v3

# Install Node.js
- name: Install Node.js
if: ${{ steps.release.outputs.release_created }}
uses: actions/setup-node@v3
with:
node-version: 18
registry-url: 'https://registry.npmjs.org'

# Install pnpm
- name: Install pnpm
if: ${{ steps.release.outputs.release_created }}
uses: pnpm/action-setup@v2
id: pnpm-install
with:
version: 8
run_install: false

# Get pnpm store directory
- name: Get pnpm store directory
if: ${{ steps.release.outputs.release_created }}
id: pnpm-cache
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
# Setup pnpm cache
- name: Setup pnpm cache
if: ${{ steps.release.outputs.release_created }}
uses: actions/cache@v3
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
# Install dependencies
- name: Install dependencies
if: ${{ steps.release.outputs.release_created }}
run: pnpm install

# Build for production
- name: Build for production
if: ${{ steps.release.outputs.release_created }}
run: pnpm run build

# Upload package to release
# https://github.com/philips-labs/terraform-aws-github-runner/blob/main/.github/workflows/release.yml#L46
- name: Upload package.zip to the release
if: ${{ steps.release.outputs.releases_created }}
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
gh release upload ${{ steps.release.outputs.tag_name }} "package.zip"
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Install Dependencies and Build
id: build
run: |
npm install -g pnpm && pnpm install && pnpm run build
echo "zip_path=$(pwd)/package.zip" >> $GITHUB_OUTPUT
- name: Get Current Version
id: version
run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT

- name: Check for Existing Release
id: check_release
run: |
current_version="${{ steps.version.outputs.version }}"
if git rev-parse -q --verify "refs/tags/v$current_version"; then
echo "Release $current_version already exists. Nothing to do."
exit 0
fi
commit_message=$(git log -1 --pretty=%B)
release_title="v$current_version"
echo "Creating release $release_title"
release_id=$(curl -s -X POST -H "Authorization: Bearer ${{ secrets.GH_TOKEN }}" -d "{\"tag_name\": \"$release_title\", \"name\": \"$release_title\", \"body\": \"$commit_message\"}" "https://api.github.com/repos/${{ github.repository }}/releases" | jq -r '.id')
zip_path="${{ steps.build.outputs.zip_path }}"
echo "Uploading binary to release $release_id"
gh release upload $release_title $zip_path

0 comments on commit d968303

Please sign in to comment.