Merge pull request #156 from zetxek/151-footer-selector-styling #145
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
## Updates demo site (https://github.com/zetxek/adritian-demo) | |
## taken from https://stackoverflow.com/a/68213855/570087 | |
name: Update demo site (on main update) | |
on: | |
push: | |
## run on push to main or a new semantic tag (ie: v1.2.3) | |
branches: | |
- main | |
tags: | |
- 'v[0-9]+.[0-9]+.[0-9]+' | |
workflow_dispatch: | |
jobs: | |
update: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
repository: zetxek/adritian-demo | |
token: ${{ secrets.PRIVATE_TOKEN_GITHUB }} | |
submodules: true | |
- name: Print submodule status | |
run: | | |
git submodule status | |
- name: Print submodule diff | |
run: | | |
git diff --submodule=diff | |
- name: Update & send pull-request | |
run: | | |
LATEST_TAG=$(git describe --tags --always) | |
LATEST_COMMIT=$(git rev-parse HEAD) | |
REPOSITORY="zetxek/adritian-demo" | |
FOLDER="bin/$REPOSITORY" | |
BRANCH_NAME="theme-update/update-theme-to-$LATEST_TAG" | |
BASE_BRANCH="main" | |
ASSIGNEE="zetxek" | |
echo "Latest tag: $LATEST_TAG" | |
echo "Latest commit: $LATEST_COMMIT" | |
git config --global --add --bool push.autoSetupRemote true | |
# Clone the remote repository and change working directory to the | |
# folder it was cloned to. | |
git clone \ | |
--depth=1 \ | |
--branch=main \ | |
https://some-user:${{ secrets.PRIVATE_TOKEN_GITHUB }}@github.com/$REPOSITORY \ | |
$FOLDER | |
cd $FOLDER | |
# Setup the committers identity. | |
git config user.email "[email protected]" | |
git config user.name "GitHub Actions - update theme submodule" | |
git config pull.rebase false | |
# Create a new feature branch for the changes. | |
git checkout -b $BRANCH_NAME | |
# Initialize and update the submodules. | |
echo "Initializing and updating submodules..." | |
git submodule update --init --recursive | |
# Update the script files to the latest version. | |
echo "Updating theme to $LATEST_TAG..." | |
cd themes/adritian-free-hugo-theme | |
git checkout main | |
git pull origin main | |
cd ../.. | |
git add themes/adritian-free-hugo-theme | |
echo "Updated submodule. Comitting changes." | |
# Commit the changes and push the feature branch to origin | |
git config --global --add --bool push.autoSetupRemote true | |
echo "🔄 Adding all changes - updating theme to $LATEST_TAG" | |
git add --all | |
echo "✉️ Changes added. Comitting and pushing." | |
COMMIT_MSG_THEME='chore: update theme submodule to `'"$LATEST_TAG"'`' | |
echo 'Committing theme: '"$COMMIT_MSG_THEME" | |
git commit -am "$COMMIT_MSG_THEME" && git push --force || echo "No changes to theme" | |
tree themes/adritian-free-hugo-theme -r | |
# Copy content | |
cp themes/adritian-free-hugo-theme/exampleSite/hugo.toml hugo.toml | |
# Update URL | |
sed -i -e "s/\"https\:\/\/www\.adrianmoreno\.info\"/\"https\:\/\/adritian-demo\.vercel\.app\/\"/g" hugo.toml | |
COMMIT_MSG_CONFIG='chore: update config/content submodule to `'"$LATEST_TAG"'` from https://github.com/zetxek/adritian-free-hugo-theme' | |
echo "Committing content/config: $COMMIT_MSG_CONFIG" | |
git commit -am "$COMMIT_MSG_CONFIG" && git push --force || echo "No changes to config" | |
echo "Pushing branch: $BRANCH_NAME" | |
git push origin $BRANCH_NAME --force | |
# Store the PAT in a file that can be accessed by the | |
# GitHub CLI. | |
echo "${{ secrets.PRIVATE_TOKEN_GITHUB }}" > token.txt | |
# Authorize GitHub CLI for the current repository and | |
# create a pull-requests containing the updates. | |
echo "Logging in to GitHub CLI." | |
gh auth login --with-token < token.txt | |
echo "Creating pull-request..." | |
PR_TITLE='chore: update theme to `'$LATEST_TAG'`' | |
echo 'PR title: '$PR_TITLE | |
PR_BODY="🤖 This automated PR updates the theme submodule to the latest version: https://github.com/zetxek/adritian-free-hugo-theme/commit/$LATEST_COMMIT. | |
🔗 Triggered by https://github.com/zetxek/adritian-free-hugo-theme/actions/workflows/update-demo-pr.yml" | |
echo "PR body: "$PR_BODY | |
gh pr create \ | |
--title "$PR_TITLE" \ | |
--body "$PR_BODY" \ | |
--head $BRANCH_NAME \ | |
--base $BASE_BRANCH \ | |
--assignee $ASSIGNEE | |
echo "✅ Pull-request created - done! " |