Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
andriokha committed Jun 24, 2024
0 parents commit 5d496fb
Show file tree
Hide file tree
Showing 9 changed files with 994 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .github/actions/test-assertions/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Common test assertions
description: Provides common test assertions for all tests
# TBH this also has side-effects, could do with a different name.

inputs:
test_config_repo:
description: The GitHub config repo for use with the test.
type: string
required: true
test_config_repo_token:
description: A token with write access to the test config repo.
type: string
required: true
test_config_repo_branch:
description: The main branch on the config repository.
type: string
required: true
test_site_repo_config_branch:
description: The branch on the site repository that mirrors the config repository.
type: string
required: true
test_site_repo:
description: The GitHub site repo for use with the test.
type: string
required: true
test_site_repo_token:
description: A token with write access to the test site repo.
type: string
required: true

runs:
using: composite
steps:
- uses: ./test/update-config/.github/actions/test-checkout
with:
test_config_repo: ${{ inputs.test_config_repo }}
test_config_repo_token: ${{ inputs.test_config_repo_token }}
test_site_repo: ${{ inputs.test_site_repo }}
test_site_repo_token: ${{ inputs.test_site_repo_token }}

- name: Assert the state after running the action
shell: sh
working-directory: test
run: |
# Assert the state after running the action
set -eu
if [[ "$(git -C remote rev-parse origin/${{ inputs.test_config_repo_branch }})" != "$(git -C site rev-parse origin/${{ inputs.test_site_repo_config_branch }})" ]]; then
echo "**TEST FAILURE:** The Drupal site repo's config-only branch wasn't in sync with the config repo's main branch." >> "$GITHUB_STEP_SUMMARY"
exit 1
fi
37 changes: 37 additions & 0 deletions .github/actions/test-checkout/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Checkout repos
description: Checkout the test site and config repos

inputs:
test_config_repo:
description: The GitHub config repo for use with the test.
type: string
required: true
test_config_repo_token:
description: A token with write access to the test config repo.
type: string
required: true
test_site_repo:
description: The GitHub site repo for use with the test.
type: string
required: true
test_site_repo_token:
description: A token with write access to the test site repo.
type: string
required: true

runs:
using: composite
steps:
- uses: actions/checkout@v4
with:
repository: ${{ inputs.test_site_repo }}
token: ${{ inputs.test_site_repo_token }}
path: test/site
fetch-depth: 0

- uses: actions/checkout@v4
with:
repository: ${{ inputs.test_config_repo }}
token: ${{ inputs.test_config_repo_token }}
path: test/remote
fetch-depth: 0
93 changes: 93 additions & 0 deletions .github/actions/test-setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Setup for test
description: Prepares test repos for automated testing.

inputs:
test_config_repo:
description: The GitHub config repo for use with the test.
type: string
required: true
test_config_repo_token:
description: A token with write access to the test config repo.
type: string
required: true
test_config_repo_branch:
description: The main branch on the config repository.
type: string
required: true
test_site_repo:
description: The GitHub site repo for use with the test.
type: string
required: true
test_site_repo_token:
description: A token with write access to the test site repo.
type: string
required: true
test_site_repo_config_branch:
description: The branch on the site repository that mirrors the config repository.
type: string
required: true
test_site_repo_pr_branch:
description: The name of the topic branch to create on the site repository with config changes.
type: string
required: true
test_site_repo_pr_branch_base:
description: The branch on the site repository from which to create the PR branch.
type: string
required: true

# DO I WANT?
branch_prefix:
description: The prefix used for test branches.
type: string
required: true

runs:
using: composite
steps:

- uses: ./test/update-config/.github/actions/test-checkout
with:
test_config_repo: ${{ inputs.test_config_repo }}
test_config_repo_token: ${{ inputs.test_config_repo_token }}
test_site_repo: ${{ inputs.test_site_repo }}
test_site_repo_token: ${{ inputs.test_site_repo_token }}

- name: Setup for test
shell: bash
working-directory: test
run: |
# Setup for test
set -eu
git config --global user.name 'Test User'
git config --global user.email '[email protected]'
pushd remote
git checkout --orphan ${{ inputs.test_config_repo_branch }}-new
git rm -rf .
touch c d
git add .
git commit -m "Add initial mock config"
echo modified > c
touch e
git add c e
git rm d
git commit -m "Updated"
git push origin HEAD:${{ inputs.test_config_repo_branch }} --force
git checkout ${{ inputs.test_config_repo_branch }}
git reset --hard origin/${{ inputs.test_config_repo_branch }}
popd
pushd site
git checkout --orphan ${{ inputs.test_site_repo_pr_branch_base }}-new
git rm -rf .
mkdir -p a z config/sync
cp -r ../remote/* config/sync
touch {a,z}/.gitkeep b
git config user.name 'Test User'
git config user.email '[email protected]'
git add .
git commit -m "Add mock Drupal site"
git push origin HEAD:${{ inputs.test_site_repo_pr_branch_base }} --force
git checkout ${{ inputs.test_site_repo_pr_branch_base }}
git reset --hard origin/${{ inputs.test_site_repo_pr_branch_base }}
popd
21 changes: 21 additions & 0 deletions .github/actions/test-teardown/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Tear down for test
description: Makes any necessary changes to clean up after running a test

inputs:
branch_prefix:
description: The prefix used for test branches.
type: string
required: true

runs:
using: composite
steps:
- name: Tear down for test
shell: bash
working-directory: test/site
run: |
# Tear down for test
set -eu
git for-each-ref "refs/remotes/origin/${{ inputs.branch_prefix }}*" --format '%(refname:short)' | while read refname
do git push -d origin ${refname//'origin/'/}
done
Loading

0 comments on commit 5d496fb

Please sign in to comment.