impresscms-dev/phpdocs-wiki-update-action

View on GitHub
action.yml

Summary

Maintainability
Test Coverage
name: 'Update wiki with PHP project documentation'
description: 'Updates project wiki with automatic generated PHP project documentation'

branding:
  icon: book
  color: purple

inputs:
  wiki_github_update_token:
    description: GitHub token to use for updating project wiki
    required: false
    default: ${{ github.token }}
  wiki_github_update_user:
    description: GitHub username for whom this token belongs
    required: false
    default: ${{ github.actor }}
  engine:
    description: What documentation generator should be used
    required: false
    default: clean/phpdoc-md
  class_root_namespace:
    description: Root class namespace that should be used for documentation
    required: false
  include:
    description: Defines what classes should be included in generated documentation (supports glob style wildcards syntax; each line means one rule)
    required: false
    default: ''
  ignored_files:
    description: Defines files that can be ignored (supports glob rules)
    required: false
    default: ''
  prefix_lines:
    description: Lines that will be used to prefix generated wiki content
    required: false
    default: |
      ##### Notice: Wiki was automatic generated from project sources as project API documentation. Do not edit manually!
  setup_php:
    description: Automatically setups PHP for action (default)
    required: false
    default: 'true'
  branches_map:
    description: "This is used to map repo branches with wiki branches (format: local repo branch: wiki repo branch)"
    required: false
    default: |
      main: master

runs:
  using: 'composite'
  steps:
    - name: Setuping...
      run: bash "$GITHUB_ACTION_PATH/bin/setup.sh" "${{ inputs.engine }}"
      shell: bash

    - name: Setup yq environment
      run: |
        wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
        chmod a+x /usr/local/bin/yq
        yq --version
      shell: bash

    - name: Installing PHP...
      uses: shivammathur/setup-php@2.30.4
      with:
        php-version: ${{ env.NEEDED_PHP_VERSION }}
        extensions: curl, gd, pdo_mysql, json, mbstring, pcre, session
        ini-values: post_max_size=256M
        coverage: none
        tools: composer:v2
      if: inputs.setup_php == 'true'

    - name: Writing tmp branches map file...
      uses: DamianReeves/write-file-action@master
      with:
        path: ${{ env.TMP_BRANCH_MAP_FILE }}
        contents: ${{ inputs.branches_map }}
        write-mode: overwrite

    - name: Running composer...
      run: composer install --no-scripts --no-plugins -n -o
      shell: bash
      if: inputs.setup_php == 'true'

    - name: Cloning original wiki...
      run: |
        bash ${{ github.action_path }}/bin/cloning.sh \
          "${{ inputs.wiki_github_update_token }}" \
          "${{ inputs.wiki_github_update_user }}"
      shell: bash

    - name: Configuring GIT...
      run: |
        bash ${{ github.action_path }}/bin/configure_git.sh \
          "${{ inputs.wiki_github_update_user }}" \
          "${{ inputs.wiki_github_update_user }}@users.noreply.github.com"
      shell: bash

    - name: Checkouting needed branch...
      run: bash ${{ github.action_path }}/bin/checkout.sh
      shell: bash

    - name: Generating new documentation with clean/phpdoc-md...
      uses: impresscms-dev/generate-phpdocs-with-clean-phpdoc-md-action@v1.0.3
      with:
        class_root_namespace: ${{ inputs.class_root_namespace }}
        included_classes: ${{ inputs.include }}
        output_path: ${{ env.NEW_WIKI_CHECKOUT_PATH }}
      if: inputs.engine == 'clean/phpdoc-md'

    - name: Generating new documentation with evert/phpdoc-md...
      uses: impresscms-dev/generate-phpdocs-with-evert-phpdoc-md-action@v1.0.4
      with:
        ignored_files: ${{ inputs.ignored_files }}
        output_path: ${{ env.NEW_WIKI_CHECKOUT_PATH }}
      if: inputs.engine == 'evert/phpdoc-md'

    - name: Renaming index file...
      run: bash ${{ github.action_path }}/bin/rename_index.sh "${{ inputs.engine }}"
      shell: bash

    - name: Prefixing files...
      uses: impresscms-dev/prefix-or-suffix-text-files-action@v0.1
      with:
        path: ${{ env.NEW_WIKI_CHECKOUT_PATH }}
        text: ${{ inputs.prefix_lines }}
        suffix: false
      if: inputs.prefix_lines != ''

    - name: Flattering new documentation...
      uses: impresscms-dev/flattern-markdown-folder-structure-action@v0.2
      with:
        path: ${{ env.NEW_WIKI_CHECKOUT_PATH }}
        
    - name: Stripping MarkDown file extensions...
      uses: impresscms-dev/strip-markdown-extensions-from-links-action@v0.1
      with:
        path: ${{ env.NEW_WIKI_CHECKOUT_PATH }}

    - name: Moving old .git data to new docs folder...
      run: mv "$OLD_WIKI_CHECKOUT_PATH"/.git "$NEW_WIKI_CHECKOUT_PATH/"
      shell: bash

    - name: Commit and push wiki changes...
      run: |
        bash ${{ github.action_path }}/bin/commit_and_push.sh \
          "${{ github.event.commits[0].message }}"
      shell: bash

    - name: Clearing temp paths...
      run: bash ${{ github.action_path }}/bin/clear_tmp_data.sh
      shell: bash