Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration Test Nonexistent Repo #250

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/integration_tests/compliant_repo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash

set -euo pipefail

# Integration test to ensure CI fails when a non-existent repository is added

# set git credentials
git config user.name dfinity
git config user.email dfinity@dfinity.org

# create new branch
git checkout -b integration-test-2-$RUN_NUMBER

# add compliant repository to for testing
echo "test-compliant-repository" >> open-repositories.txt
sort open-repositories.txt -o open-repositories.txt
git add open-repositories.txt
git commit -m 'add compliant repository'

# create pull request
git push --set-upstream origin integration-test-2-$RUN_NUMBER
gh pr create --draft --title "Integration Test Compliant Repo" --body "generated by integration test from branch $GITHUB_HEAD_REF"

commit_sha="$(git rev-parse HEAD)"

# check CI
while true
do
sleep 3
status=$(curl -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $GH_TOKEN" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/dfinity/repositories-open-to-contributions/actions/runs?branch=integration-test-2-$RUN_NUMBER | jq '[.workflow_runs[] | select(.name=="Check New Repo")] | map(select(.head_sha=='\"$commit_sha\"')) | max_by(.run_number) | .status')
echo $status
if [[ "$status" == '"completed"' ]]
then
break
fi
done
result=$(curl -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $GH_TOKEN" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/dfinity/repositories-open-to-contributions/actions/runs?branch=integration-test-2-$RUN_NUMBER | jq '[.workflow_runs[] | select(.name=="Check New Repo")] | map(select(.head_sha=='\"$commit_sha\"')) | max_by(.run_number) | .conclusion')
if [[ $result == '"success"' ]]
then echo "test passed"
else
echo "test failed, expected Check New Repo to result in success but got $result" >&2
git push origin -d integration-test-2-$RUN_NUMBER
exit 1
fi

# delete branch and close PR
git push origin -d integration-test-2-$RUN_NUMBER
14 changes: 8 additions & 6 deletions .github/integration_tests/nonexistent_repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,39 @@ git config user.name dfinity
git config user.email dfinity@dfinity.org

# create new branch
git checkout -b integration-test-1
git checkout -b integration-test-1-$RUN_NUMBER

# add a fake repository
echo "fake-repository" >> open-repositories.txt
sort open-repositories.txt -o open-repositories.txt
git add open-repositories.txt
git commit -m 'add nonexistent repository'

# create pull request
git push --set-upstream origin integration-test-1
gh pr create --draft --title "Integration Test 1" --body "generated by integration test from branch $GITHUB_HEAD_REF"
git push --set-upstream origin integration-test-1-$RUN_NUMBER
gh pr create --draft --title "Integration Test Nonexistent Repo" --body "generated by integration test from branch $GITHUB_HEAD_REF"

commit_sha="$(git rev-parse HEAD)"

# check CI
while true
do
sleep 3
status=$(curl -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $GH_TOKEN" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/dfinity/repositories-open-to-contributions/actions/runs?branch=integration-test-1 | jq '[.workflow_runs[] | select(.name=="Check New Repo")] | map(select(.head_sha=='\"$commit_sha\"')) | max_by(.run_number) | .status')
status=$(curl -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $GH_TOKEN" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/dfinity/repositories-open-to-contributions/actions/runs?branch=integration-test-1-$RUN_NUMBER| jq '[.workflow_runs[] | select(.name=="Check New Repo")] | map(select(.head_sha=='\"$commit_sha\"')) | max_by(.run_number) | .status')
echo $status
if [[ $status == '"completed"' ]]
then
break
fi
done
result=$(curl -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $GH_TOKEN" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/dfinity/repositories-open-to-contributions/actions/runs?branch=integration-test-1 | jq '[.workflow_runs[] | select(.name=="Check New Repo")] | map(select(.head_sha=='\"$commit_sha\"')) | max_by(.run_number) | .conclusion')
result=$(curl -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $GH_TOKEN" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/dfinity/repositories-open-to-contributions/actions/runs?branch=integration-test-1-$RUN_NUMBER| jq '[.workflow_runs[] | select(.name=="Check New Repo")] | map(select(.head_sha=='\"$commit_sha\"')) | max_by(.run_number) | .conclusion')
if [[ $result == '"failure"' ]]
then echo "test passed"
else
echo "test failed, expected Check New Repo to result in failure but got $result" >&2
git push origin -d integration-test-1-$RUN_NUMBER
exit 1
fi

# delete branch and close PR
git push origin -d integration-test-1
git push origin -d integration-test-1-$RUN_NUMBER
50 changes: 50 additions & 0 deletions .github/workflows/compliance_integration_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Workflow to run integration tests
# Checks that check_new_repo workflow works as expected

name: Compliance Integration Tests

on:
push:
branches-ignore:
- integration-test-*
paths:
- .github/custom_python_actions/check_compliance.py
- .github/custom_python_actions/check_external_contrib.py
- .github/tests/test_compliance_checks.py
- .github/tests/test_check_external_contrib.py
- .github/workflows/check_existing_repo.yml
- .github/workflows/check_new_repo.yml
- .github/workflows/compliance_integration_tests.yml
- .github/integration_tests/compliant_repo.sh
- .github/integration_tests/nonexistent_repo.sh
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
compliance-integration-test-nonexistant-repo:
name: Integration Test Nonexistant repo
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Integration Test
run: |
${GITHUB_WORKSPACE}/.github/integration_tests/nonexistent_repo.sh
env:
GH_TOKEN: ${{ secrets.INTEGRATION_TESTS_RUN_WORKFLOW }}
RUN_NUMBER: ${{ github.run_number }}

compliance-integration-test-compliant-repo:
name: Integration Test Compliant Repo
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Integration Test
run: |
${GITHUB_WORKSPACE}/.github/integration_tests/compliant_repo.sh
env:
GH_TOKEN: ${{ secrets.INTEGRATION_TESTS_RUN_WORKFLOW }}
RUN_NUMBER: ${{ github.run_number }}
32 changes: 0 additions & 32 deletions .github/workflows/integration_tests.yml

This file was deleted.

1 change: 1 addition & 0 deletions open-repositories.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dfx-extensions
examples
exchange-rate-canister
experimental-minting-tool
fake-repository
feedback
getting-started
hardware-wallet-cli
Expand Down
Loading