Sync Documentation #10
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 | |
| on: | |
| repository_dispatch: | |
| types: | |
| - sync-api-docs | |
| - sync-dataset-docs | |
| - sync-governance-docs | |
| workflow_dispatch: | |
| inputs: | |
| source: | |
| description: "Source repository to sync from" | |
| required: true | |
| type: choice | |
| options: | |
| - all | |
| - api | |
| - dataset | |
| - governance | |
| ref: | |
| description: "Git ref (branch/tag/commit) to sync from" | |
| required: false | |
| default: "main" | |
| type: string | |
| permissions: | |
| contents: write | |
| jobs: | |
| prepare: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| matrix: ${{ steps.set-matrix.outputs.matrix }} | |
| steps: | |
| - id: set-matrix | |
| run: | | |
| # Initialize variables | |
| INPUT_SOURCE="" | |
| INPUT_REF="" | |
| SHA_VAL="" | |
| if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then | |
| INPUT_SOURCE="${{ inputs.source }}" | |
| INPUT_REF="${{ inputs.ref }}" | |
| else | |
| # For repository_dispatch, source comes from payload | |
| INPUT_SOURCE="${{ github.event.client_payload.source }}" | |
| INPUT_REF="${{ github.event.client_payload.ref }}" | |
| SHA_VAL="${{ github.event.client_payload.sha }}" | |
| fi | |
| if [ "$INPUT_SOURCE" == "all" ]; then | |
| # Create matrix for all repositories | |
| # Using minified JSON for matrix output | |
| echo "matrix={\"include\":[{\"source\":\"api\",\"ref\":\"$INPUT_REF\",\"sha\":\"\"},{\"source\":\"dataset\",\"ref\":\"$INPUT_REF\",\"sha\":\"\"},{\"source\":\"governance\",\"ref\":\"$INPUT_REF\",\"sha\":\"\"}]}" >> $GITHUB_OUTPUT | |
| else | |
| # Single repository | |
| echo "matrix={\"include\":[{\"source\":\"$INPUT_SOURCE\",\"ref\":\"$INPUT_REF\",\"sha\":\"$SHA_VAL\"}]}" >> $GITHUB_OUTPUT | |
| fi | |
| sync-docs: | |
| needs: prepare | |
| name: Sync ${{ matrix.source }} | |
| runs-on: ubuntu-latest | |
| strategy: | |
| max-parallel: 1 | |
| matrix: ${{ fromJson(needs.prepare.outputs.matrix) }} | |
| fail-fast: false | |
| permissions: | |
| contents: write | |
| actions: write | |
| steps: | |
| - name: Set Source Variables | |
| id: source | |
| run: | | |
| SOURCE="${{ matrix.source }}" | |
| REF="${{ matrix.ref }}" | |
| SHA="${{ matrix.sha }}" | |
| echo "source=$SOURCE" >> $GITHUB_OUTPUT | |
| if [ -n "$SHA" ]; then | |
| echo "sha=$SHA" >> $GITHUB_OUTPUT | |
| else | |
| # Calculate SHA from Ref if not provided | |
| REPO_SUFFIX="open-ev-data-$SOURCE" | |
| if [ "$SOURCE" == "governance" ]; then REPO_SUFFIX=".github"; fi | |
| REPO_URL="https://github.com/open-ev-data/$REPO_SUFFIX" | |
| echo "Resolving SHA for $REPO_URL at $REF..." | |
| CALCULATED_SHA=$(git ls-remote $REPO_URL $REF | cut -f1) | |
| if [ -z "$CALCULATED_SHA" ]; then | |
| echo "Error: Could not resolve SHA for $REF" | |
| exit 1 | |
| fi | |
| echo "sha=$CALCULATED_SHA" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Generate GitHub App token | |
| id: generate_token | |
| uses: tibdex/github-app-token@v2 | |
| with: | |
| app_id: ${{ secrets.APP_ID }} | |
| private_key: ${{ secrets.PRIVATE_KEY }} | |
| - name: Checkout Website Repository | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ steps.generate_token.outputs.token }} | |
| fetch-depth: 0 | |
| - name: Configure Git | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| - name: Checkout Source Repository | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: ${{ steps.source.outputs.source == 'governance' && 'open-ev-data/.github' || format('open-ev-data/open-ev-data-{0}', steps.source.outputs.source) }} | |
| ref: ${{ steps.source.outputs.sha }} | |
| path: source-repo | |
| token: ${{ steps.generate_token.outputs.token }} | |
| - name: Sync API Documentation | |
| if: steps.source.outputs.source == 'api' | |
| run: | | |
| mkdir -p docs/api | |
| cp source-repo/README.md docs/api/index.md | |
| cp source-repo/docs/GET_STARTED.md docs/api/ | |
| cp source-repo/docs/ARCHITECTURE.md docs/api/ | |
| cp source-repo/docs/TESTING.md docs/api/ | |
| cp source-repo/docs/RUST_GUIDELINES.md docs/api/ | |
| cp source-repo/docs/RELEASE_STRATEGY.md docs/api/ | |
| cp source-repo/docs/API_ERRORS.md docs/api/ | |
| cp source-repo/docs/PROBLEM_DETAILS_RFC_7807.md docs/api/ | |
| cp source-repo/docs/CRATE_EV_CORE.md docs/api/ | |
| cp source-repo/docs/CRATE_EV_ETL.md docs/api/ | |
| cp source-repo/docs/CRATE_EV_SERVER.md docs/api/ | |
| cp source-repo/CHANGELOG.md docs/changelog-api.md | |
| - name: Sync Dataset Documentation | |
| if: steps.source.outputs.source == 'dataset' | |
| run: | | |
| mkdir -p docs/dataset | |
| cp source-repo/README.md docs/dataset/index.md | |
| cp source-repo/docs/HOW_TO_CONSUME.md docs/dataset/ | |
| cp source-repo/docs/ARCHITECTURE.md docs/dataset/ | |
| cp source-repo/docs/SCHEMA.md docs/dataset/ | |
| cp source-repo/docs/RELEASE_PROCESS.md docs/dataset/ | |
| cp source-repo/docs/CONTRIBUTING_VEHICLES.md docs/dataset/ | |
| cp source-repo/CHANGELOG.md docs/changelog-dataset.md | |
| - name: Sync Governance Documentation | |
| if: steps.source.outputs.source == 'governance' | |
| run: | | |
| mkdir -p docs/governance | |
| cp source-repo/README.md docs/governance/index.md | |
| cp source-repo/GET_STARTED.md docs/governance/GET_STARTED.md | |
| cp source-repo/CONTRIBUTING.md docs/governance/CONTRIBUTING.md | |
| cp source-repo/CODE_OF_CONDUCT.md docs/governance/CODE_OF_CONDUCT.md | |
| - name: Commit and Push Changes | |
| run: | | |
| git add docs/ | |
| if git diff --staged --quiet; then | |
| echo "No documentation changes detected" | |
| exit 0 | |
| fi | |
| SOURCE="${{ steps.source.outputs.source }}" | |
| SHA="${{ steps.source.outputs.sha }}" | |
| # Commit changes locally first | |
| git commit -m "docs($SOURCE): sync documentation from $SOURCE@$SHA" | |
| # Pull and rebase on top of latest main (handles matrix race conditions) | |
| git pull --rebase origin main | |
| git push origin main | |
| echo "✅ Documentation synchronized from $SOURCE" |