Sync documentation sources #309
This file contains hidden or 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: Sync documentation sources | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| release_tag: | |
| description: 'Release tag (e.g., v1.2.1) — leave empty for latest version' | |
| required: false | |
| # 03:00 UTC, 05:00 Prague, usually all PRs in cozystack/cozystack get merged before this time. | |
| schedule: | |
| - cron: '0 3 * * *' | |
| # Triggered remotely via: | |
| # curl -XPOST -H "Authorization: token <PAT>" \ | |
| # -H "Accept: application/vnd.github.v3+json" \ | |
| # https://api.github.com/repos/cozystack/website/dispatches \ | |
| # -d '{"event_type":"update_managed_apps","client_payload":{"release_tag":"v1.2.1"}}' | |
| repository_dispatch: | |
| types: [update_managed_apps] | |
| jobs: | |
| sync-docs: | |
| runs-on: ubuntu-latest | |
| steps: | |
| # Checkout the target repository (this one) | |
| - name: Checkout target repo | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: 'main' | |
| - name: Determine version parameters | |
| id: version | |
| env: | |
| RELEASE_TAG_INPUT: ${{ github.event.client_payload.release_tag || github.event.inputs.release_tag || '' }} | |
| run: | | |
| # Validate release tag format if provided | |
| if [[ -n "$RELEASE_TAG_INPUT" && ! "$RELEASE_TAG_INPUT" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
| echo "::error::Invalid release tag format: '$RELEASE_TAG_INPUT' (expected vX.Y.Z)" | |
| exit 1 | |
| fi | |
| RELEASE_TAG="$RELEASE_TAG_INPUT" | |
| if [[ -n "$RELEASE_TAG" ]]; then | |
| echo "release_tag=${RELEASE_TAG}" >> $GITHUB_OUTPUT | |
| # Derive doc version for branch naming | |
| VER="${RELEASE_TAG#v}" | |
| MAJOR="${VER%%.*}" | |
| MINOR="${VER#*.}" | |
| MINOR="${MINOR%%.*}" | |
| if [[ "$MAJOR" == "0" ]]; then | |
| DOC_VERSION="v0" | |
| else | |
| DOC_VERSION="v${MAJOR}.${MINOR}" | |
| fi | |
| echo "doc_version=${DOC_VERSION}" >> $GITHUB_OUTPUT | |
| echo "branch_suffix=${DOC_VERSION}" >> $GITHUB_OUTPUT | |
| else | |
| # Daily sync: target latest version from hugo.yaml | |
| LATEST=$(grep 'latest_version_id' hugo.yaml | head -1 | awk '{print $2}' | tr -d '"') | |
| echo "doc_version=${LATEST}" >> $GITHUB_OUTPUT | |
| echo "branch_suffix=${LATEST}" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Update docs via script | |
| env: | |
| RELEASE_TAG: ${{ steps.version.outputs.release_tag }} | |
| DOC_VERSION: ${{ steps.version.outputs.doc_version }} | |
| run: | | |
| if [[ -n "$RELEASE_TAG" ]]; then | |
| make update-all RELEASE_TAG="$RELEASE_TAG" | |
| else | |
| make update-all DOC_VERSION="$DOC_VERSION" | |
| fi | |
| git status -s | |
| # Commit and push any changes | |
| - name: Commit & push changes | |
| env: | |
| DOC_VERSION: ${{ steps.version.outputs.doc_version }} | |
| run: | | |
| BRANCH="update-managed-apps-${DOC_VERSION}" | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add content | |
| if git diff --cached --quiet; then | |
| echo "No changes to commit" | |
| exit 0 | |
| fi | |
| git branch -D "$BRANCH" || true | |
| git checkout -b "$BRANCH" | |
| git commit --signoff -m "[docs] Update managed apps reference for ${DOC_VERSION} $(date -u +'%Y-%m-%d %H:%M:%S')" | |
| git push --force --set-upstream origin "$BRANCH" | |
| - name: Open pull request if not exists | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| DOC_VERSION: ${{ steps.version.outputs.doc_version }} | |
| run: | | |
| BRANCH="update-managed-apps-${DOC_VERSION}" | |
| # Determine PR state | |
| pr_state=$(gh pr view "$BRANCH" --json state --jq .state 2>/dev/null || echo "") | |
| echo "Current PR state: ${pr_state:-NONE}" | |
| if [[ "$pr_state" == "OPEN" ]]; then | |
| echo "An open pull request already exists – skipping creation." | |
| else | |
| gh pr create \ | |
| --title "[docs] Update managed apps reference for ${DOC_VERSION}" \ | |
| --body "Automated update via workflow." \ | |
| --head "$BRANCH" \ | |
| --base main | |
| fi |