Trigger Source Operations on a Schedule #384
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: Trigger Source Operations on a Schedule | |
on: | |
schedule: | |
# Run at 00:15 every day | |
- cron: '15 */19 * * *' | |
workflow_dispatch: | |
env: | |
PLATFORMSH_CLI_TOKEN: ${{ secrets.TEMPLATES_CLI_TOKEN }} | |
GITHUB_TOKEN: ${{ secrets.TEMPLATES_GITHUB_TOKEN }} | |
UPDATE_BRANCH: "update" | |
jobs: | |
run_update: | |
name: Trigger Source Op | |
runs-on: ubuntu-latest | |
if: ${{ github.repository_owner == 'platformsh-templates' }} | |
steps: | |
- name: 'Install Psh CLI tool' | |
id: install-psh-cli | |
run: | | |
curl -fsS https://platform.sh/cli/installer | php | |
echo "PATH=${HOME}/.platformsh/bin:${PATH}" >> $GITHUB_ENV | |
- name: 'Get project ID' | |
id: 'get-projid' | |
uses: platformsh/gha-retrieve-projectid@main | |
with: | |
github_token: ${GITHUB_TOKEN} | |
- name: 'Set Project ID' | |
id: 'set-projid' | |
run: | | |
echo "::notice::Found Project ID of ${{ steps.get-projid.outputs.project_id }}" | |
echo "PLATFORM_PROJECT=${{ steps.get-projid.outputs.project_id }}" >> $GITHUB_ENV | |
- name: 'check out repo' | |
id: check-out-repo | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: "Check for update branch" | |
id: "check-update-branch" | |
run: | | |
# For now the update branch name is hard-coded above as an env var | |
# Switch to updater branch if it exists else create a local copy from default | |
echo "::notice::Switching to branch ${UPDATE_BRANCH}" | |
git checkout ${UPDATE_BRANCH} 2>/dev/null || git checkout -b ${UPDATE_BRANCH} origin/${{ github.event.repository.default_branch }} | |
- name: "Make sure it is sync'ed" | |
id: 'sync-update-branch' | |
run: | | |
git fetch | |
git pull origin ${UPDATE_BRANCH} 2>/dev/null || echo "::notice::Branch ${UPDATE_BRANCH} doesnt exist on origin yet" | |
echo "::notice::Pulling changes from ${{ github.event.repository.default_branch}} into ${UPDATE_BRANCH}." | |
git pull origin ${{ github.event.repository.default_branch }} | |
- name: 'Push back so we can get it pushed to psh' | |
id: push-update-branch | |
run: | | |
#now push it back up in case we just created it so we can sync it to platform.sh | |
echo "::notice::Pushing ${UPDATE_BRANCH} to origin." | |
git push -u origin ${UPDATE_BRANCH} | |
- name: 'Run source ops' | |
id: run-source-op | |
run: | | |
# @todo we need to check to see if this fails for some reason that doesnt cause the CLI to return a non-0 exit | |
# code. E.G. no source-op defined by this name | |
platform source-operation:run auto-update -e ${UPDATE_BRANCH} |