From 86857cbe53911b5c69d18d87723f63f25316388e Mon Sep 17 00:00:00 2001 From: Marshall Ku Date: Tue, 19 Nov 2024 08:16:52 +0900 Subject: [PATCH] Modify workflow for deploying package --- .github/workflows/create-release.yml | 75 ---------------------------- .github/workflows/npm-publish.yml | 17 ------- .github/workflows/publish.yml | 61 ++++++++++++++++++++++ 3 files changed, 61 insertions(+), 92 deletions(-) delete mode 100644 .github/workflows/create-release.yml delete mode 100644 .github/workflows/npm-publish.yml create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml deleted file mode 100644 index 73283be..0000000 --- a/.github/workflows/create-release.yml +++ /dev/null @@ -1,75 +0,0 @@ -name: Create tag and release - -on: - push: - branches: - - master - -jobs: - check-commit: - runs-on: ubuntu-latest - outputs: - version: ${{ steps.check.outputs.version }} - steps: - - uses: actions/checkout@v4 - - name: Check commit message - id: check - run: echo "version=$(echo '${{ github.event.head_commit.message }}' | grep -oP '^Update version to \K.*$')" >> $GITHUB_OUTPUT - shell: bash - create-tag: - runs-on: ubuntu-latest - needs: ["check-commit"] - if: ${{ needs.check-commit.outputs.version != '' }} - outputs: - tag-exists: ${{ steps.create-tag.outputs.tag_exists }} - release-body: ${{ steps.generate-body.outputs.body }} - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - name: Generate body - id: generate-body - run: | - EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) - git_logs=$(git log "$(git describe --tags --abbrev=0)"..HEAD --oneline) - git_logs="${git_logs//$'\n'/$'\n'- }" - { - echo "body<<$EOF" - echo "- $git_logs" - echo "$EOF" - } >>"$GITHUB_OUTPUT" - shell: bash - - uses: rickstaa/action-create-tag@v1 - id: create-tag - with: - tag: ${{ needs.check-commit.outputs.version }} - tag_exists_error: true - message: ${{ needs.check-commit.outputs.version }} - create-release: - runs-on: ubuntu-latest - needs: ["check-commit", "create-tag"] - if: ${{ needs.create-tag.outputs.tag-exists == 'false' }} - steps: - - uses: actions/checkout@v4 - - name: Create a GitHub release - uses: ncipollo/release-action@v1 - with: - tag: ${{ needs.check-commit.outputs.version }} - name: ${{ needs.check-commit.outputs.version }} - body: ${{ needs.create-tag.outputs.release-body }} - trigger-deploy: - runs-on: ubuntu-latest - needs: ["create-release"] - name: Trigger publish workflow - steps: - - uses: actions/github-script@v6 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - script: | - github.rest.actions.createWorkflowDispatch({ - owner: context.repo.owner, - repo: context.repo.repo, - workflow_id: 'npm-publish.yml', - ref: 'master', - }) diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml deleted file mode 100644 index 766bd35..0000000 --- a/.github/workflows/npm-publish.yml +++ /dev/null @@ -1,17 +0,0 @@ -name: Publish package - -on: - release: - types: [created] - workflow_dispatch: - repository_dispatch: - -jobs: - publish-npm: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: marshallku/actions/setup/pnpm@master - - run: pnpm publish --access=public - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..5712052 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,61 @@ +name: Publish package + +on: + push: + branches: + - master + +jobs: + check-version: + runs-on: ubuntu-latest + outputs: + version: ${{ steps.check.outputs.version }} + steps: + - name: Check version change + id: check + uses: marshallku/actions/version/check-npm@master + create-tag-release: + runs-on: ubuntu-latest + needs: ["check-version"] + if: ${{ needs.check-version.outputs.version != '' }} + outputs: + tag-exists: ${{ steps.create-tag.outputs.tag_exists }} + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Generate body + id: generate-body + run: | + EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) + git_logs=$(git log "$(git describe --tags --abbrev=0)"..HEAD --oneline) + git_logs="${git_logs//$'\n'/$'\n'- }" + { + echo "body<<$EOF" + echo "- $git_logs" + echo "$EOF" + } >>"$GITHUB_OUTPUT" + shell: bash + - uses: rickstaa/action-create-tag@v1 + id: create-tag + with: + tag: ${{ needs.check-version.outputs.version }} + tag_exists_error: true + message: ${{ needs.check-version.outputs.version }} + - name: Create a GitHub release + if: ${{ steps.create-tag.outputs.tag_exists == 'false' }} + uses: ncipollo/release-action@v1 + with: + tag: ${{ needs.check-version.outputs.version }} + name: ${{ needs.check-version.outputs.version }} + body: ${{ steps.generate-body.outputs.body }} + publish: + runs-on: ubuntu-latest + needs: ["check-version", "create-tag-release"] + if: ${{ needs.check-version.outputs.version != '' && needs.create-tag-release.outputs.tag-exists == 'false' }} + steps: + - uses: actions/checkout@v4 + - uses: marshallku/actions/setup/pnpm@master + - run: pnpm publish --access=public + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}