diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml new file mode 100644 index 0000000..2f837be --- /dev/null +++ b/.github/workflows/npm-publish.yml @@ -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"}'