ci: adds auto release

This commit is contained in:
ZackaryW 2024-09-06 23:05:13 -07:00
parent daa0cba23c
commit a95d61133b
1 changed files with 90 additions and 0 deletions

90
.github/workflows/release.yml vendored Normal file
View File

@ -0,0 +1,90 @@
name: Release Package
on:
push:
branches:
- main
- master
paths:
- package.json
pull_request:
branches:
- main
- master
paths:
- package.json
workflow_dispatch:
inputs:
version:
description: 'Version to release'
required: true
type: string
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '16' # Use your preferred version
- name: Install dependencies
run: npm install
- name: Get version from package.json
id: get_version
run: |
VERSION=$(cat package.json | jq -r '.version')
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Set GitHub Token
run: echo "GH_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV
- name: Check if version exists in releases
id: version_check
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION_EXISTS=$(gh release list | grep -w "$VERSION" || true)
if [ -n "$VERSION_EXISTS" ]; then
echo "Version $VERSION already exists. Aborting."
exit 0
fi
- name: Update version in package.json (Manual Trigger)
if: github.event_name == 'workflow_dispatch'
run: |
VERSION=${{ github.event.inputs.version }}
npm version $VERSION --no-git-tag-version
echo "Updated package.json to version $VERSION"
- name: Update version in manifest.json
run: |
VERSION=$(cat package.json | jq -r '.version')
jq --arg v "$VERSION" '.version = $v' manifest.json > manifest_tmp.json
mv manifest_tmp.json manifest.json
- name: Build the project
run: npm run build
- name: Create Release Directory
run: |
mkdir -p output
cp manifest.json output/
if [ -f styles.css ]; then
cp styles.css output/
if [ -f main.js ]; then
cp main.js output/
fi
- name: Create GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION=$(cat package.json | jq -r '.version')
gh release create "$VERSION" ./output/* --title "v$VERSION" --notes "Release $VERSION"