(A) Config Sync — Run backups #130
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: (A) Config Sync — Run backups | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '20 19 * * 3' | |
permissions: | |
pull-requests: write | |
contents: write | |
jobs: | |
sync: | |
name: Grab live db and add un-synced files | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/[email protected] | |
- uses: ./.github/actions/dingorunner | |
env: | |
runner: bkup | |
terminus_api: ${{ secrets.TERMINUS_API }} | |
SSH_PRIVATE_KEY: ${{ secrets.PANTHEON_DEPLOY_KEY}} | |
site_name: ${{ secrets.TERMINUS_SITE_NAME }} | |
env: live | |
- id: Lando | |
uses: necyberteam/amp_lando_start@v2 | |
with: | |
DATABASE: '' | |
GH_TOKEN_REPO: ${{ secrets.GH_TOKEN_REPO }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Config diff | |
run: | | |
git remote set-url origin https://$username:[email protected]/necyberteam/cyberteam_drupal.git | |
git config --global user.email "$username" | |
git config --global user.name "$email" | |
git fetch | |
current_branch=main | |
git checkout $(git rev-list --tags --max-count=1) | |
git checkout $current_branch | |
git branch | |
date=$(date '+%y%m%d') | |
git branch md-$date | |
git checkout md-$date | |
lando composer config -g github-oauth.github.com $gh_token | |
composer config -g github-oauth.github.com $gh_token | |
composer install --ignore-platform-reqs | |
rm -fR web/sites/default/config | |
git checkout web/sites/default/config | |
lando drush cr | |
lando drush cex -y | |
git rev-list --tags --max-count=1 | |
rm -fR web/sites/default/config/local | |
git checkout web/sites/default/config/local | |
git checkout .github | |
git status | |
echo 'post status' | |
echo $current_branch | |
git branch | |
git diff --name-status -M100% $(git rev-list --tags --max-count=1)..$current_branch web/sites/default/config/default > checkout.sh | |
sed -i 's/^M./git checkout /g' checkout.sh | |
sed -i 's/^A./git add /g' checkout.sh | |
sed -i 's/^D./rm /g' checkout.sh | |
echo 'echo "end of checkout.sh"' >> checkout.sh | |
cat checkout.sh | |
chmod u+x checkout.sh | |
./checkout.sh | |
rm checkout.sh | |
status=$(git status --porcelain web/sites/default/config/default) | |
echo "#! /bin/bash | |
if [[ -z '$status' ]] | |
then | |
echo 'no config changes' | |
else | |
git fetch | |
echo 'Adding web/sites/default/config/default' | |
git add web/sites/default/config/default/ | |
git commit -m 'config: adding changes from live' | |
echo "Committed changes" | |
git status | |
echo 'pushing changes' | |
git push origin md-$date | |
fi" > commit.sh | |
chmod u+x commit.sh | |
./commit.sh | |
echo 'commit.sh ran' | |
rm commit.sh | |
git status | |
env: | |
gh_token: ${{ secrets.GITHUB_TOKEN }} | |
username: ${{ github.actor }} | |
email: [email protected] | |
gh_user: ${{ secrets.GH_USER }} | |
- name: Create Pull Request | |
run: | | |
gh pr create --title "[Config sync]" --body "Sync the config from branch" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GH_TOKEN_REPO }} |