Do not merge: Ambassador Features Staging #100
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: pre-commit | |
on: | |
pull_request: | |
jobs: | |
pre-commit: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Set up Docker Compose | |
run: | | |
sudo curl -L "https://github.com/docker/compose/releases/download/v2.23.3/docker-compose-$(uname -s)-$(uname -m)" \ | |
-o /usr/local/bin/docker-compose | |
sudo chmod +x /usr/local/bin/docker-compose | |
- name: Get number of PR commits + 1 | |
run: echo "PR_FETCH_DEPTH=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> $GITHUB_ENV | |
- uses: unstructuredstudio/zubhub/.github/actions/checkout@master | |
with: | |
ref: ${{ github.head_ref }} | |
fetch_depth: ${{ env.PR_FETCH_DEPTH }} | |
- name: Undo all PR commits and keep changes in staging area | |
run: | | |
# some of our pre-commit hooks uses `git diff --name-only --cached` to get the list | |
# changed files. This step undos the most recent commits in the checkout, | |
# leaving the changes in the staging area for our `git diff ..` to find. | |
git reset --soft HEAD~$(( ${{ env.PR_FETCH_DEPTH }} - 1 )) | |
- run: | | |
# Running pre-commit on the following files: | |
target_files=$(git diff --name-only --cached) | |
echo "Running pre-commit on the following files:" | |
echo "$target_files" | |
- uses: actions/setup-python@v3 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 16 | |
cache: 'npm' | |
cache-dependency-path: zubhub_frontend/zubhub/package-lock.json | |
- run: npm ci --prefix ./zubhub_frontend/zubhub/ | |
- uses: pre-commit/[email protected] | |
id: pre_commit | |
with: | |
# by default pre-commit/action runs `pre-commit run --all-files ...`. | |
# Here we use empty extra_args to force it to run `pre-commit run ...` instead. | |
# this is important because we want it to only run on the files that have changed | |
extra_args: | |
continue-on-error: true | |
- name: Success comment | |
if: steps.pre_commit.outcome == 'success' | |
uses: unstructuredstudio/zubhub/.github/actions/comment_action@master | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
issue_number: ${{ github.event.pull_request.number }} | |
owner: ${{ github.repository_owner }} | |
repo: ${{ github.event.repository.name }} | |
message: | | |
All pre-commit checks passed ✅✅✅ | |
- name: Failure comment | |
if: steps.pre_commit.outcome != 'success' | |
uses: unstructuredstudio/zubhub/.github/actions/comment_action@master | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
issue_number: ${{ github.event.pull_request.number }} | |
owner: ${{ github.repository_owner }} | |
repo: ${{ github.event.repository.name }} | |
message: | | |
pre-commit checks failed ❌❌❌ | |
make sure you have pre-commit set up locally (see the README.md for instructions). | |
If you have set up pre-commit locally, you may need to undo this commit and | |
run "pre-commit" locally to see what the errors are. | |
- name: Failure exit | |
if: steps.pre_commit.outcome != 'success' | |
run: exit 1 |