|
# Copyright 2019 Google LLC |
|
# |
|
# Licensed 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 |
|
# |
|
# https://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. |
|
|
|
# Edits the HEAD commit if it is tagged with the Copybara tag to use the |
|
# submodule state specified in SUBMODULE_VERSIONS.txt and merge from the |
|
# specified commit. |
|
# WARNING: rewrites history! |
|
|
|
name: Fixup Copybara |
|
|
|
on: |
|
push: |
|
branches: |
|
# Do not add this to human branches like main. It rewrites history! |
|
- google |
|
|
|
env: |
|
COPYBARA_TAG: "COPYBARA_INTEGRATE_REVIEW" |
|
UPSTREAM_REMOTE: origin |
|
|
|
jobs: |
|
fixup: |
|
runs-on: ubuntu-18.04 |
|
steps: |
|
- name: Checking out repository |
|
uses: actions/checkout@v2 |
|
with: |
|
token: ${{ secrets.GITHUB_WRITE_ACCESS_TOKEN }} |
|
# Get all history. We're force-pushing here and will otherwise drop |
|
# all the branch history. This takes a whopping 2 seconds. I think |
|
# we'll live. |
|
fetch-depth: 0 |
|
- name: Setting git config |
|
run: | |
|
git config --local user.email "iree-github-actions-bot@google.com" |
|
git config --local user.name "Copybara Fixup Action" |
|
- name: Running fixer script |
|
run: | |
|
./scripts/git/fix_copybara_export.sh |
|
- name: Checking for a change |
|
run: | |
|
echo "commit_amended=false" >> $GITHUB_ENV |
|
if [[ "$(git rev-parse HEAD)" != "${GITHUB_SHA?}" ]]; then |
|
echo "commit_amended=true" >> $GITHUB_ENV |
|
fi |
|
- name: Pushing changes |
|
if: env.commit_amended == 'true' |
|
run: git push -f origin ${{ github.ref }} |
|
|
|
check_submodules: |
|
runs-on: ubuntu-18.04 |
|
steps: |
|
- name: Checking out repository |
|
uses: actions/checkout@v2 |
|
- name: Checking submodules |
|
run: ./scripts/git/submodule_versions.py check |
|
|
|
check_copybara_tag: |
|
runs-on: ubuntu-18.04 |
|
steps: |
|
- name: Checking out repository |
|
uses: actions/checkout@v2 |
|
- name: Checking for Copybara tag |
|
run: | |
|
if git log --format=%B -n 1 HEAD | grep -q "${COPYBARA_TAG}"; then |
|
echo "Commit contains Copybara tag" |
|
exit 1 |
|
fi |