From 74c9aac36f57c44e0a073aaba5972da4e3607f34 Mon Sep 17 00:00:00 2001 From: Tomachi <8929706+book000@users.noreply.github.com> Date: Sat, 17 Jun 2023 12:19:00 +0900 Subject: [PATCH] ci: actions/create-release to ncipollo/release-action (#1060) and deleted some workflow ref: https://github.com/book000/book000/issues/11 --- .github/workflows/build.yml | 29 ----- .github/workflows/codeql-analysis.yml | 47 -------- .github/workflows/maven-ci.yml | 115 ++++++++++++++++++++ .github/workflows/release.yml | 148 -------------------------- qodana.yml | 6 -- 5 files changed, 115 insertions(+), 230 deletions(-) delete mode 100644 .github/workflows/build.yml delete mode 100644 .github/workflows/codeql-analysis.yml create mode 100644 .github/workflows/maven-ci.yml delete mode 100644 .github/workflows/release.yml delete mode 100644 qodana.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index bcf6c2eae..000000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: CI - -on: [ push, pull_request ] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - java-version: 17 - distribution: adopt - - - name: Cache local Maven repository - uses: actions/cache@v3 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven- - - - name: Build with Maven - run: mvn -B package --file pom.xml diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml deleted file mode 100644 index 5c811130d..000000000 --- a/.github/workflows/codeql-analysis.yml +++ /dev/null @@ -1,47 +0,0 @@ -name: "CodeQL" - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - schedule: - - cron: '15 6 * * 5' - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - - strategy: - fail-fast: false - matrix: - language: [ 'java' ] - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - java-version: 17 - distribution: adopt - - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - with: - languages: ${{ matrix.language }} - - - name: Cache local Maven repository - uses: actions/cache@v3 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven- - - - name: Autobuild - uses: github/codeql-action/autobuild@v2 - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/maven-ci.yml b/.github/workflows/maven-ci.yml new file mode 100644 index 000000000..f7f4523ae --- /dev/null +++ b/.github/workflows/maven-ci.yml @@ -0,0 +1,115 @@ +# Maven でビルドを実行する。マージされたら、リリースを作成する。 +# リリースが作成されたら、本番環境へデプロイする。 + +name: Maven + +on: + pull_request: + branches: + - main + - master + types: + - opened + - synchronize + paths: + - .github/workflows/maven-ci.yml + pull_request_target: + branches: + - main + - master + types: + - opened + - synchronize + - reopened + - closed + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.merged == true && github.base_ref || github.event.pull_request.head.sha }} + +jobs: + maven-ci: + name: Maven CI + uses: book000/templates/.github/workflows/reusable-maven.yml@master + + deploy: + runs-on: ubuntu-latest + if: github.event.pull_request.merged == true + + needs: + - maven-ci + + steps: + - name: Create GitHub deployment + uses: chrnorm/deployment-action@v2.0.5 + id: deployment + with: + token: ${{ secrets.GITHUB_TOKEN }} + ref: ${{ needs.maven-ci.outputs.tag }} + environment: "production" + environment-url: https://github.com/${{ github.repository }}/releases/tag/${{ needs.maven-ci.outputs.tag }} + + - name: Update deployment status (in_progress) + uses: chrnorm/deployment-status@v2.0.1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + state: in_progress + deployment-id: ${{ steps.deployment.outputs.deployment_id }} + + - name: Deploy + id: deployRequest + run: | + curl -i -X POST -H 'Authorization: Bearer ${{ secrets.DEPLOY_KEY }}' "${{ secrets.DEPLOY_URL }}" > response.txt + cat response.txt + + - name: Is Successful Deploy + if: ${{ success() }} + run: | + cat < comment.txt + # :white_check_mark: デプロイが完了しました + + プルリクエストがマージされたため、本番環境へのデプロイを行いました。 + バージョンは \`${{ needs.maven-ci.outputs.version }}\` です。 + 反映は本番環境の再起動後ですので、アクティブログインユーザーの同意を得て再起動するか、3時の自動再起動を待ってください。 + + https://github.com/${{ github.repository }}/releases/tag/${{ needs.maven-ci.outputs.tag }} + EOF + + gh pr comment ${{ github.event.pull_request.number }} -R ${{ github.repository }} -F comment.txt + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Is Failed Deploy + if: ${{ failure() }} + run: | + cat < comment.txt + # :x: デプロイに失敗しました + + プルリクエストがマージされたため、本番環境へのデプロイを行おうとしましたが失敗しました。 + エラー内容は以下の通りです。 + + \`\`\` + $(cat response.txt) + \`\`\` + + https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} + EOF + + gh pr comment ${{ github.event.pull_request.number }} -R ${{ github.repository }} -F comment.txt + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Is Successful Deploy + if: ${{ success() }} + uses: chrnorm/deployment-status@v2.0.1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + state: success + deployment-id: ${{ steps.deployment.outputs.deployment_id }} + + - name: Update deployment status (failure) + if: ${{ failure() }} + uses: chrnorm/deployment-status@v2.0.1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + state: failure + deployment-id: ${{ steps.deployment.outputs.deployment_id }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 75b50f114..000000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,148 +0,0 @@ -name: Release - -on: - workflow_dispatch: - pull_request_target: - branches: - - master - types: - - closed - paths: - - src/** - - pom.xml - -jobs: - release: - runs-on: ubuntu-latest - if: github.event_name == 'workflow_dispatch' || github.event.pull_request.merged == true - - outputs: - version: ${{ steps.tag_version.outputs.new_version }} - release-upload-url: ${{ steps.create_release.outputs.upload_url }} - release-html-url: ${{ steps.create_release.outputs.html_url }} - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Bump version and push tag - id: tag_version - uses: mathieudutour/github-tag-action@v6.1 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - default_bump: "minor" - custom_release_rules: "feat:minor:✨ Features,fix:patch:🐛 Fixes,docs:patch:📰 Docs,chore:patch:🎨 Chore,pref:patch:🎈 Performance improvements,refactor:patch:🧹 Refactoring,build:patch:🔍 Build,ci:patch:🔍 CI,revert:patch:⏪ Revert,style:patch:🧹 Style,test:patch:👀 Test" - - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - java-version: 17 - distribution: adopt - - - name: Cache local Maven repository - uses: actions/cache@v3 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven- - - - name: Sed Version - run: | - sed -r -i "1,/version/s#(.+?)#${{ steps.tag_version.outputs.new_version }}#" pom.xml - git diff - - - name: Set PROJECT_NAME - id: vars - run: | - echo "PROJECT_NAME=`TOP=$(git rev-parse --show-toplevel); echo ${TOP##*/}`" >> $GITHUB_OUTPUT - - - name: Build with Maven - run: mvn -B package --file pom.xml - - - name: Publish release - uses: actions/create-release@v1 - id: create_release - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: ${{ steps.tag_version.outputs.new_tag }} - release_name: ${{ steps.tag_version.outputs.new_tag }} - body: ${{ steps.tag_version.outputs.changelog }} - - - name: Upload Release Asset - uses: shogo82148/actions-upload-release-asset@v1.6.4 - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: target/*.jar - - - name: Calculate hash - working-directory: ./target - run: | - sha256sum *.jar > sha256sum.txt - - - name: Upload Release Asset sha256sum.txt - uses: shogo82148/actions-upload-release-asset@v1.6.4 - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: target/sha256sum.txt - - - name: Released comment - uses: actions/github-script@v6 - if: github.event_name == 'pull_request_target' - with: - script: | - github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: `# リリースが完了しました\n\n${{ steps.create_release.outputs.html_url }}` - }) - - deploy-production: - runs-on: ubuntu-latest - needs: release - - steps: - - name: Deploy - id: deployRequest - uses: fjogeleit/http-request-action@master - with: - url: ${{ secrets.DEPLOY_URL }} - method: 'POST' - bearerToken: ${{ secrets.DEPLOY_KEY }} - ignoreStatusCodes: '500' - timeout: 600000 - - - name: Show Response - run: echo ${{ steps.deployRequest.outputs.response }} - - - name: Is Successful Deploy - if: ${{ fromJson(steps.deployRequest.outputs.response).status == 'SUCCESSFUL' }} - uses: peter-evans/create-or-update-comment@v3 - with: - issue-number: ${{ github.event.pull_request.number }} - body: | - # :white_check_mark: デプロイが完了しました - - プルリクエストがマージされたため、本番環境へのデプロイを行いました。 - バージョンは `${{ needs.release.outputs.version }}` です。稼働中バージョンの確認は Minecraft サーバ内で `/ver MyMaid4` を実行することで確認できます。 - 反映は本番環境の再起動後ですので、アクティブログインユーザーの同意を得て再起動するか、3時の自動再起動を待ってください。 - - ${{ needs.release.outputs.release-html-url }} - - - name: Is Failed Deploy - if: ${{ fromJson(steps.deployRequest.outputs.response).status == 'ERROR' }} - uses: peter-evans/create-or-update-comment@v3 - with: - issue-number: ${{ github.event.pull_request.number }} - body: | - # :x: デプロイに失敗しました - - プルリクエストがマージされたため、本番環境へのデプロイを行おうとしましたが失敗しました。 - エラー内容は以下の通りです。 - - ``` - ${{ fromJson(steps.deployRequest.outputs.response).type }} (${{ fromJson(steps.deployRequest.outputs.response).type_ja }}) - ${{ fromJson(steps.deployRequest.outputs.response).status }} (${{ fromJson(steps.deployRequest.outputs.response).status_ja }}) - ${{ fromJson(steps.deployRequest.outputs.response).message }} - ``` diff --git a/qodana.yml b/qodana.yml deleted file mode 100644 index 9224d9d90..000000000 --- a/qodana.yml +++ /dev/null @@ -1,6 +0,0 @@ -version: 1.0 -failThreshold: 100 -profile: - name: qodana.recommended -exclude: - - name: AssignmentToStaticFieldFromInstanceMethod \ No newline at end of file