From 8cf881fc0f5b1da5fddde8551bb0eff2b99dde87 Mon Sep 17 00:00:00 2001 From: gahyuun Date: Sat, 21 Dec 2024 19:43:18 +0900 Subject: [PATCH 1/2] feat: automatic npm publish yml --- .github/workflows/npm-publish.yml | 50 +++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 .github/workflows/npm-publish.yml diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml new file mode 100644 index 0000000..b895e0d --- /dev/null +++ b/.github/workflows/npm-publish.yml @@ -0,0 +1,50 @@ +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 From 97cc94b66766b75541f978378e798933e5d3ddbd Mon Sep 17 00:00:00 2001 From: gahyuun Date: Sun, 22 Dec 2024 23:37:28 +0900 Subject: [PATCH 2/2] feat: trigger webhook --- .github/workflows/npm-publish.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index b895e0d..2f837be 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -48,3 +48,11 @@ jobs: 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"}'