|
| 1 | +name: Delta repository generator |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - master |
| 6 | +jobs: |
| 7 | + commit: |
| 8 | + runs-on: ubuntu-latest |
| 9 | + if: >- |
| 10 | + !( |
| 11 | + contains(github.event.head_commit.message, '[ci skip]') || |
| 12 | + contains(github.event.head_commit.message, '[skip ci]') || |
| 13 | + contains(github.event.head_commit.message, '[actions skip]') || |
| 14 | + contains(github.event.head_commit.message, '[skip actions]') |
| 15 | + ) |
| 16 | + env: |
| 17 | + REMOTE: ProjectIgnis/DeltaUtopia.git |
| 18 | + DESTINATION: DeltaUtopia/script |
| 19 | + BASE_SHA: 20200403 |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@v1 |
| 22 | + - name: Clone destination repository |
| 23 | + run: | |
| 24 | + cd $HOME |
| 25 | + git clone https://${{ secrets.DEPLOY_TOKEN }}@github.com/$REMOTE |
| 26 | + mkdir -p $DESTINATION |
| 27 | + - name: Copy new or changed files |
| 28 | + id: copy |
| 29 | + run: | |
| 30 | + ADDED=$(git diff --name-only --no-renames --diff-filter=d $BASE_SHA | grep -vP "(^|/)\..*" | grep -P "\.lua$") |
| 31 | + if [[ "$ADDED" ]]; then |
| 32 | + rsync -avR $ADDED $HOME/$DESTINATION |
| 33 | + fi |
| 34 | + - name: Remove deleted files |
| 35 | + run: | |
| 36 | + if [[ -f $HOME/$DESTINATION/VERSION ]]; then |
| 37 | + LAST_SHA=$(cat $HOME/$DESTINATION/VERSION) |
| 38 | + REMOVED=$(git diff --name-only --no-renames --diff-filter=D $LAST_SHA) |
| 39 | + if [[ "$REMOVED" ]]; then |
| 40 | + cd $HOME/$DESTINATION |
| 41 | + git rm -rf --ignore-unmatch $REMOVED |
| 42 | + fi |
| 43 | + fi |
| 44 | + - name: Commit and push with original metadata |
| 45 | + run: | |
| 46 | + MESSAGE=$(git log -1 --pretty=%B) |
| 47 | + AUTHOR=$(git log -1 --pretty=format:'%an') |
| 48 | + EMAIL=$(git log -1 --pretty=format:'%ae') |
| 49 | + COMMITTER=$(git log -1 --pretty=format'%cn') |
| 50 | + CEMAIL=$(git log -1 --pretty=format:'%ce') |
| 51 | + cd $HOME/$DESTINATION |
| 52 | + echo $GITHUB_SHA > VERSION |
| 53 | + git config user.email "$CEMAIL" |
| 54 | + git config user.name "$COMMITTER" |
| 55 | + git add -A . |
| 56 | + if [[ $(git status --porcelain) ]]; then |
| 57 | + git commit --author="$AUTHOR <$EMAIL>" -m "$MESSAGE" |
| 58 | + git push |
| 59 | + fi |
0 commit comments