Skip to content

Commit

Permalink
Merge pull request #27 from Myongji-Graduate/feat/ci-cd
Browse files Browse the repository at this point in the history
feat: automatic npm publish
  • Loading branch information
gahyuun authored Jan 5, 2025
2 parents f5be18d + 97cc94b commit f2bb788
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Publish Package

on:
push:
branches:
- main

jobs:
version-check-and-publish:
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: '20.11.1'
registry-url: 'https://registry.npmjs.org/'

- name: Cache npm dependencies
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-npm-cache-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-npm-cache-
- name: Install dependencies
run: npm ci

- name: Check for version update
id: check_version
run: |
LATEST_VERSION=$(npm show $(jq -r '.name' package.json) version)
CURRENT_VERSION=$(jq -r '.version' package.json)
if [ "$CURRENT_VERSION" = "$LATEST_VERSION" ]; then
exit 0
# If를 열면 if를 닫는거
fi
echo "::set-output name=version_updated::true"
- name: Publish package to npm
if: steps.check_version.outputs.version_updated == 'true'
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npm publish --access public

- name: Trigger webhook
if: steps.check_version.outputs.version_updated == 'true'
run: |
curl -X POST -H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${{ secrets.PAT }}" \
https://api.github.com/repos/Myongji-Graduate/myongji-graduate-next/dispatches \
-d '{"event_type": "fetch-ax-updated"}'

0 comments on commit f2bb788

Please sign in to comment.