diff --git a/.github/actions/publish_pages/action.yml b/.github/actions/publish_pages/action.yml index 72b70bd76..18294f262 100644 --- a/.github/actions/publish_pages/action.yml +++ b/.github/actions/publish_pages/action.yml @@ -1,26 +1,66 @@ -name: Publish Page Action +name: Build and Publish Documentation inputs: target: required: true type: string - base_path: + output_path: required: true type: string + hosting_base_path: + required: true + type: string + branch_name: + required: true + type: string + default: gh-pages runs: using: "composite" steps: + - name: Create a directory for documentation + shell: bash + run: mkdir ./docs; + + - name: Build the package + shell: bash + run: swift build; + - name: Build DocC shell: bash run: | - mkdir ./docs; - swift build; swift package \ --allow-writing-to-directory ./docs \ generate-documentation \ --target ${{ inputs.target }} \ - --output-path ./docs/${{ inputs.base_path }} \ + --output-path ./docs/${{ inputs.output_path }} \ --transform-for-static-hosting \ - --hosting-base-path flare/${{ inputs.base_path }}; \ No newline at end of file + --hosting-base-path ${{ inputs.hosting_base_path }}; + + - name: Commit and push generated documentation + shell: bash + run: | + git fetch + git worktree add --checkout ${{ inputs.branch_name }} origin/${{ inputs.branch_name }} + + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + git switch ${{ inputs.branch_name }} + + rm -r ./${{ inputs.output_path }} + cp -r ./docs/${{ inputs.output_path }} ./${{ inputs.output_path }} + rm -r ./docs + + git add ./${{ inputs.output_path }} + + if [ -n "$(git status --porcelain)" ]; then + echo "Documentation changes found. Commiting the changes to the '${{ inputs.branch_name }}' branch and pushing to origin." + git commit -a -m "Generated ${{ inputs.target }} Swift DocC" + git push origin ${{ inputs.branch_name }} + else + # No changes found, nothing to commit. + echo "No documentation changes found." + fi + + git worktree remove ${{ inputs.branch_name }} \ No newline at end of file diff --git a/.github/workflows/publish-pages.yml b/.github/workflows/publish-pages.yml index 03c04ac55..540cefb6d 100644 --- a/.github/workflows/publish-pages.yml +++ b/.github/workflows/publish-pages.yml @@ -29,32 +29,11 @@ jobs: - name: Checkout 🛎️ uses: actions/checkout@v3 with: + # Fetch all history for all branches and tags. fetch-depth: 0 - - name: Build DocC - shell: bash - run: | - mkdir ./docs; - swift build; - swift package \ - --allow-writing-to-directory ./docs \ - generate-documentation \ - --target ${{ matrix.target }} \ - --output-path ./docs/${{ matrix.base_path }} \ - --transform-for-static-hosting \ - --hosting-base-path flare/${{ matrix.base_path }}; - - name: Commit and push generated documentation - run: | - git fetch - git worktree add --checkout gh-pages origin/gh-pages - - git config --local user.email "github-actions[bot]@users.noreply.github.com" - git config --local user.name "github-actions[bot]" - git switch gh-pages - - rm -r ./${{ matrix.base_path }} - cp -r ./docs/${{ matrix.base_path }} ./${{ matrix.base_path }} - rm -r ./docs - - git add ./${{ matrix.base_path }} - git commit -a -m "Generated ${{ matrix.target }} Swift DocC" - git push origin gh-pages \ No newline at end of file + - name: Build and Push Generated Documentation + uses: space-code/oss-common-actions/.github/actions/publish_docc@main + with: + target: ${{ matrix.target }} + output_path: ${{ matrix.base_path }} + hosting_base_path: flare/${{ matrix.base_path }} \ No newline at end of file