Merge pull request #27 from Myongji-Graduate/feat/ci-cd #1
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: 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"}' |