diff --git a/.github/workflows/deploy-hato-bot.yml b/.github/workflows/deploy-hato-bot.yml index 5e0ce5fc73..4909890ed8 100644 --- a/.github/workflows/deploy-hato-bot.yml +++ b/.github/workflows/deploy-hato-bot.yml @@ -127,6 +127,61 @@ jobs: github-token: ${{secrets.GITHUB_TOKEN}} branch-name-prefix: fix-version-python-version pr-title-prefix: .python-versionを直してあげたよ! + pr-update-version: + runs-on: ubuntu-latest + needs: deploy_docker_image + if: always() && (needs.deploy_docker_image.result == 'success' || (github.event_name == 'pull_request' && github.event.action == 'closed')) + permissions: + contents: write + pull-requests: write + steps: + - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 + if: github.event_name != 'pull_request' || github.event.action != 'closed' + with: + fetch-depth: 0 + ref: ${{ github.event.pull_request.head.sha }} + - uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 + if: github.event_name != 'pull_request' || github.event.action != 'closed' + with: + cache: npm + node-version-file: package.json + - name: Get npm version + id: get_npm_version + if: github.event_name != 'pull_request' || github.event.action != 'closed' + run: bash "${GITHUB_WORKSPACE}/scripts/deploy_hato_bot/pr_update_version/get_npm_version_.sh" + env: + HEAD_REF: ${{github.head_ref || github.event.release.tag_name}} + - uses: dev-hato/actions-diff-pr-management@128afc4203b4e391e03868be91c987b2ddba7ea5 # v1.1.12 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + branch-name-prefix: fix-version + pr-title-prefix: nodeをアップデートしてあげたよ! + # package.jsonに差分があれば、package.jsonからpackage-lock.jsonを作り出す + pr-check-npm: + runs-on: ubuntu-latest + needs: pr-update-version + steps: + - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 + if: github.event_name != 'pull_request' || github.event.action != 'closed' + with: + # ここでsubmodule持ってくるとdetached headにcommitして死ぬ + # submodule: 'recursive' + fetch-depth: 0 + ref: ${{ github.event.pull_request.head.sha }} + - name: Set up Node.js + uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 + if: github.event_name != 'pull_request' || github.event.action != 'closed' + with: + cache: npm + node-version-file: package.json + - name: Install dependencies + if: github.event_name != 'pull_request' || github.event.action != 'closed' + run: bash "${GITHUB_WORKSPACE}/scripts/deploy_hato_bot/npm_install.sh" + - uses: dev-hato/actions-diff-pr-management@128afc4203b4e391e03868be91c987b2ddba7ea5 # v1.1.12 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + branch-name-prefix: npm + pr-title-prefix: package.jsonやpackage-lock.jsonが更新されたので直してあげたよ! update-dockle: runs-on: ubuntu-latest steps: @@ -156,12 +211,13 @@ jobs: if: always() needs: - update-version-python-version + - pr-check-npm - update-dockle - dockle steps: - - if: needs.update-dockle.result == 'success' && (github.event_name == 'push' || (github.event_name == 'pull_request' && github.repository != github.event.pull_request.head.repo.full_name) || (needs.update-version-python-version.result == 'success' && (github.event.action == 'closed' || needs.dockle.result == 'success'))) + - if: needs.update-dockle.result == 'success' && (github.event_name == 'push' || (github.event_name == 'pull_request' && github.repository != github.event.pull_request.head.repo.full_name) || (needs.update-version-python-version.result == 'success' && needs.pr-check-npm.result == 'success' && (github.event.action == 'closed' || needs.dockle.result == 'success'))) run: exit 0 - - if: ${{ !(needs.update-dockle.result == 'success' && (github.event_name == 'push' || (github.event_name == 'pull_request' && github.repository != github.event.pull_request.head.repo.full_name) || (needs.update-version-python-version.result == 'success' && (github.event.action == 'closed' || needs.dockle.result == 'success')))) }} + - if: ${{ !(needs.update-dockle.result == 'success' && (github.event_name == 'push' || (github.event_name == 'pull_request' && github.repository != github.event.pull_request.head.repo.full_name) || (needs.update-version-python-version.result == 'success' && needs.pr-check-npm.result == 'success' && (github.event.action == 'closed' || needs.dockle.result == 'success')))) }} run: exit 1 concurrency: group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }} diff --git a/.github/workflows/pr-check-npm.yml b/.github/workflows/pr-check-npm.yml deleted file mode 100644 index 00f79278f4..0000000000 --- a/.github/workflows/pr-check-npm.yml +++ /dev/null @@ -1,80 +0,0 @@ ---- -name: pr-check-npm -on: - pull_request: - types: - - opened - - synchronize - - reopened - - closed - push: - branches: - - master - - develop -permissions: - contents: write - pull-requests: write -jobs: - pr-update-version: - runs-on: ubuntu-latest - permissions: - contents: write - pull-requests: write - steps: - - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 - if: github.event_name != 'pull_request' || github.event.action != 'closed' - with: - fetch-depth: 0 - ref: ${{ github.event.pull_request.head.sha }} - - uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 - if: github.event_name != 'pull_request' || github.event.action != 'closed' - with: - cache: npm - node-version-file: package.json - - name: Get npm version - id: get_npm_version - if: github.event_name != 'pull_request' || github.event.action != 'closed' - run: bash "${GITHUB_WORKSPACE}/scripts/pr_check_npm/pr_update_version/get_npm_version.sh" - - uses: dev-hato/actions-diff-pr-management@128afc4203b4e391e03868be91c987b2ddba7ea5 # v1.1.12 - with: - github-token: ${{secrets.GITHUB_TOKEN}} - branch-name-prefix: fix-version - pr-title-prefix: nodeをアップデートしてあげたよ! - # package.jsonに差分があれば、package.jsonからpackage-lock.jsonを作り出す - pr-check-npm: - runs-on: ubuntu-latest - needs: pr-update-version - steps: - - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 - if: github.event_name != 'pull_request' || github.event.action != 'closed' - with: - # ここでsubmodule持ってくるとdetached headにcommitして死ぬ - # submodule: 'recursive' - fetch-depth: 0 - ref: ${{ github.event.pull_request.head.sha }} - - name: Set up Node.js - uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 - if: github.event_name != 'pull_request' || github.event.action != 'closed' - with: - cache: npm - node-version-file: package.json - - name: Install dependencies - if: github.event_name != 'pull_request' || github.event.action != 'closed' - run: bash "${GITHUB_WORKSPACE}/scripts/pr_check_npm/npm_install.sh" - - uses: dev-hato/actions-diff-pr-management@128afc4203b4e391e03868be91c987b2ddba7ea5 # v1.1.12 - with: - github-token: ${{secrets.GITHUB_TOKEN}} - branch-name-prefix: npm - pr-title-prefix: package.jsonやpackage-lock.jsonが更新されたので直してあげたよ! - pr-check-npm-complete: - runs-on: ubuntu-latest - if: always() - needs: pr-check-npm - steps: - - if: needs.pr-check-npm.result == 'success' - run: exit 0 - - if: needs.pr-check-npm.result != 'success' - run: exit 1 -concurrency: - group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }} - cancel-in-progress: true diff --git a/scripts/pr_check_npm/npm_install.sh b/scripts/deploy_hato_bot/npm_install.sh similarity index 100% rename from scripts/pr_check_npm/npm_install.sh rename to scripts/deploy_hato_bot/npm_install.sh diff --git a/scripts/deploy_hato_bot/pr_update_version/get_npm_version.sh b/scripts/deploy_hato_bot/pr_update_version/get_npm_version.sh new file mode 100755 index 0000000000..2b8acb2db9 --- /dev/null +++ b/scripts/deploy_hato_bot/pr_update_version/get_npm_version.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +DOCKER_CMD="npm --version" +DEPENDABOT_NPM_VERSION="$(docker run ghcr.io/dependabot/dependabot-core sh -c "${DOCKER_CMD}")" +echo "Dependabot npm version:" "${DEPENDABOT_NPM_VERSION}" +RENOVATE_NPM_VERSION="$(docker run ghcr.io/renovatebot/renovate sh -c "${DOCKER_CMD}")" +echo "Renovate npm version:" "${RENOVATE_NPM_VERSION}" +cp .env.example .env +export TAG_NAME="${HEAD_REF//\//-}" +docker compose pull +HATO_BOT_NPM_VERSION="$(docker compose run hato-bot sh -c "${DOCKER_CMD}")" +echo "hato-bot npm version:" "${HATO_BOT_NPM_VERSION}" +NPM_PATTERN_PACKAGE="s/\"npm\": \".*\"/\"npm\": \"^${HATO_BOT_NPM_VERSION} || ^${RENOVATE_NPM_VERSION} || ^${DEPENDABOT_NPM_VERSION}\"/g" +sed -i -e "${NPM_PATTERN_PACKAGE}" package.json +bash "${GITHUB_WORKSPACE}/scripts/deploy_hato_bot/npm_install.sh" diff --git a/scripts/pr_check_npm/pr_update_version/get_npm_version.sh b/scripts/pr_check_npm/pr_update_version/get_npm_version.sh deleted file mode 100755 index ff86a68b9b..0000000000 --- a/scripts/pr_check_npm/pr_update_version/get_npm_version.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash - -DOCKER_CMD="npm --version" -DEPENDABOT_NPM_VERSION="$(docker run ghcr.io/dependabot/dependabot-core sh -c "${DOCKER_CMD}")" -echo "Dependabot npm version:" "${DEPENDABOT_NPM_VERSION}" -RENOVATE_NPM_VERSION="$(docker run ghcr.io/renovatebot/renovate sh -c "${DOCKER_CMD}")" -echo "Renovate npm version:" "${RENOVATE_NPM_VERSION}" -NPM_PATTERN_PACKAGE="s/\"npm\": \".*\"/\"npm\": \"^${RENOVATE_NPM_VERSION} || ^${DEPENDABOT_NPM_VERSION}\"/g" -sed -i -e "${NPM_PATTERN_PACKAGE}" package.json -bash "${GITHUB_WORKSPACE}/scripts/pr_check_npm/npm_install.sh"