diff --git a/.github/workflows/update-docs.yml b/.github/workflows/update-docs.yml new file mode 100644 index 0000000..b7be95b --- /dev/null +++ b/.github/workflows/update-docs.yml @@ -0,0 +1,82 @@ +name: Update CLI Docs + +on: + push: + tags: + - 'v*' + +permissions: + contents: read + +jobs: + update-docs: + concurrency: + group: update-cli-docs + cancel-in-progress: false + permissions: + contents: write + pull-requests: write + runs-on: ubuntu-24.04 + steps: + - name: Checkout + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + + - name: Install Nix + uses: cachix/install-nix-action@4e002c8ec80594ecd40e759629461e26c8abed15 # v31 + + - name: Setup Cachix + uses: cachix/cachix-action@3ba601ff5bbb07c7220846facfa2cd81eeee15a1 # v16 + with: + name: crossplane + authToken: ${{ secrets.CACHIX_AUTH_TOKEN }} + + - name: Build CLI + run: | + nix build .#crossplane --print-build-logs + cp result/bin/crossplane /tmp/crossplane + + - name: Generate Docs + run: | + mkdir -p generated-docs + /tmp/crossplane generate-docs -o generated-docs/command-reference.md + + - name: Checkout Docs + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + with: + repository: crossplane/docs + token: ${{ secrets.DOCS_WRITE_TOKEN }} + path: docs + + - name: Determine Target Directory + id: target + run: | + VERSION="${GITHUB_REF#refs/tags/}" + MINOR_VERSION="${VERSION%.*}" + echo "dir=content/cli/${MINOR_VERSION#v}" >> "$GITHUB_OUTPUT" + + - name: Update Docs + env: + TARGET_DIR: ${{ steps.target.outputs.dir }} + run: | + mkdir -p "docs/${TARGET_DIR}" + cp generated-docs/command-reference.md "docs/${TARGET_DIR}/command-reference.md" + cd docs + if [[ -n "$(git status --porcelain --untracked-files=all)" ]]; then + echo "docs-changed=true" >> "$GITHUB_ENV" + fi + + - name: Create Pull Request + if: env.docs-changed == 'true' + uses: peter-evans/create-pull-request@204220e584d39b97d07e8e00693fe658ea76b09d # v7 + with: + path: docs + token: ${{ secrets.DOCS_WRITE_TOKEN }} + commit-message: "docs(cli): auto-update command reference" + title: "docs(cli): auto-update command reference for ${{ steps.target.outputs.dir }}" + body: | + Auto-generated CLI command reference update. + + Generated from: `${{ github.sha }}` + Trigger: `${{ github.event_name }} ${{ github.ref }}` + branch: auto/update-cli-docs + delete-branch: true