Update Repository #913
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: Update Repository | |
on: | |
schedule: | |
- cron: "55 9 * * *" | |
- cron: "55 21 * * *" | |
workflow_dispatch: | |
inputs: | |
start_from: | |
description: "Start from chapter:" | |
type: number | |
end_at: | |
description: "End at chapter:" | |
type: number | |
cooldown: | |
description: "Cooldown between requests (in seconds):" | |
required: true | |
default: 1 | |
type: number | |
timeout: | |
description: "Consecutive unchanged chapters before exiting:" | |
default: 5 | |
type: number | |
permissions: | |
contents: write | |
pull-requests: write | |
actions: write | |
concurrency: | |
group: labosphere | |
cancel-in-progress: true | |
jobs: | |
update: | |
name: Update | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
- name: Configure Git | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
- name: Set Up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: 3.12 | |
- name: Name Update Branch | |
shell: python | |
run: | | |
import os | |
import uuid | |
print(f"UPDATE_BRANCH=update/{uuid.uuid4()}", file=open(os.getenv("GITHUB_ENV"), "a")) | |
- name: Create Update Branch | |
run: | | |
git branch -f ${{ env.UPDATE_BRANCH }} | |
git checkout ${{ env.UPDATE_BRANCH }} | |
git push -u origin ${{ env.UPDATE_BRANCH }} | |
git branch --set-upstream-to=origin/${{ env.UPDATE_BRANCH }} | |
- name: Set Up Poetry | |
run: curl -sSL https://install.python-poetry.org | python - --version=$(cat .poetry-version) | |
- name: Install Dependencies | |
run: poetry install --only main | |
- name: Get Labosphere Options | |
id: options | |
shell: python | |
run: | | |
import os | |
start_from = os.getenv("START_FROM") | |
end_at = os.getenv("END_AT") | |
cooldown = os.getenv("COOLDOWN") or 1 | |
timeout = os.getenv("TIMEOUT") or 5 | |
options = [] | |
if start_from: | |
options.append(f"--from {start_from}") | |
if end_at: | |
options.append(f"--to {end_at}") | |
if cooldown: | |
options.append(f"--cooldown {cooldown}") | |
if timeout: | |
options.append(f"--timeout {timeout}") | |
print(f"options={' '.join(options)}", file=open(os.getenv("GITHUB_OUTPUT"), "a")) | |
env: | |
START_FROM: ${{ inputs.start_from }} | |
END_AT: ${{ inputs.end_at }} | |
COOLDOWN: ${{ inputs.cooldown }} | |
TIMEOUT: ${{ inputs.timeout }} | |
- name: Run Labosphere | |
run: | | |
poetry run labosphere start ${{ steps.options.outputs.options }} | |
- name: Exit if No Changes | |
run: | | |
if [[ -z $(git diff -- cubari.json) ]]; then | |
gh run cancel ${{ github.run_id }} | |
gh run watch ${{ github.run_id }} > /dev/null 2>&1 | |
fi | |
env: | |
GH_TOKEN: ${{ github.token }} | |
- name: Commit Changes | |
run: | | |
git add . | |
git commit -m "Update cubari.json" | |
git push | |
- name: Open Pull Request | |
run: | | |
if [[ -n "${{ env.LABOSPHERE_FLAG_PR }}" ]]; then | |
gh pr create --title "Update repository" --body "More chapters updated than expected; review required." | |
else | |
gh pr create --title "Update repository" --body "" | |
gh pr merge --squash ${{ env.UPDATE_BRANCH }} | |
fi | |
env: | |
GH_TOKEN: ${{ github.token }} | |
- name: Delete Update Branch | |
if: ${{ always() && env.LABOSPHERE_FLAG_PR != 1 }} | |
run: git push -d origin ${{ env.UPDATE_BRANCH }} |