Skip to content

Commit

Permalink
Don't overwrite updates made on staging
Browse files Browse the repository at this point in the history
  • Loading branch information
andriokha committed Jun 24, 2024
1 parent 0952c29 commit 65ebb49
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 15 deletions.
16 changes: 12 additions & 4 deletions .github/actions/test-setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ inputs:
description: The branch on the site repository that mirrors the config repository.
type: string
required: true
test_site_repo_live_branch:
description: The name of the live branch (ie the one that's currently deployed).
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
Expand Down Expand Up @@ -61,6 +65,7 @@ runs:
git config --global user.name 'Test User'
git config --global user.email '[email protected]'
# Create the main branch on the config repo with two commits.
pushd remote
git checkout --orphan ${{ inputs.test_config_repo_branch }}-new
git rm -rf .
Expand All @@ -72,26 +77,29 @@ runs:
git add c e
git rm d
git commit -m "Updated"
git push origin HEAD:${{ inputs.test_config_repo_branch }} --force
git push origin HEAD:${{ inputs.test_config_repo_branch }}
git checkout ${{ inputs.test_config_repo_branch }}
git reset --hard origin/${{ inputs.test_config_repo_branch }}
popd
# Add the mock site with current config to staging and main.
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 branch ${{ inputs.test_site_repo_live_branch }}
git push origin ${{ inputs.test_site_repo_live_branch }}
# Add an extra commit to staging only with an additional config change.
echo modified > config/sync/e
git add config/sync
git commit -m "Simulate updating config during development"
git push origin HEAD:${{ inputs.test_site_repo_pr_branch_base }} --force
git push origin HEAD:${{ inputs.test_site_repo_pr_branch_base }}
git checkout ${{ inputs.test_site_repo_pr_branch_base }}
git reset --hard origin/${{ inputs.test_site_repo_pr_branch_base }}
Expand Down
13 changes: 9 additions & 4 deletions .github/actions/test-teardown/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ runs:
steps:
- name: Tear down for test
shell: bash
working-directory: test/site
working-directory: test
run: |
set -x
# 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/'/}
for directory in remote site; do
cd "$directory"
git for-each-ref "refs/remotes/origin/${{ inputs.branch_prefix }}*" --format '%(refname:short)' | while read refname; do
branch=${refname//'origin/'/}
git push -d origin $branch
echo "Deleted $directory branch '$branch'."
done
done
29 changes: 23 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:
env:
test_config_repo_branch: "${{ github.job }}-main"
test_site_repo_config_branch: "${{ github.job }}-config-only"
test_site_repo_live_branch: "${{ github.job }}-main"
test_site_repo_pr_branch: "${{ github.job }}-automatic-config-export"
test_site_repo_pr_branch_base: "${{ github.job }}-staging"
steps:
Expand All @@ -54,6 +55,7 @@ jobs:
test_site_repo: ${{ vars.TEST_SITE_REPO }}
test_site_repo_token: ${{ secrets.TEST_SITE_REPO_TOKEN }}
test_site_repo_config_branch: ${{ env.test_site_repo_config_branch }}
test_site_repo_live_branch: ${{ env.test_site_repo_live_branch }}
test_site_repo_pr_branch: ${{ env.test_site_repo_pr_branch }}
test_site_repo_pr_branch_base: ${{ env.test_site_repo_pr_branch_base }}

Expand All @@ -65,6 +67,7 @@ jobs:
site_repo: ${{ vars.TEST_SITE_REPO }}
site_repo_token: ${{ secrets.TEST_SITE_REPO_TOKEN }}
site_repo_config_branch: ${{ env.test_site_repo_config_branch }}
site_repo_live_branch: ${{ env.test_site_repo_live_branch }}
site_repo_pr_branch: ${{ env.test_site_repo_pr_branch }}
site_repo_pr_branch_base: ${{ env.test_site_repo_pr_branch_base }}

Expand Down Expand Up @@ -104,6 +107,7 @@ jobs:
test_site_repo_config_branch: "${{ github.job }}-config-only"
test_site_repo_pr_branch: "${{ github.job }}-automatic-config-export"
test_site_repo_pr_branch_base: "${{ github.job }}-staging"
test_site_repo_live_branch: "${{ github.job }}-main"
steps:

- uses: actions/checkout@v4
Expand All @@ -119,6 +123,7 @@ jobs:
test_site_repo: ${{ vars.TEST_SITE_REPO }}
test_site_repo_token: ${{ secrets.TEST_SITE_REPO_TOKEN }}
test_site_repo_config_branch: ${{ env.test_site_repo_config_branch }}
test_site_repo_live_branch: ${{ env.test_site_repo_live_branch }}
test_site_repo_pr_branch: ${{ env.test_site_repo_pr_branch }}
test_site_repo_pr_branch_base: ${{ env.test_site_repo_pr_branch_base }}

Expand All @@ -134,12 +139,17 @@ jobs:
cp * "$tmp_dir"
git push origin HEAD
git checkout ${{ env.test_site_repo_pr_branch_base }}
rm config/sync/*
cp -r "$tmp_dir"/* config/sync
git add .
git commit --amend -m "Update"
git push origin HEAD --force
git checkout ${{ inputs.test_site_repo_live_branch }}
git rm config/sync/*
mv "$tmp_dir"/* config/sync
git add config/sync
git commit --amend
git push --force
git checkout ${{ inputs.test_site_repo_pr_branch_base }}
echo modified > config/sync/e
git commit -m "Simulate updating config during development"
git push --force
- uses: ./test/update-config
with:
Expand All @@ -149,6 +159,7 @@ jobs:
site_repo: ${{ vars.TEST_SITE_REPO }}
site_repo_token: ${{ secrets.TEST_SITE_REPO_TOKEN }}
site_repo_config_branch: ${{ env.test_site_repo_config_branch }}
site_repo_live_branch: ${{ env.test_site_repo_live_branch }}
site_repo_pr_branch: ${{ env.test_site_repo_pr_branch }}
site_repo_pr_branch_base: ${{ env.test_site_repo_pr_branch_base }}

Expand Down Expand Up @@ -212,6 +223,7 @@ jobs:
env:
test_config_repo_branch: "${{ github.job }}-main"
test_site_repo_config_branch: "${{ github.job }}-config-only"
test_site_repo_live_branch: "${{ github.job }}-main"
test_site_repo_pr_branch: "${{ github.job }}-automatic-config-export"
test_site_repo_pr_branch_base: "${{ github.job }}-staging"
steps:
Expand All @@ -229,6 +241,7 @@ jobs:
test_site_repo: ${{ vars.TEST_SITE_REPO }}
test_site_repo_token: ${{ secrets.TEST_SITE_REPO_TOKEN }}
test_site_repo_config_branch: ${{ env.test_site_repo_config_branch }}
test_site_repo_live_branch: ${{ env.test_site_repo_live_branch }}
test_site_repo_pr_branch: ${{ env.test_site_repo_pr_branch }}
test_site_repo_pr_branch_base: ${{ env.test_site_repo_pr_branch_base }}

Expand Down Expand Up @@ -273,6 +286,7 @@ jobs:
site_repo: ${{ vars.TEST_SITE_REPO }}
site_repo_token: ${{ secrets.TEST_SITE_REPO_TOKEN }}
site_repo_config_branch: ${{ env.test_site_repo_config_branch }}
site_repo_live_branch: ${{ env.test_site_repo_live_branch }}
site_repo_pr_branch: ${{ env.test_site_repo_pr_branch }}
site_repo_pr_branch_base: ${{ env.test_site_repo_pr_branch_base }}

Expand Down Expand Up @@ -311,6 +325,7 @@ jobs:
test_site_repo_config_branch: "${{ github.job }}-config-only"
test_site_repo_pr_branch: "${{ github.job }}-automatic-config-export"
test_site_repo_pr_branch_base: "${{ github.job }}-staging"
test_site_repo_live_branch: "${{ github.job }}-main"
steps:

- uses: actions/checkout@v4
Expand All @@ -326,6 +341,7 @@ jobs:
test_site_repo: ${{ vars.TEST_SITE_REPO }}
test_site_repo_token: ${{ secrets.TEST_SITE_REPO_TOKEN }}
test_site_repo_config_branch: ${{ env.test_site_repo_config_branch }}
test_site_repo_live_branch: "${{ github.job }}-main"
test_site_repo_pr_branch: ${{ env.test_site_repo_pr_branch }}
test_site_repo_pr_branch_base: ${{ env.test_site_repo_pr_branch_base }}

Expand All @@ -348,6 +364,7 @@ jobs:
site_repo: ${{ vars.TEST_SITE_REPO }}
site_repo_token: ${{ secrets.TEST_SITE_REPO_TOKEN }}
site_repo_config_branch: ${{ env.test_site_repo_config_branch }}
site_repo_live_branch: ${{ env.test_site_repo_live_branch }}
site_repo_pr_branch: ${{ env.test_site_repo_pr_branch }}
site_repo_pr_branch_base: ${{ env.test_site_repo_pr_branch_base }}

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ with:
# The branch on the site repository that mirrors the config repository.
# Default: config-only
site_repo_config_branch: ''
# The name of the live branch (ie the one that's currently deployed).
# Default: main
site_repo_live_branch: ''

# The name of the topic branch to create on the site repository with config
# changes.
Expand Down
7 changes: 6 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ inputs:
type: string
required: true
default: config-only
site_repo_live_branch:
description: The name of the live branch (ie the one that's currently deployed).
type: string
default: main
required: true
site_repo_pr_branch:
description: The name of the topic branch to create on the site repository with config changes.
type: string
Expand Down Expand Up @@ -167,7 +172,7 @@ runs:
set -eu
source_branch=${{ inputs.site_repo_pr_branch }}
if ! git show-branch remotes/origin/${{ inputs.site_repo_pr_branch }} &> /dev/null; then
git branch ${{ inputs.site_repo_pr_branch }} origin/${{ inputs.site_repo_pr_branch_base }}
git branch ${{ inputs.site_repo_pr_branch }} origin/${{ inputs.site_repo_live_branch }}
source_branch=${{ inputs.site_repo_pr_branch_base }}
fi
git checkout ${{ inputs.site_repo_pr_branch }}
Expand Down
3 changes: 3 additions & 0 deletions workflow-templates/update-config-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ name: Check for config updates
# - CONFIG_REPO: The GitHub config repo, eg. MyOrg/MySiteConfig.
# - SITE_REPO_PR_BRANCH_BASE: (optional) The branch from which the config topic
# branch will be made for the PR; defaults to 'staging'.
# - SITE_REPO_LIVE_BRANCH: (optional) The name of the live branch (ie the one
# that's currently deployed).
# - GITHUB_NOTIFY: (optional) A space-separated list of github users including
# '@' to ping on a new PR, eg. '@andy @becca'.

Expand All @@ -38,3 +40,4 @@ jobs:
config_repo_token: ${{ secrets.CONFIG_REPO_TOKEN }}
github_notify: ${{ vars.GITHUB_NOTIFY }}
site_repo_pr_branch_base: ${{ vars.SITE_REPO_PR_BRANCH_BASE || 'staging' }}
site_repo_live_branch: ${{ vars.SITE_REPO_LIVE_BRANCH || 'main' }}

0 comments on commit 65ebb49

Please sign in to comment.