Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
end_of_line = lf
insert_final_newline = false
charset = utf-8
indent_style = space
trim_trailing_whitespace = true
tab_width = 4
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* text=auto

*.sh text eol=lf
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ jobs:
- name: Checkouting project code...
uses: actions/checkout@v2
- name: Updating wiki...
uses: impresscms-dev/phpdocs-wiki-update-action@v1.0.0
uses: impresscms-dev/phpdocs-wiki-update-action@v2.2.0
with:
wiki_github_update_token: ${{ secrets.WIKI_GITHUB_UPDATE_TOKEN }}
wiki_github_update_user: ${{ secrets.WIKI_GITHUB_UPDATE_USER }}
engine: clean/phpdoc-md
class_root_namespace: My Project
include: |
Expand All @@ -50,9 +48,10 @@ This action supports such arguments (used in `with` keyword):
|--------------------------|----------|-----------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| wiki_github_update_token | No | *github_token* | GitHub token to use for updating project wiki. [This token must have all repo permissions](https://github.com/settings/tokens/new?scopes=repo). |
| wiki_github_update_user | No | *current_user* | GitHub username for whom this token belongs |
| engine | No | clean/phpdoc-md | What documentation generator should be used? See [engines section](#engines) about possible values |
| prefix_lines | No | `##### Notice: Wiki was automatic generated from project sources as project API documentation. Do not edit manually!` | Lines that will be used to prefix generated wiki content |
| setup_php | No | True | If true, automatically runs commands to setup PHP and install composer dependencies. Set to false, if your package use custom logic or needs some custom PHP extensions |
| engine | No | <pre lang="yaml">clean/phpdoc-md</pre> | What documentation generator should be used? See [engines section](#engines) about possible values |
| prefix_lines | No | ```##### Notice: Wiki was automatic generated from project sources as project API documentation. Do not edit manually!``` | Lines that will be used to prefix generated wiki content |
| setup_php | No | <pre lang="yaml">true</pre> | If true, automatically runs commands to setup PHP and install composer dependencies. Set to false, if your package use custom logic or needs some custom PHP extensions |
| branches_map | No | <pre lang="yaml">main: master</pre> | At least for now project wiki can't have changed default branch. For such cases is possible to specify branches mapping in YAML format (key is repo branch name and value is wiki branch name) |

Some engines supports or requires extra parameters. See [engines section](#engines) about more info.

Expand Down
21 changes: 20 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ inputs:
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'
Expand All @@ -46,6 +51,13 @@ runs:
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.20.1
with:
Expand All @@ -56,6 +68,13 @@ runs:
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
Expand Down Expand Up @@ -123,4 +142,4 @@ runs:

- name: Clearing temp paths...
run: bash ${{ github.action_path }}/bin/clear_tmp_data.sh
shell: bash
shell: bash
18 changes: 10 additions & 8 deletions bin/checkout.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@
# shellcheck disable=SC2164
pushd "$OLD_WIKI_CHECKOUT_PATH"

git ls-remote -q --heads --exit-code origin "$GITHUB_REF_NAME" > /dev/null
WIKI_BRANCH=$(bash "$ACTION_BIN_PATH"/get-mapped-branch.sh)

git ls-remote -q --heads --exit-code origin "$WIKI_BRANCH" > /dev/null
REMOTE_CHECK_EXIT_CODE=$?

git show-ref -q --heads "$GITHUB_REF_NAME" > /dev/null
git show-ref -q --heads "$WIKI_BRANCH" > /dev/null
LOCAL_CHECK_EXIT_CODE=$?

if [ "$REMOTE_CHECK_EXIT_CODE" -gt 0 ] || [ "$LOCAL_CHECK_EXIT_CODE" -gt 0 ]; then
echo "Remote '$GITHUB_REF_NAME' found."
git checkout "$GITHUB_REF_NAME"
echo "Remote '$WIKI_BRANCH' found."
git checkout "$WIKI_BRANCH"
else
echo "Remote '$GITHUB_REF_NAME' not found. Creating."
git checkout -b "$GITHUB_REF_NAME"
git push --set-upstream origin "$GITHUB_REF_NAME"
echo "Remote '$WIKI_BRANCH' not found. Creating."
git checkout -b "$WIKI_BRANCH"
git push --set-upstream origin "$WIKI_BRANCH"
fi;

# shellcheck disable=SC2164
popd
popd
3 changes: 2 additions & 1 deletion bin/clear_tmp_data.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env bash

rm -rf "$OLD_WIKI_CHECKOUT_PATH" || true
rm -rf "$NEW_WIKI_CHECKOUT_PATH" || true
rm -rf "$NEW_WIKI_CHECKOUT_PATH" || true
rm -rf "$TMP_BRANCH_MAP_FILE" || true
9 changes: 9 additions & 0 deletions bin/get-mapped-branch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

# shellcheck disable=SC2002
MAPPED_BRANCH=$(cat "$TMP_BRANCH_MAP_FILE" | yq ".\"$GITHUB_REF_NAME\"")
if [ "$MAPPED_BRANCH" == "null" ]; then
echo "$GITHUB_REF_NAME"
else
echo "$MAPPED_BRANCH"
fi
2 changes: 2 additions & 0 deletions bin/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ ENGINE="$1"
ACTION_SUFFIX="${GITHUB_SHA}-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}"
OLD_WIKI_CHECKOUT_PATH="${RUNNER_TEMP}/old-wiki-${ACTION_SUFFIX}"
NEW_WIKI_CHECKOUT_PATH="${RUNNER_TEMP}/new-wiki-${ACTION_SUFFIX}"
TMP_BRANCH_MAP_FILE="${RUNNER_TEMP}/branches-map-${ACTION_SUFFIX}"
ACTION_BIN_PATH="${GITHUB_ACTION_PATH}/bin"

if [ "$ENGINE" == "evert/phpdoc-md" ]; then
Expand All @@ -21,6 +22,7 @@ echo "OLD_WIKI_CHECKOUT_PATH=$OLD_WIKI_CHECKOUT_PATH" >> $GITHUB_ENV
echo "NEW_WIKI_CHECKOUT_PATH=$NEW_WIKI_CHECKOUT_PATH" >> $GITHUB_ENV
echo "NEEDED_PHP_VERSION=$NEEDED_PHP_VERSION" >> $GITHUB_ENV
echo "ACTION_BIN_PATH=$ACTION_BIN_PATH" >> $GITHUB_ENV
echo "TMP_BRANCH_MAP_FILE=$TMP_BRANCH_MAP_FILE" >> $GITHUB_ENV

rm -rf "$OLD_WIKI_CHECKOUT_PATH" || true
rm -rf "$NEW_WIKI_CHECKOUT_PATH" || true
Expand Down