Skip to content

Commit ac9d038

Browse files
authored
Merge pull request #208 from MekDrop/feat/branch-maps
Branch maps
2 parents 6340b64 + 6759731 commit ac9d038

File tree

8 files changed

+60
-16
lines changed

8 files changed

+60
-16
lines changed

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = false
6+
charset = utf-8
7+
indent_style = space
8+
trim_trailing_whitespace = true
9+
tab_width = 4

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* text=auto
2+
3+
*.sh text eol=lf

README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ jobs:
3232
- name: Checkouting project code...
3333
uses: actions/checkout@v2
3434
- name: Updating wiki...
35-
uses: impresscms-dev/phpdocs-wiki-update-action@v1.0.0
35+
uses: impresscms-dev/phpdocs-wiki-update-action@v2.2.0
3636
with:
37-
wiki_github_update_token: ${{ secrets.WIKI_GITHUB_UPDATE_TOKEN }}
38-
wiki_github_update_user: ${{ secrets.WIKI_GITHUB_UPDATE_USER }}
3937
engine: clean/phpdoc-md
4038
class_root_namespace: My Project
4139
include: |
@@ -50,9 +48,10 @@ This action supports such arguments (used in `with` keyword):
5048
|--------------------------|----------|-----------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
5149
| 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). |
5250
| wiki_github_update_user | No | *current_user* | GitHub username for whom this token belongs |
53-
| engine | No | clean/phpdoc-md | What documentation generator should be used? See [engines section](#engines) about possible values |
54-
| 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 |
55-
| 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 |
51+
| engine | No | <pre lang="yaml">clean/phpdoc-md</pre> | What documentation generator should be used? See [engines section](#engines) about possible values |
52+
| 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 |
53+
| 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 |
54+
| 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) |
5655

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

action.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ inputs:
3838
description: Automatically setups PHP for action (default)
3939
required: false
4040
default: 'true'
41+
branches_map:
42+
description: "This is used to map repo branches with wiki branches (format: local repo branch: wiki repo branch)"
43+
required: false
44+
default: |
45+
main: master
4146
4247
runs:
4348
using: 'composite'
@@ -46,6 +51,13 @@ runs:
4651
run: bash "$GITHUB_ACTION_PATH/bin/setup.sh" "${{ inputs.engine }}"
4752
shell: bash
4853

54+
- name: Setup yq environment
55+
run: |
56+
wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
57+
chmod a+x /usr/local/bin/yq
58+
yq --version
59+
shell: bash
60+
4961
- name: Installing PHP...
5062
uses: shivammathur/setup-php@2.21.0
5163
with:
@@ -56,6 +68,13 @@ runs:
5668
tools: composer:v2
5769
if: inputs.setup_php == 'true'
5870

71+
- name: Writing tmp branches map file...
72+
uses: DamianReeves/write-file-action@master
73+
with:
74+
path: ${{ env.TMP_BRANCH_MAP_FILE }}
75+
contents: ${{ inputs.branches_map }}
76+
write-mode: overwrite
77+
5978
- name: Running composer...
6079
run: composer install --no-scripts --no-plugins -n -o
6180
shell: bash
@@ -123,4 +142,4 @@ runs:
123142

124143
- name: Clearing temp paths...
125144
run: bash ${{ github.action_path }}/bin/clear_tmp_data.sh
126-
shell: bash
145+
shell: bash

bin/checkout.sh

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@
33
# shellcheck disable=SC2164
44
pushd "$OLD_WIKI_CHECKOUT_PATH"
55

6-
git ls-remote -q --heads --exit-code origin "$GITHUB_REF_NAME" > /dev/null
6+
WIKI_BRANCH=$(bash "$ACTION_BIN_PATH"/get-mapped-branch.sh)
7+
8+
git ls-remote -q --heads --exit-code origin "$WIKI_BRANCH" > /dev/null
79
REMOTE_CHECK_EXIT_CODE=$?
810

9-
git show-ref -q --heads "$GITHUB_REF_NAME" > /dev/null
11+
git show-ref -q --heads "$WIKI_BRANCH" > /dev/null
1012
LOCAL_CHECK_EXIT_CODE=$?
1113

1214
if [ "$REMOTE_CHECK_EXIT_CODE" -gt 0 ] || [ "$LOCAL_CHECK_EXIT_CODE" -gt 0 ]; then
13-
echo "Remote '$GITHUB_REF_NAME' found."
14-
git checkout "$GITHUB_REF_NAME"
15+
echo "Remote '$WIKI_BRANCH' found."
16+
git checkout "$WIKI_BRANCH"
1517
else
16-
echo "Remote '$GITHUB_REF_NAME' not found. Creating."
17-
git checkout -b "$GITHUB_REF_NAME"
18-
git push --set-upstream origin "$GITHUB_REF_NAME"
18+
echo "Remote '$WIKI_BRANCH' not found. Creating."
19+
git checkout -b "$WIKI_BRANCH"
20+
git push --set-upstream origin "$WIKI_BRANCH"
1921
fi;
2022

2123
# shellcheck disable=SC2164
22-
popd
24+
popd

bin/clear_tmp_data.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env bash
22

33
rm -rf "$OLD_WIKI_CHECKOUT_PATH" || true
4-
rm -rf "$NEW_WIKI_CHECKOUT_PATH" || true
4+
rm -rf "$NEW_WIKI_CHECKOUT_PATH" || true
5+
rm -rf "$TMP_BRANCH_MAP_FILE" || true

bin/get-mapped-branch.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
# shellcheck disable=SC2002
4+
MAPPED_BRANCH=$(cat "$TMP_BRANCH_MAP_FILE" | yq ".\"$GITHUB_REF_NAME\"")
5+
if [ "$MAPPED_BRANCH" == "null" ]; then
6+
echo "$GITHUB_REF_NAME"
7+
else
8+
echo "$MAPPED_BRANCH"
9+
fi

bin/setup.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ ENGINE="$1"
55
ACTION_SUFFIX="${GITHUB_SHA}-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}"
66
OLD_WIKI_CHECKOUT_PATH="${RUNNER_TEMP}/old-wiki-${ACTION_SUFFIX}"
77
NEW_WIKI_CHECKOUT_PATH="${RUNNER_TEMP}/new-wiki-${ACTION_SUFFIX}"
8+
TMP_BRANCH_MAP_FILE="${RUNNER_TEMP}/branches-map-${ACTION_SUFFIX}"
89
ACTION_BIN_PATH="${GITHUB_ACTION_PATH}/bin"
910

1011
if [ "$ENGINE" == "evert/phpdoc-md" ]; then
@@ -21,6 +22,7 @@ echo "OLD_WIKI_CHECKOUT_PATH=$OLD_WIKI_CHECKOUT_PATH" >> $GITHUB_ENV
2122
echo "NEW_WIKI_CHECKOUT_PATH=$NEW_WIKI_CHECKOUT_PATH" >> $GITHUB_ENV
2223
echo "NEEDED_PHP_VERSION=$NEEDED_PHP_VERSION" >> $GITHUB_ENV
2324
echo "ACTION_BIN_PATH=$ACTION_BIN_PATH" >> $GITHUB_ENV
25+
echo "TMP_BRANCH_MAP_FILE=$TMP_BRANCH_MAP_FILE" >> $GITHUB_ENV
2426

2527
rm -rf "$OLD_WIKI_CHECKOUT_PATH" || true
2628
rm -rf "$NEW_WIKI_CHECKOUT_PATH" || true

0 commit comments

Comments
 (0)