-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from andstor/develop
v3.0.0
- Loading branch information
Showing
5 changed files
with
128 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# 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-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. | ||
- 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/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 | ||
[1.0.1]: https://github.com/andstor/copycat-action/compare/v1.0.0...v1.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
FROM alpine:3.10 | ||
|
||
RUN apk add --no-cache bash | ||
RUN apk add --no-cache git | ||
|
||
COPY entrypoint.sh /entrypoint.sh | ||
ENTRYPOINT ["/entrypoint.sh"] | ||
ENTRYPOINT ["/bin/bash", "-c", "/entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,43 @@ | ||
#!/bin/sh | ||
#!/bin/bash | ||
# | ||
# @author André Storhaug <[email protected]> | ||
# @date 2020-02-22 | ||
# @date 2020-03-09 | ||
# @license MIT | ||
# @version 2.0.0 | ||
# @version 3.0.0 | ||
|
||
set -o pipefail | ||
|
||
shopt -s extglob globstar nullglob dotglob | ||
|
||
PERSONAL_TOKEN="$INPUT_PERSONAL_TOKEN" | ||
SRC_PATH="$INPUT_SRC_PATH" | ||
DST_PATH="$INPUT_DST_PATH" | ||
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" | ||
SRC_WIKI="$INPUT_SRC_WIKI" | ||
DST_WIKI="$INPUT_DST_WIKI" | ||
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 | ||
|
@@ -46,6 +52,10 @@ else | |
DST_WIKI="" | ||
fi | ||
|
||
if [[ -n "$EXCLUDE" && -z "$FILTER" ]]; then | ||
FILTER="**" | ||
fi | ||
|
||
BASE_PATH=$(pwd) | ||
DST_PATH="${DST_PATH:-${SRC_PATH}}" | ||
|
||
|
@@ -60,15 +70,15 @@ 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}" | ||
git config --global user.email "${EMAIL}" | ||
|
||
if [[ -z "$SRC_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 \"${SRC_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 | ||
|
@@ -78,8 +88,25 @@ if [ "$?" -ne 0 ]; then | |
fi | ||
rm -rf ${SRC_REPO_NAME}/.git | ||
|
||
if [[ -n "$SRC_FILTER" ]]; then | ||
find ${SRC_REPO_NAME}/ -type f -not -name "${SRC_FILTER}" -exec rm {} \; | ||
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) | ||
mkdir ${temp_dir}/${SRC_REPO_NAME} | ||
cd ${SRC_REPO_NAME} | ||
FINAL_SOURCE="${tmp_dir}/${SRC_REPO_NAME}/${SRC_PATH}" | ||
for f in ${FILTER} ; do | ||
[ -e "$f" ] || continue | ||
[ -d "$f" ] && continue | ||
if [[ -n "$EXCLUDE" ]] ; then | ||
[[ $f == $EXCLUDE ]] && continue | ||
fi | ||
file_dir=$(dirname "${f}") | ||
mkdir -p ${tmp_dir}/${SRC_REPO_NAME}/${file_dir} && cp ${f} ${tmp_dir}/${SRC_REPO_NAME}/${file_dir} | ||
done | ||
cd .. | ||
fi | ||
|
||
git clone --branch ${DST_BRANCH} --single-branch --depth 1 https://${PERSONAL_TOKEN}@github.com/${DST_REPO}.git | ||
|
@@ -88,14 +115,24 @@ if [ "$?" -ne 0 ]; then | |
exit 1 | ||
fi | ||
|
||
mkdir -p ${DST_REPO_NAME}/${DIR} || exit "$?" | ||
cp -rf ${SRC_REPO_NAME}/${SRC_PATH} ${DST_REPO_NAME}/${DST_PATH} || exit "$?" | ||
if [ "$CLEAN" = "true" ]; then | ||
if [ -f "${DST_REPO_NAME}/${DST_PATH}" ] ; then | ||
find ${DST_REPO_NAME}/${DST_PATH} -type f -not -path '*/\.git/*' -delete | ||
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 | ||
|
||
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}/${SRC_REPO_NAME}/${SRC_PATH}" ]; 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 | ||
|