1.0.12 #6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: state | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- "package.json" | |
jobs: | |
check-version: | |
runs-on: ubuntu-latest | |
outputs: | |
version_changed: ${{ steps.check_version.outputs.version_changed }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 2 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
- name: Install jq | |
run: sudo apt-get install -y jq | |
- name: Debug current and previous versions | |
run: | | |
echo "Current version in package.json: $(jq -r .version < package.json)" | |
PREV_VERSION=$(git show HEAD~1:package.json | jq -r .version || echo "none") | |
echo "Previous version in package.json: $PREV_VERSION" | |
- name: Check version increment | |
id: check_version | |
run: | | |
PREV_VERSION=$(git show HEAD~1:package.json | jq -r .version || echo "none") | |
CURR_VERSION=$(jq -r .version < package.json) | |
echo "Previous version: $PREV_VERSION" | |
echo "Current version: $CURR_VERSION" | |
if [ "$PREV_VERSION" = "none" ] || [ "$PREV_VERSION" != "$CURR_VERSION" ]; then | |
echo "version_changed=true" >> $GITHUB_ENV | |
echo "version_changed=true" >> $GITHUB_OUTPUT | |
else | |
echo "version_changed=true" >> $GITHUB_ENV | |
echo "version_changed=true" >> $GITHUB_OUTPUT | |
fi | |
build: | |
runs-on: ubuntu-latest | |
needs: check-version | |
if: needs.check-version.outputs.version_changed == 'true' | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
- name: Install dependencies | |
run: npm i | |
- name: Building codebase | |
run: npm run build | |
- name: Test codebase | |
run: npm run test | |
- name: Upload dist artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: dist | |
path: dist | |
publish: | |
needs: | |
- build | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Download dist artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
name: dist | |
path: dist | |
- name: Configure npm for publishing | |
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc | |
- name: Publish to NPM | |
run: npm publish --access public | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |