Skip to content

add changelog;

add changelog; #5

Workflow file for this run

name: Release package
on:
push:
branches:
- master
env:
NODE_VERSION: "18.x"
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # entire history is needed for the changelog
- name: Read manifest
run: |
echo "PACKAGE_NAME=$(cat package.json | jq -r '.name')" >> $GITHUB_ENV
echo "PACKAGE_VERSION=$(cat package.json | jq -r '.version')" >> $GITHUB_ENV
echo "TAG_NAME=$(cat package.json | jq -r '.version')" >> $GITHUB_ENV
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
cache: "yarn"
# check if tag exists and fail if not [force-release] in commit message
- name: Check if tag exists
id: check_tag
if: "!contains(github.event.head_commit.message, '[force-release]')"
run: |
git fetch --tags &> /dev/null
if git rev-parse ${{ env.TAG_NAME }} >/dev/null 2>&1; then
echo "Tag ${{ env.TAG_NAME }} already exists; Use [force-release] to skip check."
exit 1
else
echo "Will create tag ${{ env.TAG_NAME }} on release."
echo "PUSH_TAG=true" >> $GITHUB_ENV
fi
- name: Force release
if: "contains(github.event.head_commit.message, '[force-release]')"
run: |
echo "Will create tag ${{ env.TAG_NAME }} on release."
echo "PUSH_TAG=true" >> $GITHUB_ENV
- name: Cache node modules
uses: actions/cache@v3
with:
path: node_modules
key: node_modules-${{hashFiles('package-lock.json')}}
restore-keys: node_modules- # Take any latest cache if failed to find it for current lock file
- name: Install dependencies
run: yarn install
- name: Build
id: build
run: yarn build
- name: Zip dist
id: zip
run: |
cd dist
zip -r ../isomorphic-logger.zip *
cd ..
- name: Generate changelog
id: changelog
uses: orhun/git-cliff-action@v2
with:
config: cliff.toml
args: --verbose --tag ${{ env.TAG_NAME }}
env:
OUTPUT: CHANGELOG.md
- name: Setup git user
run: |
git config --local user.name "Github Actions"
git config --local user.email "[email protected]"
- name: Commit and push changelog
run: |
if ! git diff --quiet CHANGELOG.md; then
git add CHANGELOG.md
git commit -m "Update CHANGELOG.md"
git push
else
echo "No changes to CHANGELOG.md"
fi
- name: Create tag and push
if: env.PUSH_TAG == 'true'
run: |
git commit --allow-empty -m "Release ${{ env.TAG_NAME }}"
git tag ${{ env.TAG_NAME }} || true
git push
git push origin ${{ env.TAG_NAME }}
- name: Generate latest changes
id: changes
uses: orhun/git-cliff-action@v2
with:
config: cliff.toml
args: --verbose --latest --strip header
env:
OUTPUT: "CHANGELOG.md"
- name: Create Release
id: create_release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ env.TAG_NAME }}
name: ${{ env.TAG_NAME }}
body: ${{ steps.changes.outputs.content }}
draft: false
prerelease: false
fail_on_unmatched_files: true
files: |
isomorphic-logger.zip
- name: Publish to NPM
uses: JS-DevTools/npm-publish@v2
with:
token: ${{ secrets.NPM_TOKEN }}
access: public