From 61b3d71eb7a1fd01835c09be7c7d8fdc0f2fe1a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Sun, 8 Mar 2020 04:27:19 +0100 Subject: [PATCH 01/48] Make filtering support complex glob patterns --- entrypoint.sh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 034b94f..a1a8836 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,12 +1,15 @@ -#!/bin/sh +#!/bin/bash # # @author André Storhaug -# @date 2020-02-22 +# @date 2020-03-08 # @license MIT -# @version 2.0.0 +# @version 2.1.0 set -o pipefail +shopt -s extglob +shopt -s globstar + PERSONAL_TOKEN="$INPUT_PERSONAL_TOKEN" SRC_PATH="$INPUT_SRC_PATH" DST_PATH="$INPUT_DST_PATH" @@ -14,6 +17,7 @@ DST_OWNER="$INPUT_DST_OWNER" DST_REPO_NAME="$INPUT_DST_REPO_NAME" SRC_BRANCH="$INPUT_SRC_BRANCH" DST_BRANCH="$INPUT_DST_BRANCH" +SRC_FILTER="$INPUT_SRC_FILTER" SRC_WIKI="$INPUT_SRC_WIKI" DST_WIKI="$INPUT_DST_WIKI" USERNAME="$INPUT_USERNAME" @@ -79,7 +83,11 @@ fi rm -rf ${SRC_REPO_NAME}/.git if [[ -n "$SRC_FILTER" ]]; then - find ${SRC_REPO_NAME}/ -type f -not -name "${SRC_FILTER}" -exec rm {} \; + for f in ${SRC_REPO_NAME}/**/!(${$SRC_FILTER}) ; do + [ -e "$f" ] || continue + [ -d "$f! ] && continue + rm $f + done fi git clone --branch ${DST_BRANCH} --single-branch --depth 1 https://${PERSONAL_TOKEN}@github.com/${DST_REPO}.git From 07eaf950ea18d856732855dd822a74c9b3c6da7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Sun, 8 Mar 2020 04:29:53 +0100 Subject: [PATCH 02/48] Install bash --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index ae260c3..4647f25 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,6 @@ FROM alpine:3.10 +RUN apk add --no-cache bash RUN apk add --no-cache git COPY entrypoint.sh /entrypoint.sh From f5014d26c394b9da786ef01a218c517ca0841064 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Sun, 8 Mar 2020 04:31:42 +0100 Subject: [PATCH 03/48] Fix typo --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index a1a8836..93d7fe2 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -85,7 +85,7 @@ rm -rf ${SRC_REPO_NAME}/.git if [[ -n "$SRC_FILTER" ]]; then for f in ${SRC_REPO_NAME}/**/!(${$SRC_FILTER}) ; do [ -e "$f" ] || continue - [ -d "$f! ] && continue + [ -d "$f" ] && continue rm $f done fi From 0bdaba148e8a61680bcdd2ae2c58b651e6c4bc50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Sun, 8 Mar 2020 04:56:11 +0100 Subject: [PATCH 04/48] Run with bash --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 4647f25..847cf7d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,4 +4,4 @@ RUN apk add --no-cache bash RUN apk add --no-cache git COPY entrypoint.sh /entrypoint.sh -ENTRYPOINT ["/entrypoint.sh"] +CMD ["/bin/bash", "./entrypoint.sh"] From fb1711307907db83770f31cdcd069d5c89264161 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Sun, 8 Mar 2020 05:12:50 +0100 Subject: [PATCH 05/48] Update Dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 847cf7d..fc825b2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,4 +4,4 @@ RUN apk add --no-cache bash RUN apk add --no-cache git COPY entrypoint.sh /entrypoint.sh -CMD ["/bin/bash", "./entrypoint.sh"] +CMD ["/bin/bash", "-c", "./entrypoint.sh"] From 393ce528b8250b38fd5afaf95feffd2b59ea4fe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Sun, 8 Mar 2020 05:17:15 +0100 Subject: [PATCH 06/48] Update Dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index fc825b2..8457ccf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,4 +4,4 @@ RUN apk add --no-cache bash RUN apk add --no-cache git COPY entrypoint.sh /entrypoint.sh -CMD ["/bin/bash", "-c", "./entrypoint.sh"] +ENTRYPOINT ["/bin/bash", "-c", "./entrypoint.sh"] From 36b9eeba34894dbd8d8b9221f35e59945409ca3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Sun, 8 Mar 2020 05:19:14 +0100 Subject: [PATCH 07/48] Update entrypoint.sh --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 93d7fe2..2125542 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -83,7 +83,7 @@ fi rm -rf ${SRC_REPO_NAME}/.git if [[ -n "$SRC_FILTER" ]]; then - for f in ${SRC_REPO_NAME}/**/!(${$SRC_FILTER}) ; do + for f in ${SRC_REPO_NAME}/**/!(${SRC_FILTER}) ; do [ -e "$f" ] || continue [ -d "$f" ] && continue rm $f From 3dc3848ebb5bc9094c9e57649c41e1c83c80f516 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Sun, 8 Mar 2020 05:20:23 +0100 Subject: [PATCH 08/48] Update Dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 8457ccf..2254441 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,4 +4,4 @@ RUN apk add --no-cache bash RUN apk add --no-cache git COPY entrypoint.sh /entrypoint.sh -ENTRYPOINT ["/bin/bash", "-c", "./entrypoint.sh"] +ENTRYPOINT ["/bin/bash", "-c", "/entrypoint.sh"] From 7577e3f5f143197f03202ac8bea7d559cd0fa0c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Sun, 8 Mar 2020 22:55:33 +0100 Subject: [PATCH 09/48] Enable complex globbing pattern matching for files Note: input variable SRC_FILTER is changed to FILTER --- entrypoint.sh | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 2125542..5e51d86 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -17,7 +17,7 @@ DST_OWNER="$INPUT_DST_OWNER" DST_REPO_NAME="$INPUT_DST_REPO_NAME" SRC_BRANCH="$INPUT_SRC_BRANCH" DST_BRANCH="$INPUT_DST_BRANCH" -SRC_FILTER="$INPUT_SRC_FILTER" +FILTER="$INPUT_FILTER" SRC_WIKI="$INPUT_SRC_WIKI" DST_WIKI="$INPUT_DST_WIKI" USERNAME="$INPUT_USERNAME" @@ -65,14 +65,15 @@ DST_REPO="${DST_OWNER}/${DST_REPO_NAME}${DST_WIKI}" DST_REPO_NAME="${DST_REPO_NAME}${DST_WIKI}" DIR="${DST_PATH%/*}" +FINAL_SOURCE="${SRC_REPO_NAME}/${SRC_PATH}" git config --global user.name "${USERNAME}" git config --global user.email "${EMAIL}" -if [[ -z "$SRC_FILTER" ]]; then +if [[ -z "$FILTER" ]]; then echo "Copying \"${SRC_REPO_NAME}/${SRC_PATH}\" and pushing it to ${GITHUB_REPOSITORY}" else - echo "Copying files matching \"${SRC_FILTER}\" from \"${SRC_REPO_NAME}/${SRC_PATH}\" and pushing it to ${GITHUB_REPOSITORY}" + echo "Copying files matching \"${FILTER}\" from \"${SRC_REPO_NAME}/${SRC_PATH}\" and pushing it to ${GITHUB_REPOSITORY}" fi git clone --branch ${SRC_BRANCH} --single-branch --depth 1 https://${PERSONAL_TOKEN}@github.com/${SRC_REPO}.git @@ -82,11 +83,15 @@ if [ "$?" -ne 0 ]; then fi rm -rf ${SRC_REPO_NAME}/.git -if [[ -n "$SRC_FILTER" ]]; then - for f in ${SRC_REPO_NAME}/**/!(${SRC_FILTER}) ; do +tmp_dir=$(mktemp -d -t ci-XXXXXXXXXX) + +if [[ -n "$FILTER" ]]; then + FINAL_SOURCE="${tmp_dir}/${SRC_REPO_NAME}/${SRC_PATH}" + for f in ${SRC_REPO_NAME}/${FILTER} ; do [ -e "$f" ] || continue [ -d "$f" ] && continue - rm $f + file_dir=$(dirname "${f}") + mkdir -p ${tmp_dir}/${file_dir} && cp ${f} ${tmp_dir}/${file_dir} done fi @@ -97,10 +102,11 @@ if [ "$?" -ne 0 ]; then fi mkdir -p ${DST_REPO_NAME}/${DIR} || exit "$?" -cp -rf ${SRC_REPO_NAME}/${SRC_PATH} ${DST_REPO_NAME}/${DST_PATH} || exit "$?" +cp -rf ${FINAL_SOURCE} ${DST_REPO_NAME}/${DST_PATH} || exit "$?" +rm -rf $tmp_dir || exit "$?" cd ${DST_REPO_NAME} || exit "$?" -if [ -d "${BASE_PATH}/${SRC_REPO_NAME}/${SRC_PATH}" ]; then +if [ -d "${BASE_PATH}/${FINAL_SOURCE}" ]; then COMMIT_MESSAGE="Update file(s) in \"${SRC_PATH}\" from \"${GITHUB_REPOSITORY}\"" else COMMIT_MESSAGE="Update file \"${SRC_PATH}\" from \"${GITHUB_REPOSITORY}\"" From 10662877f5225f1fae737193449ed8b84a770733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Sun, 8 Mar 2020 22:56:43 +0100 Subject: [PATCH 10/48] Change src_filter to just filter --- action.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index b0c98cd..72a0cb2 100644 --- a/action.yml +++ b/action.yml @@ -28,8 +28,8 @@ inputs: description: 'The branch name of the destination repository' required: false default: 'master' - src_filter: - description: 'A pattern for filtering files to be copied' + filter: + description: 'A extglob pattern for filtering files to be copied' required: false src_wiki: description: 'Set to true if the source repository you want to copy from is the GitHub Wiki' @@ -56,7 +56,7 @@ runs: - ${{ inputs.dst_repo_name }} - ${{ inputs.src_branch }} - ${{ inputs.dst_branch }} - - ${{ inputs.src_filter }} + - ${{ inputs.filter }} - ${{ inputs.src_wiki }} - ${{ inputs.dst_wiki }} - ${{ inputs.username }} From 2c010090ff70bada8dd2d9040efad21c9aa3f737 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Sun, 8 Mar 2020 23:37:29 +0100 Subject: [PATCH 11/48] Change cwd --- entrypoint.sh | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 5e51d86..2ab3ac3 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -84,15 +84,18 @@ fi rm -rf ${SRC_REPO_NAME}/.git tmp_dir=$(mktemp -d -t ci-XXXXXXXXXX) - if [[ -n "$FILTER" ]]; then - FINAL_SOURCE="${tmp_dir}/${SRC_REPO_NAME}/${SRC_PATH}" - for f in ${SRC_REPO_NAME}/${FILTER} ; do - [ -e "$f" ] || continue - [ -d "$f" ] && continue - file_dir=$(dirname "${f}") - mkdir -p ${tmp_dir}/${file_dir} && cp ${f} ${tmp_dir}/${file_dir} + cd ${SRC_REPO_NAME} + FINAL_SOURCE="${tmp_dir}/${SRC_PATH}" + + for f in ${FILTER} ; do + [ -e "$f" ] || continue + [ -d "$f" ] && continue + file_dir=$(dirname "${f}") + mkdir -p ${tmp_dir}/${file_dir} && cp ${f} ${tmp_dir}/${file_dir} done + + cd ../ fi git clone --branch ${DST_BRANCH} --single-branch --depth 1 https://${PERSONAL_TOKEN}@github.com/${DST_REPO}.git From a5c1e70b2ad3f4d2f09d871ed63a3ced60e85598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Mon, 9 Mar 2020 04:35:08 +0100 Subject: [PATCH 12/48] Add exclude option --- entrypoint.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 2ab3ac3..7295dbe 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -18,6 +18,7 @@ DST_REPO_NAME="$INPUT_DST_REPO_NAME" SRC_BRANCH="$INPUT_SRC_BRANCH" DST_BRANCH="$INPUT_DST_BRANCH" FILTER="$INPUT_FILTER" +EXCLUDE="$INPUT_EXCLUDE" SRC_WIKI="$INPUT_SRC_WIKI" DST_WIKI="$INPUT_DST_WIKI" USERNAME="$INPUT_USERNAME" @@ -83,14 +84,17 @@ if [ "$?" -ne 0 ]; then fi rm -rf ${SRC_REPO_NAME}/.git -tmp_dir=$(mktemp -d -t ci-XXXXXXXXXX) if [[ -n "$FILTER" ]]; then + tmp_dir=$(mktemp -d -t ci-XXXXXXXXXX) cd ${SRC_REPO_NAME} FINAL_SOURCE="${tmp_dir}/${SRC_PATH}" for f in ${FILTER} ; do [ -e "$f" ] || continue [ -d "$f" ] && continue + if [[ -n "$EXCLUDE_DIR" ]] ; then + [[ $f == *$EXCLUDE* ]] && continue + fi file_dir=$(dirname "${f}") mkdir -p ${tmp_dir}/${file_dir} && cp ${f} ${tmp_dir}/${file_dir} done @@ -106,7 +110,6 @@ fi mkdir -p ${DST_REPO_NAME}/${DIR} || exit "$?" cp -rf ${FINAL_SOURCE} ${DST_REPO_NAME}/${DST_PATH} || exit "$?" -rm -rf $tmp_dir || exit "$?" cd ${DST_REPO_NAME} || exit "$?" if [ -d "${BASE_PATH}/${FINAL_SOURCE}" ]; then From edb734bd8d54ec29a1bb766f6a2c3f8f2c6218aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Mon, 9 Mar 2020 04:37:35 +0100 Subject: [PATCH 13/48] Update action.yml --- action.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 72a0cb2..29df285 100644 --- a/action.yml +++ b/action.yml @@ -29,7 +29,10 @@ inputs: required: false default: 'master' filter: - description: 'A extglob pattern for filtering files to be copied' + description: 'A glob pattern for filtering files to be copied' + required: false + exclude: + description: 'A glob pattern for excluding directories to be copied' required: false src_wiki: description: 'Set to true if the source repository you want to copy from is the GitHub Wiki' From 3a6c0ff16dae9719367fa88fb6859704a8806604 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Mon, 9 Mar 2020 15:01:55 +0100 Subject: [PATCH 14/48] Update entrypoint.sh --- entrypoint.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 7295dbe..b71904e 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -92,8 +92,8 @@ if [[ -n "$FILTER" ]]; then for f in ${FILTER} ; do [ -e "$f" ] || continue [ -d "$f" ] && continue - if [[ -n "$EXCLUDE_DIR" ]] ; then - [[ $f == *$EXCLUDE* ]] && continue + if [[ -n "$EXCLUDE" ]] ; then + [[ $f == $EXCLUDE ]] && continue fi file_dir=$(dirname "${f}") mkdir -p ${tmp_dir}/${file_dir} && cp ${f} ${tmp_dir}/${file_dir} From d4f8b10e0c5f176a013afbcc48350fd2a0c9f49a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Mon, 9 Mar 2020 15:03:40 +0100 Subject: [PATCH 15/48] Add exclude input --- action.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 29df285..401c6c2 100644 --- a/action.yml +++ b/action.yml @@ -32,7 +32,7 @@ inputs: description: 'A glob pattern for filtering files to be copied' required: false exclude: - description: 'A glob pattern for excluding directories to be copied' + description: 'A glob pattern for excluding paths' required: false src_wiki: description: 'Set to true if the source repository you want to copy from is the GitHub Wiki' @@ -60,6 +60,7 @@ runs: - ${{ inputs.src_branch }} - ${{ inputs.dst_branch }} - ${{ inputs.filter }} + - ${{ inputs.exclude }} - ${{ inputs.src_wiki }} - ${{ inputs.dst_wiki }} - ${{ inputs.username }} From 9b63313ba5196aa4f0620490ba02bc0fe27fb6d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Mon, 9 Mar 2020 15:22:14 +0100 Subject: [PATCH 16/48] Set nullglob --- entrypoint.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index b71904e..8ec607f 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -7,8 +7,7 @@ set -o pipefail -shopt -s extglob -shopt -s globstar +shopt -s extglob globstar nullglob PERSONAL_TOKEN="$INPUT_PERSONAL_TOKEN" SRC_PATH="$INPUT_SRC_PATH" From 9ad1c4ece49a4567e6dbe394e75073c7ad655a13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Mon, 9 Mar 2020 15:51:44 +0100 Subject: [PATCH 17/48] Update entrypoint.sh --- entrypoint.sh | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 8ec607f..5b86f0c 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -24,32 +24,40 @@ USERNAME="$INPUT_USERNAME" EMAIL="$INPUT_EMAIL" if [[ -z "$SRC_PATH" ]]; then - echo "SRC_PATH environment variable is missing. Cannot proceed." - exit 1 + echo "SRC_PATH environment variable is missing. Cannot proceed." + exit 1 fi if [[ -z "$DST_OWNER" ]]; then - echo "DST_OWNER environment variable is missing. Cannot proceed." - exit 1 + echo "DST_OWNER environment variable is missing. Cannot proceed." + exit 1 fi if [[ -z "$DST_REPO_NAME" ]]; then - echo "DST_REPO_NAME environment variable is missing. Cannot proceed." - exit 1 + echo "DST_REPO_NAME environment variable is missing. Cannot proceed." + exit 1 fi if [ "$SRC_WIKI" = "true" ]; then SRC_WIKI=".wiki" + exit 1 else SRC_WIKI="" + exit 1 fi if [ "$DST_WIKI" = "true" ]; then DST_WIKI=".wiki" + exit 1 else DST_WIKI="" fi +if [[ -n "$EXCLUDE" && -z "$FILTER" ]]; then + $FILTER=** + exit 1 +fi + BASE_PATH=$(pwd) DST_PATH="${DST_PATH:-${SRC_PATH}}" @@ -87,7 +95,6 @@ if [[ -n "$FILTER" ]]; then tmp_dir=$(mktemp -d -t ci-XXXXXXXXXX) cd ${SRC_REPO_NAME} FINAL_SOURCE="${tmp_dir}/${SRC_PATH}" - for f in ${FILTER} ; do [ -e "$f" ] || continue [ -d "$f" ] && continue @@ -97,8 +104,8 @@ if [[ -n "$FILTER" ]]; then file_dir=$(dirname "${f}") mkdir -p ${tmp_dir}/${file_dir} && cp ${f} ${tmp_dir}/${file_dir} done - cd ../ + exit 1 fi git clone --branch ${DST_BRANCH} --single-branch --depth 1 https://${PERSONAL_TOKEN}@github.com/${DST_REPO}.git From ddfbd71b8660ca89ab4d32d0569042c8cd8ca6c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Mon, 9 Mar 2020 15:56:46 +0100 Subject: [PATCH 18/48] Update entrypoint.sh --- entrypoint.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 5b86f0c..a96389a 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -40,15 +40,12 @@ fi if [ "$SRC_WIKI" = "true" ]; then SRC_WIKI=".wiki" - exit 1 else SRC_WIKI="" - exit 1 fi if [ "$DST_WIKI" = "true" ]; then DST_WIKI=".wiki" - exit 1 else DST_WIKI="" fi From 4c882d871dc3416a1a54f4a38cbb69f91cf0fc26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Mon, 9 Mar 2020 16:37:58 +0100 Subject: [PATCH 19/48] Update entrypoint.sh --- entrypoint.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index a96389a..3e0f520 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -52,7 +52,6 @@ fi if [[ -n "$EXCLUDE" && -z "$FILTER" ]]; then $FILTER=** - exit 1 fi BASE_PATH=$(pwd) @@ -102,7 +101,6 @@ if [[ -n "$FILTER" ]]; then mkdir -p ${tmp_dir}/${file_dir} && cp ${f} ${tmp_dir}/${file_dir} done cd ../ - exit 1 fi git clone --branch ${DST_BRANCH} --single-branch --depth 1 https://${PERSONAL_TOKEN}@github.com/${DST_REPO}.git From 3602c1e7af5a2255c5ddd109124a038da339aed9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Mon, 9 Mar 2020 17:01:16 +0100 Subject: [PATCH 20/48] Update entrypoint.sh --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 3e0f520..137440c 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -51,7 +51,7 @@ else fi if [[ -n "$EXCLUDE" && -z "$FILTER" ]]; then - $FILTER=** + FILTER="**" fi BASE_PATH=$(pwd) From 5d6c3abddd8f96134d272213889104a1e1a4a99c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Mon, 9 Mar 2020 17:20:13 +0100 Subject: [PATCH 21/48] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b9c43d3..33ce33f 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,8 @@ The following input variable options can/must be configured: |`dst_repo_name`|Required|The name of the repository to push to. For example, `copycat-action`.|| |`src_branch`|Optional|The branch name of the source repository.|`master`| |`dst_branch`|Optional|The branch name of the destination repository.|`master`| -|`src_filter`|Optional|A pattern for filtering files to be copied. For example `*.sh`|| +|`filter`|Optional|A glob pattern for filtering files to be copied. Acts on file paths. For example `**/*.sh`|| +|`exclude`|Optional|A glob pattern for excluding paths. For example `*/dev/*`|| |`src_wiki`|Optional|Set to `true` if the source repository you want to copy from is the GitHub Wiki.| `false`| |`dst_wiki`|Optional|Set to `true` if the destination repository you want to copy from is the GitHub Wiki.|`false`| |`username`|Optional|The GitHub username to associate commits made by this GitHub action.|[`GITHUB_ACTOR`](https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables)| From 1cc9f878870911ab94f3a3bad292f0ef3859a809 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Mon, 9 Mar 2020 18:43:42 +0100 Subject: [PATCH 22/48] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 33ce33f..4722325 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ The following input variable options can/must be configured: |`src_branch`|Optional|The branch name of the source repository.|`master`| |`dst_branch`|Optional|The branch name of the destination repository.|`master`| |`filter`|Optional|A glob pattern for filtering files to be copied. Acts on file paths. For example `**/*.sh`|| -|`exclude`|Optional|A glob pattern for excluding paths. For example `*/dev/*`|| +|`exclude`|Optional|A glob pattern for excluding paths. For example `*/tests/*`|| |`src_wiki`|Optional|Set to `true` if the source repository you want to copy from is the GitHub Wiki.| `false`| |`dst_wiki`|Optional|Set to `true` if the destination repository you want to copy from is the GitHub Wiki.|`false`| |`username`|Optional|The GitHub username to associate commits made by this GitHub action.|[`GITHUB_ACTOR`](https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables)| From 765e7b73fea9e2bf9945f641d0023c3d5e3ae04e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Mon, 9 Mar 2020 19:49:35 +0100 Subject: [PATCH 23/48] Add FILE_FILTER for filtering file names --- entrypoint.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 137440c..f92c7ab 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -16,6 +16,7 @@ DST_OWNER="$INPUT_DST_OWNER" DST_REPO_NAME="$INPUT_DST_REPO_NAME" SRC_BRANCH="$INPUT_SRC_BRANCH" DST_BRANCH="$INPUT_DST_BRANCH" +FILE_FILTER="$INPUT_FILE_FILTER" FILTER="$INPUT_FILTER" EXCLUDE="$INPUT_EXCLUDE" SRC_WIKI="$INPUT_SRC_WIKI" @@ -74,10 +75,10 @@ FINAL_SOURCE="${SRC_REPO_NAME}/${SRC_PATH}" git config --global user.name "${USERNAME}" git config --global user.email "${EMAIL}" -if [[ -z "$FILTER" ]]; then +if [[ -z "$FILE_FILTER" ]]; then echo "Copying \"${SRC_REPO_NAME}/${SRC_PATH}\" and pushing it to ${GITHUB_REPOSITORY}" else - echo "Copying files matching \"${FILTER}\" from \"${SRC_REPO_NAME}/${SRC_PATH}\" and pushing it to ${GITHUB_REPOSITORY}" + echo "Copying files matching \"${FILE_FILTER}\" from \"${SRC_REPO_NAME}/${SRC_PATH}\" and pushing it to ${GITHUB_REPOSITORY}" fi git clone --branch ${SRC_BRANCH} --single-branch --depth 1 https://${PERSONAL_TOKEN}@github.com/${SRC_REPO}.git @@ -87,6 +88,10 @@ if [ "$?" -ne 0 ]; then fi rm -rf ${SRC_REPO_NAME}/.git +if [[ -n "$FILE_FILTER" ]]; then + find ${SRC_REPO_NAME}/ -type f -not -name "${FILE_FILTER}" -exec rm {} \; +fi + if [[ -n "$FILTER" ]]; then tmp_dir=$(mktemp -d -t ci-XXXXXXXXXX) cd ${SRC_REPO_NAME} From 86cf62ff7de02f1362e5eede30c70076d694122d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Mon, 9 Mar 2020 19:55:10 +0100 Subject: [PATCH 24/48] Add file_filter --- action.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 401c6c2..a4965e5 100644 --- a/action.yml +++ b/action.yml @@ -28,8 +28,11 @@ inputs: description: 'The branch name of the destination repository' required: false default: 'master' + file_filter: + description: 'A glob pattern for filtering file names' + required: false filter: - description: 'A glob pattern for filtering files to be copied' + description: 'A glob pattern for filtering file paths to be included for copying' required: false exclude: description: 'A glob pattern for excluding paths' @@ -59,6 +62,7 @@ runs: - ${{ inputs.dst_repo_name }} - ${{ inputs.src_branch }} - ${{ inputs.dst_branch }} + - ${{ inputs.file_filter }} - ${{ inputs.filter }} - ${{ inputs.exclude }} - ${{ inputs.src_wiki }} From 7bc8cdd6b73b82e535731e078ddc8348eaa67b92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Mon, 9 Mar 2020 20:03:50 +0100 Subject: [PATCH 25/48] Add file_filter documentation --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4722325..7fdc141 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,8 @@ The following input variable options can/must be configured: |`dst_repo_name`|Required|The name of the repository to push to. For example, `copycat-action`.|| |`src_branch`|Optional|The branch name of the source repository.|`master`| |`dst_branch`|Optional|The branch name of the destination repository.|`master`| -|`filter`|Optional|A glob pattern for filtering files to be copied. Acts on file paths. For example `**/*.sh`|| +|`file_filter`|Optional|A simple glob pattern for filtering files to be copied. Acts on file basename. For example `*.sh`|| +|`filter`|Optional|A glob pattern for filtering files to be copied. Acts on file paths. For example `**/!(*.*)`|| |`exclude`|Optional|A glob pattern for excluding paths. For example `*/tests/*`|| |`src_wiki`|Optional|Set to `true` if the source repository you want to copy from is the GitHub Wiki.| `false`| |`dst_wiki`|Optional|Set to `true` if the destination repository you want to copy from is the GitHub Wiki.|`false`| From cd10b67dbcbed1efee91383ee5ee51989c55a6ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Mon, 9 Mar 2020 20:08:47 +0100 Subject: [PATCH 26/48] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7fdc141..1fae7cb 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ The following input variable options can/must be configured: |`src_wiki`|Optional|Set to `true` if the source repository you want to copy from is the GitHub Wiki.| `false`| |`dst_wiki`|Optional|Set to `true` if the destination repository you want to copy from is the GitHub Wiki.|`false`| |`username`|Optional|The GitHub username to associate commits made by this GitHub action.|[`GITHUB_ACTOR`](https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables)| -|`email`|Optional|The email used for associating commits made by this GitHub action.|[`GITHUB_ACTOR`](https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables)`@users.noreply.github.com`| +|`email`|Optional|The email used for associating commits made by this GitHub action.|[`GITHUB_ACTOR`](https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables) `@users.noreply.github.com`| ## Secrets From 1df8da03619f082d8f40ff7f6a2b47ff4599f89a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Mon, 9 Mar 2020 21:00:15 +0100 Subject: [PATCH 27/48] Create CHANGELOG.md --- CHANGELOG.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..abc76ea --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,29 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org). + +## [Unreleased] + +## [3.0.0] - 2020-03-09 +### Added +- Input variable `exclude` for path exclusion filter with glob patterns. +- Input variable `filter` for path filtering with glob patterns. +### Changed +- Renamed input variable `src_filter` to `file_filter`. + +## [2.0.0] - 2020-02-23 + +## [1.1.0] - 2019-08-29 + +## [1.0.1] - 2019-07-09 + +## 1.0.0 - 2019-07-09 + +[Unreleased]: https://github.com/andstor/copycat-action/compare/v3.0.0...HEAD +[3.0.0]: https://github.com/andstor/jsdoc-action/compare/v3.0.0...v3.0.0 +[2.0.0]: https://github.com/andstor/jsdoc-action/compare/v1.1.0...v2.0.0 +[1.1.0]: https://github.com/andstor/jsdoc-action/compare/v1.1.0...v1.0.1 +[1.0.1]: https://github.com/andstor/jsdoc-action/compare/v1.0.1...v1.0.1 +[1.0.1]: https://github.com/andstor/jsdoc-action/compare/v1.0.0...v1.0.1 From 1d0447e47926200a7f51fd65863ddd43d43376cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Mon, 9 Mar 2020 21:00:38 +0100 Subject: [PATCH 28/48] Update version number --- entrypoint.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index f92c7ab..1f99561 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,9 +1,9 @@ #!/bin/bash # # @author André Storhaug -# @date 2020-03-08 +# @date 2020-03-09 # @license MIT -# @version 2.1.0 +# @version 3.0.0 set -o pipefail From fb0e1147cefcde64ef455b4d78b3c1445285ce9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Mon, 9 Mar 2020 21:01:29 +0100 Subject: [PATCH 29/48] Update version number --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1fae7cb..759aa1d 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ The following example [workflow step](https://help.github.com/en/actions/configu ```yml - name: Copy - uses: andstor/copycat-action@v2 + uses: andstor/copycat-action@v3 with: personal_token: ${{ secrets.PERSONAL_TOKEN }} src_path: /. @@ -65,7 +65,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Copycat - uses: andstor/copycat-action@v2 + uses: andstor/copycat-action@v3 with: personal_token: ${{ secrets.PERSONAL_TOKEN }} src_path: /. From 4aa2348184893ebae32783019e7bedae09830760 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Mon, 9 Mar 2020 21:13:02 +0100 Subject: [PATCH 30/48] Update CHANGELOG.md --- CHANGELOG.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index abc76ea..20be974 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,8 +22,8 @@ and this project adheres to [Semantic Versioning](https://semver.org). ## 1.0.0 - 2019-07-09 [Unreleased]: https://github.com/andstor/copycat-action/compare/v3.0.0...HEAD -[3.0.0]: https://github.com/andstor/jsdoc-action/compare/v3.0.0...v3.0.0 -[2.0.0]: https://github.com/andstor/jsdoc-action/compare/v1.1.0...v2.0.0 -[1.1.0]: https://github.com/andstor/jsdoc-action/compare/v1.1.0...v1.0.1 -[1.0.1]: https://github.com/andstor/jsdoc-action/compare/v1.0.1...v1.0.1 -[1.0.1]: https://github.com/andstor/jsdoc-action/compare/v1.0.0...v1.0.1 +[3.0.0]: https://github.com/andstor/copycat-action/compare/v3.0.0...v3.0.0 +[2.0.0]: https://github.com/andstor/copycat-action/compare/v1.1.0...v2.0.0 +[1.1.0]: https://github.com/andstor/copycat-action/compare/v1.1.0...v1.0.1 +[1.0.1]: https://github.com/andstor/copycat-action/compare/v1.0.1...v1.0.1 +[1.0.1]: https://github.com/andstor/copycat-action/compare/v1.0.0...v1.0.1 From 88e4c448baac24ac6a036abee9cae30e44b784aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Mon, 9 Mar 2020 21:20:21 +0100 Subject: [PATCH 31/48] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 20be974..eba95a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). ## 1.0.0 - 2019-07-09 [Unreleased]: https://github.com/andstor/copycat-action/compare/v3.0.0...HEAD -[3.0.0]: https://github.com/andstor/copycat-action/compare/v3.0.0...v3.0.0 +[3.0.0]: https://github.com/andstor/copycat-action/compare/v2.0.0...v3.0.0 [2.0.0]: https://github.com/andstor/copycat-action/compare/v1.1.0...v2.0.0 [1.1.0]: https://github.com/andstor/copycat-action/compare/v1.1.0...v1.0.1 [1.0.1]: https://github.com/andstor/copycat-action/compare/v1.0.1...v1.0.1 From bcd66d2a3fced220c0f5eb71fb161f956b18cb8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Mon, 9 Mar 2020 21:24:48 +0100 Subject: [PATCH 32/48] Fix typo --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 1f99561..75654b7 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -105,7 +105,7 @@ if [[ -n "$FILTER" ]]; then file_dir=$(dirname "${f}") mkdir -p ${tmp_dir}/${file_dir} && cp ${f} ${tmp_dir}/${file_dir} done - cd ../ + cd .. fi git clone --branch ${DST_BRANCH} --single-branch --depth 1 https://${PERSONAL_TOKEN}@github.com/${DST_REPO}.git From 71f7d7ed5352641dc107a3260ce31bd0a532c104 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Mon, 9 Mar 2020 22:16:36 +0100 Subject: [PATCH 33/48] Add cleaning functionality --- entrypoint.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/entrypoint.sh b/entrypoint.sh index 75654b7..b0b2380 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -16,6 +16,7 @@ DST_OWNER="$INPUT_DST_OWNER" DST_REPO_NAME="$INPUT_DST_REPO_NAME" SRC_BRANCH="$INPUT_SRC_BRANCH" DST_BRANCH="$INPUT_DST_BRANCH" +CLEAN="$INPUT_CLEAN" FILE_FILTER="$INPUT_FILE_FILTER" FILTER="$INPUT_FILTER" EXCLUDE="$INPUT_EXCLUDE" @@ -114,6 +115,10 @@ if [ "$?" -ne 0 ]; then exit 1 fi +if [ "$CLEAN" = "true" ]; then + find ${FINAL_SOURCE} -delete +fi + mkdir -p ${DST_REPO_NAME}/${DIR} || exit "$?" cp -rf ${FINAL_SOURCE} ${DST_REPO_NAME}/${DST_PATH} || exit "$?" cd ${DST_REPO_NAME} || exit "$?" From c150c1ab27b751fb3c5a874d4a8c4688ad5dfd94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Mon, 9 Mar 2020 22:20:40 +0100 Subject: [PATCH 34/48] Add clean input variable --- action.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/action.yml b/action.yml index a4965e5..d1399c7 100644 --- a/action.yml +++ b/action.yml @@ -28,6 +28,9 @@ inputs: description: 'The branch name of the destination repository' required: false default: 'master' + clean: + description: 'Set to true if the dst_path should be emptied before copying' + required: false file_filter: description: 'A glob pattern for filtering file names' required: false @@ -62,6 +65,7 @@ runs: - ${{ inputs.dst_repo_name }} - ${{ inputs.src_branch }} - ${{ inputs.dst_branch }} + - ${{ inputs.clean }} - ${{ inputs.file_filter }} - ${{ inputs.filter }} - ${{ inputs.exclude }} From 2a8094f29c247d045d2984cb7e82e0e08fac3c98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Mon, 9 Mar 2020 22:23:12 +0100 Subject: [PATCH 35/48] Correct cleaning behavior --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index b0b2380..7ee2bbe 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -116,7 +116,7 @@ if [ "$?" -ne 0 ]; then fi if [ "$CLEAN" = "true" ]; then - find ${FINAL_SOURCE} -delete + find ${DST_REPO_NAME}/${DST_PATH} -delete fi mkdir -p ${DST_REPO_NAME}/${DIR} || exit "$?" From be724ebb8fd6cd6844f5f4982a6e42926b68b500 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Mon, 9 Mar 2020 22:24:47 +0100 Subject: [PATCH 36/48] Make input variable clean default to false --- action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/action.yml b/action.yml index d1399c7..1db8a0a 100644 --- a/action.yml +++ b/action.yml @@ -30,6 +30,7 @@ inputs: default: 'master' clean: description: 'Set to true if the dst_path should be emptied before copying' + default: false required: false file_filter: description: 'A glob pattern for filtering file names' From f7deb74a41d856ba2a00021117107d05d9aefe90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Mon, 9 Mar 2020 22:27:43 +0100 Subject: [PATCH 37/48] Add description for the "clean" input variable --- README.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 759aa1d..c35076a 100644 --- a/README.md +++ b/README.md @@ -30,15 +30,16 @@ The following input variable options can/must be configured: |Input variable|Necessity|Description|Default| |--------------------|--------|-----------|-------| -|`src_path`|Required|The source path to the file(s) or folder(s) to copy from. For example, `/.` or `path/to/home.md`.|| -|`dst_path`|Optional|The destination path to copy the file(s) or folder(s) to. For example, `/wiki/` or `path/to/index.md`. |`src_path`| -|`dst_owner`|Required|The name of the owner of the repository to push to. For example, `andstor`.|| -|`dst_repo_name`|Required|The name of the repository to push to. For example, `copycat-action`.|| +|`src_path`|Required|The source path to the file(s) or folder(s) to copy from. For example `/.` or `path/to/home.md`.|| +|`dst_path`|Optional|The destination path to copy the file(s) or folder(s) to. For example `/wiki/` or `path/to/index.md`. |`src_path`| +|`dst_owner`|Required|The name of the owner of the repository to push to. For example `andstor`.|| +|`dst_repo_name`|Required|The name of the repository to push to. For example `copycat-action`.|| |`src_branch`|Optional|The branch name of the source repository.|`master`| |`dst_branch`|Optional|The branch name of the destination repository.|`master`| -|`file_filter`|Optional|A simple glob pattern for filtering files to be copied. Acts on file basename. For example `*.sh`|| -|`filter`|Optional|A glob pattern for filtering files to be copied. Acts on file paths. For example `**/!(*.*)`|| -|`exclude`|Optional|A glob pattern for excluding paths. For example `*/tests/*`|| +|`clean`|Optional|Set to `true` if the `dst_path` should be emptied before copying.|`false`| +|`file_filter`|Optional|A simple glob pattern for filtering files to be copied. Acts on file basename. For example `*.sh`.|| +|`filter`|Optional|A glob pattern for filtering files to be copied. Acts on file paths. For example `**/!(*.*)`.|| +|`exclude`|Optional|A glob pattern for excluding paths. For example `*/tests/*`.|| |`src_wiki`|Optional|Set to `true` if the source repository you want to copy from is the GitHub Wiki.| `false`| |`dst_wiki`|Optional|Set to `true` if the destination repository you want to copy from is the GitHub Wiki.|`false`| |`username`|Optional|The GitHub username to associate commits made by this GitHub action.|[`GITHUB_ACTOR`](https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables)| From e52c8cd8f214790e5b19645067b30a161fc28215 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Mon, 9 Mar 2020 22:37:25 +0100 Subject: [PATCH 38/48] Add "clean" feature to CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index eba95a6..092c77c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). ## [3.0.0] - 2020-03-09 ### Added +- Input variable `clean` for optional removal of contents in the `dst_path` before copying. - Input variable `exclude` for path exclusion filter with glob patterns. - Input variable `filter` for path filtering with glob patterns. ### Changed From 8e872c50db06564c87150a4e3b6d4cf5378ca3d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Mon, 9 Mar 2020 23:27:09 +0100 Subject: [PATCH 39/48] Add filtering section --- README.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c35076a..4334ad0 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ The following input variable options can/must be configured: |`src_branch`|Optional|The branch name of the source repository.|`master`| |`dst_branch`|Optional|The branch name of the destination repository.|`master`| |`clean`|Optional|Set to `true` if the `dst_path` should be emptied before copying.|`false`| -|`file_filter`|Optional|A simple glob pattern for filtering files to be copied. Acts on file basename. For example `*.sh`.|| +|`file_filter`|Optional|A simple [pattern](https://www.gnu.org/software/findutils/manual/html_mono/find.html#Shell-Pattern-Matching) for filtering files to be copied. Acts on file basename. For example `*.sh`.|| |`filter`|Optional|A glob pattern for filtering files to be copied. Acts on file paths. For example `**/!(*.*)`.|| |`exclude`|Optional|A glob pattern for excluding paths. For example `*/tests/*`.|| |`src_wiki`|Optional|Set to `true` if the source repository you want to copy from is the GitHub Wiki.| `false`| @@ -49,6 +49,19 @@ The following input variable options can/must be configured: * `personal_token`: (required) GitHub Private Access Token used for the clone/push operations. To create it follow the [GitHub Documentation](https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line). +## Filtering +Copycat provides several ways of filtering which files you want to copy. +All three types of filtering can be applied simultaneously. + +### Input variables +#### `file_filter` +The `file_filter`input variable allows you to filter file basenames. Hence, you can for example only copy all text files by setting `file_filter`to `*.txt`. The variable only accepts simple [patterns](https://www.gnu.org/software/findutils/manual/html_mono/find.html#Shell-Pattern-Matching). + +#### `filter` +The `filter` input variable provides extensive globbing support. It also supports extended globbing and globstar. The globbing applies to file paths. So, to for example match all files that doesn't have a file extention, the pattern could look like `**/!(*.*)`. + +#### `exclude` +The `exclude` input variable can be used to exclude certain paths. It will apply to the file paths. One are for example able to exclude certain deirectory names. Setting `exclude` to `*/tests/*` results in only copying files that don't lie inside a folder named `tests` (both directly and indirectly). Here, a file with for example the path `foo/tests/bar/baz.txt` would not be copied over. ## Examples From e29379101ce5633f3ac17975923281df4245f2cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Tue, 10 Mar 2020 02:31:48 +0100 Subject: [PATCH 40/48] Fix problem with clean option --- entrypoint.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 7ee2bbe..ca7fcb9 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -70,7 +70,6 @@ SRC_REPO_NAME="${GITHUB_REPOSITORY#*/}${SRC_WIKI}" DST_REPO="${DST_OWNER}/${DST_REPO_NAME}${DST_WIKI}" DST_REPO_NAME="${DST_REPO_NAME}${DST_WIKI}" -DIR="${DST_PATH%/*}" FINAL_SOURCE="${SRC_REPO_NAME}/${SRC_PATH}" git config --global user.name "${USERNAME}" @@ -116,10 +115,14 @@ if [ "$?" -ne 0 ]; then fi if [ "$CLEAN" = "true" ]; then - find ${DST_REPO_NAME}/${DST_PATH} -delete + if [ -f "${DST_REPO_NAME}/${DST_PATH}" ] ; then + find ${DST_REPO_NAME}/${DST_PATH} -delete + else + find ${DST_REPO_NAME}/${DST_PATH%/*}/* -delete + fi fi -mkdir -p ${DST_REPO_NAME}/${DIR} || exit "$?" +mkdir -p ${DST_REPO_NAME}/${DST_PATH%/*} || exit "$?" cp -rf ${FINAL_SOURCE} ${DST_REPO_NAME}/${DST_PATH} || exit "$?" cd ${DST_REPO_NAME} || exit "$?" From 4adc390297365256f1e865d4d70c0baabff7aa62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Tue, 10 Mar 2020 03:04:39 +0100 Subject: [PATCH 41/48] Don't touch hidden files --- entrypoint.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/entrypoint.sh b/entrypoint.sh index ca7fcb9..08ec533 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -8,6 +8,7 @@ set -o pipefail shopt -s extglob globstar nullglob +shopt -u dotglob PERSONAL_TOKEN="$INPUT_PERSONAL_TOKEN" SRC_PATH="$INPUT_SRC_PATH" From 7bf2a7d5b5f0fdad00404ea5205062bfef1982f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Tue, 10 Mar 2020 04:06:36 +0100 Subject: [PATCH 42/48] Update entrypoint.sh --- entrypoint.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 08ec533..c8ce3c7 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -8,7 +8,6 @@ set -o pipefail shopt -s extglob globstar nullglob -shopt -u dotglob PERSONAL_TOKEN="$INPUT_PERSONAL_TOKEN" SRC_PATH="$INPUT_SRC_PATH" @@ -117,9 +116,9 @@ fi if [ "$CLEAN" = "true" ]; then if [ -f "${DST_REPO_NAME}/${DST_PATH}" ] ; then - find ${DST_REPO_NAME}/${DST_PATH} -delete + find ${DST_REPO_NAME}/${DST_PATH} -type f -not -path '*/\.git/*' -delete else - find ${DST_REPO_NAME}/${DST_PATH%/*}/* -delete + find ${DST_REPO_NAME}/${DST_PATH%/*}/* -type f -not -path '*/\.git/*' -delete fi fi From 1ea074d71db933ae1f1a323a039dcb8809055d43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Tue, 10 Mar 2020 14:37:50 +0100 Subject: [PATCH 43/48] Update entrypoint.sh --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index c8ce3c7..6307474 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -5,7 +5,7 @@ # @license MIT # @version 3.0.0 -set -o pipefail +set -xvo pipefail shopt -s extglob globstar nullglob From 8d528ba11469ee324636effe3d662e6d8aba88e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Tue, 10 Mar 2020 14:41:30 +0100 Subject: [PATCH 44/48] Update entrypoint.sh --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 6307474..241919d 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -7,7 +7,7 @@ set -xvo pipefail -shopt -s extglob globstar nullglob +shopt -s extglob globstar nullglob dotglob PERSONAL_TOKEN="$INPUT_PERSONAL_TOKEN" SRC_PATH="$INPUT_SRC_PATH" From 1db9c2fd3188536f3cc7339cb0fb3c2416b3afef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Tue, 10 Mar 2020 15:06:41 +0100 Subject: [PATCH 45/48] Update entrypoint.sh --- entrypoint.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 241919d..5366eb7 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -94,8 +94,9 @@ fi if [[ -n "$FILTER" ]]; then tmp_dir=$(mktemp -d -t ci-XXXXXXXXXX) + mkdir ${temp_dir}/${SRC_REPO_NAME} cd ${SRC_REPO_NAME} - FINAL_SOURCE="${tmp_dir}/${SRC_PATH}" + FINAL_SOURCE="${tmp_dir}/${SRC_REPO_NAME}/${SRC_PATH}" for f in ${FILTER} ; do [ -e "$f" ] || continue [ -d "$f" ] && continue @@ -103,7 +104,7 @@ if [[ -n "$FILTER" ]]; then [[ $f == $EXCLUDE ]] && continue fi file_dir=$(dirname "${f}") - mkdir -p ${tmp_dir}/${file_dir} && cp ${f} ${tmp_dir}/${file_dir} + mkdir -p ${tmp_dir}/${SRC_REPO_NAME}/${file_dir} && cp ${f} ${tmp_dir}/${SRC_REPO_NAME}/${file_dir} done cd .. fi From 758102e789d5e5ffe0f674720f7e766a59ad8e7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Tue, 10 Mar 2020 15:35:36 +0100 Subject: [PATCH 46/48] Update entrypoint.sh --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 5366eb7..4cc4ec9 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -5,7 +5,7 @@ # @license MIT # @version 3.0.0 -set -xvo pipefail +set -o pipefail shopt -s extglob globstar nullglob dotglob From 306b50a3dda6b74314252c1565a557876d696fd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Tue, 10 Mar 2020 16:15:26 +0100 Subject: [PATCH 47/48] Add check for cleaning directories If the source path is meant to be a file, and it doesn't exist the files entire directory would be cleaned. This is bad. Instead, only clean if the source path is a file or directory that **exists**. --- entrypoint.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 4cc4ec9..17b82ec 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -118,8 +118,10 @@ fi if [ "$CLEAN" = "true" ]; then if [ -f "${DST_REPO_NAME}/${DST_PATH}" ] ; then find ${DST_REPO_NAME}/${DST_PATH} -type f -not -path '*/\.git/*' -delete - else + elif [ -d "${DST_REPO_NAME}/${DST_PATH}" ] ; then find ${DST_REPO_NAME}/${DST_PATH%/*}/* -type f -not -path '*/\.git/*' -delete + else + echo >&2 "Nothing to clean 🧽" fi fi @@ -127,10 +129,10 @@ mkdir -p ${DST_REPO_NAME}/${DST_PATH%/*} || exit "$?" cp -rf ${FINAL_SOURCE} ${DST_REPO_NAME}/${DST_PATH} || exit "$?" cd ${DST_REPO_NAME} || exit "$?" -if [ -d "${BASE_PATH}/${FINAL_SOURCE}" ]; then - COMMIT_MESSAGE="Update file(s) in \"${SRC_PATH}\" from \"${GITHUB_REPOSITORY}\"" +if [ -f "${BASE_PATH}/${FINAL_SOURCE}" ]; then + COMMIT_MESSAGE="Update file in \"${SRC_PATH}\" from \"${GITHUB_REPOSITORY}\"" else - COMMIT_MESSAGE="Update file \"${SRC_PATH}\" from \"${GITHUB_REPOSITORY}\"" + COMMIT_MESSAGE="Update file(s) \"${SRC_PATH}\" from \"${GITHUB_REPOSITORY}\"" fi if [ -z "$(git status --porcelain)" ]; then From f8e71cd8141e71cc764bec8feae492f9883f138e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Storhaug?= Date: Tue, 10 Mar 2020 18:38:07 +0100 Subject: [PATCH 48/48] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 092c77c..34f696f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). ## [Unreleased] -## [3.0.0] - 2020-03-09 +## [3.0.0] - 2020-03-10 ### Added - Input variable `clean` for optional removal of contents in the `dst_path` before copying. - Input variable `exclude` for path exclusion filter with glob patterns.