maintainerr-release #5
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: Docusaurus Deploy | |
| on: | |
| repository_dispatch: | |
| types: [maintainerr-release] | |
| workflow_dispatch: | |
| inputs: | |
| versionInput: | |
| description: 'Input version from Maintainerr release' | |
| required: false | |
| permissions: | |
| contents: write | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| if: github.event.repository.fork == false | |
| env: | |
| RELEASE_VERSION: ${{ github.event.inputs.versionInput || github.event.client_payload.versionInput }} | |
| DISPATCH_BRANCH: ${{ github.event.client_payload.target_branch }} | |
| DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| ref: ${{ github.event_name == 'repository_dispatch' && github.event.client_payload.ref || github.ref }} | |
| - name: Resolve source branch | |
| id: branch | |
| run: | | |
| if [ -n "${DISPATCH_BRANCH}" ]; then | |
| SOURCE_BRANCH="${DISPATCH_BRANCH}" | |
| elif [ "${GITHUB_EVENT_NAME}" = "repository_dispatch" ]; then | |
| SOURCE_BRANCH="${DEFAULT_BRANCH:-main}" | |
| else | |
| SOURCE_BRANCH="${GITHUB_REF_NAME}" | |
| fi | |
| echo "source_branch=${SOURCE_BRANCH}" >> "${GITHUB_OUTPUT}" | |
| - name: Validate version input | |
| if: env.RELEASE_VERSION != '' | |
| run: | | |
| VERSION="${RELEASE_VERSION}" | |
| if [[ ! "${VERSION}" =~ ^[a-zA-Z0-9._-]+$ ]]; then | |
| echo "Invalid version format: '${VERSION}'" | |
| echo "Allowed characters: letters, numbers, dots (.), hyphens (-), and underscores (_)" | |
| exit 1 | |
| fi | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: npm | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Configure Git credentials | |
| if: env.RELEASE_VERSION != '' | |
| run: | | |
| git config user.name github-actions[bot] | |
| git config user.email 41898282+github-actions[bot]@users.noreply.github.com | |
| - name: Create docs version snapshot | |
| if: env.RELEASE_VERSION != '' | |
| run: | | |
| VERSION="${RELEASE_VERSION}" | |
| if [ -f versions.json ] && grep -q "\"${VERSION}\"" versions.json; then | |
| echo "Docs version ${VERSION} already exists" | |
| exit 0 | |
| fi | |
| npm run docs:version -- "${VERSION}" | |
| - name: Commit docs version snapshot | |
| if: env.RELEASE_VERSION != '' | |
| run: | | |
| if git diff --quiet -- versions.json versioned_docs versioned_sidebars; then | |
| echo "No versioned docs changes to commit" | |
| exit 0 | |
| fi | |
| git add versions.json versioned_docs versioned_sidebars | |
| git commit -m "docs: snapshot ${RELEASE_VERSION}" | |
| git push origin HEAD:${{ steps.branch.outputs.source_branch }} | |
| - name: Build Docusaurus site | |
| run: npm run build | |
| - name: Deploy to GitHub Pages | |
| uses: peaceiris/actions-gh-pages@v4 | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| publish_dir: ./build | |
| publish_branch: gh-pages | |
| force_orphan: true |