Skip to content

🔧 chore: Add release workflow #1

🔧 chore: Add release workflow

🔧 chore: Add release workflow #1

Workflow file for this run

on:
push:
branches:
- main
permissions:
contents: write
pull-requests: write
name: release
env:
IS_MERGED_RELEASE_PR: ${{ startsWith(github.event.head_commit.message, '🚀 release:') }}
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup GIT
uses: fregante/setup-git-user@v2
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 16
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
if: ${{ env.IS_MERGED_RELEASE_PR == 'false' }}
run: npm ci --ignore-scripts
- name: Install dependencies and build package
if: ${{ env.IS_MERGED_RELEASE_PR == 'true' }}
run: npm ci
# release-it configuration reference
# https://github.com/release-it/release-it/blob/fdcf005ced6967a86305a3e10fd1d61a3149407b/docs/configuration.md#configuration
# https://github.com/release-it/release-it/blob/HEAD/config/release-it.json
- name: Bump version and update changelog
if: ${{ env.IS_MERGED_RELEASE_PR == 'false' }}
run: npx release-it --no-npm.publish --no-git --no-github.release --ci
- name: Preview changelog
if: ${{ env.IS_MERGED_RELEASE_PR == 'false' }}
id: preview-changelog
run: |
{
echo 'changelog<<EOF'
npx conventional-changelog -p @favoloso/emoji -u
echo EOF
} > "$GITHUB_OUTPUT"
- name: Read package.json version
id: package-version
uses: martinbeentjes/npm-get-version-action@v1.3.1
- name: Create release PR
if: ${{ env.IS_MERGED_RELEASE_PR == 'false' }}
uses: peter-evans/create-pull-request@v5
with:
branch: "release"
commit-message: "🚀 release: ${{ steps.package-version.outputs.current-version }}"
delete-branch: true
labels: release-preview
title: ${{ steps.package-version.outputs.current-version }}
body: ${{ steps.preview-changelog.outputs.changelog }}
- name: Read changelog
if: ${{ env.IS_MERGED_RELEASE_PR == 'true' }}
id: read-changelog
run: |
{
echo 'changelog<<EOF'
npx conventional-changelog -p @favoloso/emoji -r 1
echo EOF
} > "$GITHUB_OUTPUT"
- name: Git tag, GitHub release
if: ${{ env.IS_MERGED_RELEASE_PR == 'true' }}
uses: avakar/tag-and-release@v1
with:
tag_name: ${{ steps.package-version.outputs.current-version }}
release_name: ${{ steps.package-version.outputs.current-version }}
body: ${{ steps.read-changelog.outputs.changelog }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# - name: Publish NPM package
# if: ${{ env.IS_MERGED_RELEASE_PR == 'true' }}
# run: npm publish
# env:
# NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}