From a982c4f5de84f22e13f012dc6f8a2e01fce11998 Mon Sep 17 00:00:00 2001 From: mchuangatmp <85254535+mchuangatmp@users.noreply.github.com> Date: Mon, 27 Jun 2022 09:21:08 -0700 Subject: [PATCH] fix: switch from pull_request_target to pull_request (#85) --- .github/workflows/dependabot-automerge.yml | 57 +++++++++++++++++++ .github/workflows/pull-request-app-checks.yml | 18 +++--- .github/workflows/pull-request.yml | 42 ++++++-------- .github/workflows/push.yml | 11 ---- .../higgs-shop-sample-app/build.gradle.kts | 2 +- 5 files changed, 84 insertions(+), 46 deletions(-) create mode 100644 .github/workflows/dependabot-automerge.yml delete mode 100644 .github/workflows/push.yml diff --git a/.github/workflows/dependabot-automerge.yml b/.github/workflows/dependabot-automerge.yml new file mode 100644 index 0000000..4326e4c --- /dev/null +++ b/.github/workflows/dependabot-automerge.yml @@ -0,0 +1,57 @@ +name: "Dependabot Automerge" + +on: + workflow_run: + workflows: ["Build and Test"] + types: + - completed + +jobs: + automerge-dependabot: + name: "Automerge Dependabot PR" + if: > + ${{ github.event.workflow_run.event == 'pull_request' && + github.event.workflow_run.conclusion == 'success' && + github.actor == 'dependabot[bot]' }} + env: + GITHUB_TOKEN: ${{ secrets.MP_SEMANTIC_RELEASE_BOT }} + GIT_AUTHOR_NAME: mparticle-automation + GIT_AUTHOR_EMAIL: developers@mparticle.com + GIT_COMMITTER_NAME: mparticle-automation + GIT_COMMITTER_EMAIL: developers@mparticle.com + runs-on: ubuntu-latest + steps: + - name: 'Download artifact' + uses: actions/github-script@v3.1.0 + with: + script: | + var artifacts = await github.actions.listWorkflowRunArtifacts({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: ${{ github.event.workflow_run.id }}, + }); + var matchArtifact = artifacts.data.artifacts.filter((artifact) => { + return artifact.name == "pr" + })[0]; + var download = await github.actions.downloadArtifact({ + owner: context.repo.owner, + repo: context.repo.repo, + artifact_id: matchArtifact.id, + archive_format: 'zip', + }); + var fs = require('fs'); + fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data)); + - run: unzip pr.zip + - name: 'Automerge PR' + uses: actions/github-script@v3 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + var fs = require('fs'); + var issue_number = Number(fs.readFileSync('./NR')); + await github.pulls.merge({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: issue_number, + merge_method: 'rebase' + }); \ No newline at end of file diff --git a/.github/workflows/pull-request-app-checks.yml b/.github/workflows/pull-request-app-checks.yml index 8502a99..17de2ad 100644 --- a/.github/workflows/pull-request-app-checks.yml +++ b/.github/workflows/pull-request-app-checks.yml @@ -19,15 +19,15 @@ jobs: uses: actions/checkout@v2 with: submodules: recursive -# - name: "Create Path Triggers" -# uses: dorny/paths-filter@v2 -# id: changes -# with: -# base: main -# ref: ${{ github.head_ref }} -# filters: | -# sample-app: -# - '${{ inputs.app_relative_path }}/**' + # - name: "Create Path Triggers" + # uses: dorny/paths-filter@v2 + # id: changes + # with: + # base: main + # ref: ${{ github.head_ref }} + # filters: | + # sample-app: + # - '${{ inputs.app_relative_path }}/**' # - name: "Cancel workflow" # if: steps.changes.outputs.sample-app != 'true' # uses: andymckay/cancel-action@0.2 diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index dcb674c..64e72fb 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -1,39 +1,31 @@ -name: "Pull Request Checks" +name: "Build and Test" -on: [ pull_request_target ] +on: [ push, workflow_dispatch, pull_request ] jobs: higgs-shop-sample-app: name: "Check Higgs Shop Sample App" - uses: mParticle/mparticle-workflows/.github/workflows/android-sample-app-pull-request.yml@stable + uses: mParticle/mparticle-android-sample-apps/.github/workflows/pull-request-app-checks.yml@main with: app_relative_path: "core-sdk-samples/higgs-shop-sample-app" automerge-dependabot: - name: "Automerge Dependabot PR" + name: "Save PR Number for Dependabot Automerge" needs: [ higgs-shop-sample-app ] - if: ${{ github.actor == 'dependabot[bot]' }} - env: - GITHUB_TOKEN: ${{ secrets.MP_SEMANTIC_RELEASE_BOT }} - GIT_AUTHOR_NAME: mparticle-bot - GIT_AUTHOR_EMAIL: developers@mparticle.com - GIT_COMMITTER_NAME: mparticle-bot - GIT_COMMITTER_EMAIL: developers@mparticle.com + if: ${{ github.actor == 'dependabot[bot]' && github.event_name == 'pull_request' }} runs-on: ubuntu-latest steps: - - name: "Rebase Dependabot PR" - uses: actions/github-script@v3 + - name: "Checkout PR branch" + uses: actions/checkout@v2 with: - script: | - github.pulls.merge({ - owner: context.repo.owner, - repo: context.payload.repository.name, - pull_number: context.payload.pull_request.number, - merge_method: 'rebase' - }); - rebase-development: - name: "Rebase Development onto Dependabot Branch" - needs: [ automerge-dependabot ] - if: ${{ github.actor == 'dependabot[bot]' }} - uses: mParticle/mparticle-workflows/.github/workflows/dependabot-rebase-development.yml@stable + submodules: recursive + fetch-depth: 0 + - name: "Save Pull Request Number" + run: | + mkdir -p ./pr + echo ${{ github.event.number }} > ./pr/NR + - uses: actions/upload-artifact@v2 + with: + name: pr + path: pr/ diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml deleted file mode 100644 index 0b9d73e..0000000 --- a/.github/workflows/push.yml +++ /dev/null @@ -1,11 +0,0 @@ -name: "Push Checks" - -on: [ push, workflow_dispatch ] - -jobs: - - higgs-shop-sample-app: - name: "Check Higgs Shop Sample App" - uses: mParticle/mparticle-workflows/.github/workflows/android-sample-app-push.yml@stable - with: - app_relative_path: "core-sdk-samples/higgs-shop-sample-app" \ No newline at end of file diff --git a/core-sdk-samples/higgs-shop-sample-app/build.gradle.kts b/core-sdk-samples/higgs-shop-sample-app/build.gradle.kts index 7117261..3f17a6a 100644 --- a/core-sdk-samples/higgs-shop-sample-app/build.gradle.kts +++ b/core-sdk-samples/higgs-shop-sample-app/build.gradle.kts @@ -5,7 +5,7 @@ buildscript { mavenCentral() } dependencies { - classpath("com.android.tools.build:gradle:7.1.2") + classpath("com.android.tools.build:gradle:7.2.1") classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10") } }