| # Licensed to the Apache Software Foundation (ASF) under one |
| # or more contributor license agreements. See the NOTICE file |
| # distributed with this work for additional information |
| # regarding copyright ownership. The ASF licenses this file |
| # to you under the Apache License, Version 2.0 (the |
| # "License"); you may not use this file except in compliance |
| # with the License. You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, |
| # software distributed under the License is distributed on an |
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| # KIND, either express or implied. See the License for the |
| # specific language governing permissions and limitations |
| # under the License. |
| |
| name: 'Setup action' |
| description: 'Setup repository and configure the required steps' |
| inputs: |
| comment_phrase: |
| description: "The comment phrase in the PR" |
| required: true |
| github_token: |
| description: "The GitHub token" |
| required: true |
| github_job: |
| description: "The GitHub job" |
| required: false |
| default: '' |
| |
| runs: |
| using: composite |
| steps: |
| - name: Check if the phrase is correct |
| shell: bash |
| if: github.event_name == 'issue_comment' && github.event.comment.body != inputs.comment_phrase |
| run: | |
| echo "The comment $PHRASE does not match the phrase for this instance: ${{ inputs.comment_phrase }}. Exiting." |
| exit 1 |
| env: |
| PHRASE: "${{ github.event.comment.body }}" |
| - name: Check out repository code if pull request commit |
| shell: bash |
| if: ${{ github.event_name == 'pull_request_target' }} |
| run: | |
| # GitHub will automatically generate a merge commit when there are no merge conflicts. |
| # We first try to check that out, and fall back to checking out the tip of the pull request branch. |
| git fetch --depth=1 origin +refs/pull/${{ github.event.number }}/merge:refs/remotes/pull/${{ github.event.number }}/merge || \ |
| git fetch --depth=1 origin +refs/pull/${{ github.event.number }}/head:refs/remotes/pull/${{ github.event.number }}/head |
| git checkout pull/${{ github.event.number }}/merge || git checkout pull/${{ github.event.number }}/head |
| - name: Check out repository code if comment phrase |
| shell: bash |
| if: ${{ github.event.comment.body == inputs.comment_phrase }} |
| run: | |
| # GitHub will automatically generate a merge commit when there are no merge conflicts. |
| # We first try to check that out, and fall back to checking out the tip of the pull request branch. |
| git fetch --depth=1 origin +refs/pull/${{ github.event.issue.number }}/merge:refs/remotes/pull/${{ github.event.issue.number }}/merge || \ |
| git fetch --depth=1 origin +refs/pull/${{ github.event.issue.number }}/head:refs/remotes/pull/${{ github.event.issue.number }}/head |
| git checkout pull/${{ github.event.issue.number }}/merge || git checkout pull/${{ github.event.issue.number }}/head |
| - name: Rerun if comment phrase |
| if: ${{ github.event.comment.body == inputs.comment_phrase }} |
| uses: ./.github/actions/rerun-job-action |
| with: |
| github_token: ${{ inputs.github_token }} |
| github_job: ${{ inputs.github_job || github.job }} |
| github_repository: ${{ github.repository }} |
| github_current_run_id: ${{ github.run_id }} |
| pull_request_url: ${{ github.event.issue.pull_request.url }} |
| ## Used for jobs that spawn docker containers and need to mount gcloud config directory |
| - name: expose gcloud path |
| shell: bash |
| run: | |
| echo KUBELET_GCLOUD_CONFIG_PATH=/var/lib/kubelet/pods/$POD_UID/volumes/kubernetes.io~empty-dir/gcloud >> $GITHUB_ENV |