Skip to content

Commit

Permalink
Only one archive update commit
Browse files Browse the repository at this point in the history
  • Loading branch information
npanuhin committed Feb 14, 2024
1 parent a33cc93 commit 65a3348
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 1 deletion.
19 changes: 18 additions & 1 deletion .github/workflows/daily_update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
uses: actions/checkout@v4
with:
token: ${{ secrets.GH_PAT }}
fetch-depth: 2

- name: Install Python
uses: actions/setup-python@v5
Expand All @@ -40,9 +41,25 @@ jobs:
CLOUDFLARE_AWS_ACCESS_KEY_ID: '${{ secrets.CLOUDFLARE_AWS_ACCESS_KEY_ID }}'
CLOUDFLARE_AWS_SECRET_ACCESS_KEY: '${{ secrets.CLOUDFLARE_AWS_SECRET_ACCESS_KEY }}'

- name: Check previous commit
id: previous_commit
run: echo "PREVIOUS_COMMIT_AUHOUR=$(git log -1 --pretty=%an)" >> "$GITHUB_OUTPUT"

- name: Commit and push changes
if: ${{ steps.previous_commit.outputs.PREVIOUS_COMMIT_AUHOUR == "GitHub Actions" }}
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Archive update
commit_user_name: GitHub Actions
commit_author: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com>
commit_options: --amend --no-edit
push_options: --force
skip_fetch: true

- name: Commit and push changes
if: ${{ steps.previous_commit.outputs.PREVIOUS_COMMIT_AUHOUR != "GitHub Actions" }}
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "Archive update"
commit_message: Archive update
commit_user_name: GitHub Actions
commit_author: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com>
51 changes: 51 additions & 0 deletions src/old/scripts/compress_commits.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

clear

# Get current branch name
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)

# Get the commit list
commits=$(git log --oneline --pretty=format:"%H|%s|%an|%ae|%ad")

# Initialize variables to track next commit
next_commit_hash=""
next_commit_message=""

# Loop through the commits
while IFS='|' read -r commit_hash commit_message author_name author_email author_date; do

if [ "$commit_message" = "Archive update" ] && [ "$next_commit_message" = "Archive update" ]; then
echo "Squashing $commit_hash into $next_commit_hash"

# Checkout the parent of the asked commit
git -c advice.detachedHead=false checkout "$commit_hash"
git checkout HEAD~

# Merge the commit into it's parent, keeping the commit message of the parent
git merge --squash "$commit_hash"
git add .
git add --update

export GIT_COMMITTER_NAME="$author_name"
export GIT_COMMITTER_EMAIL="$author_email"
export GIT_COMMITTER_DATE="$author_date"
git commit --amend --no-edit

# Store the current commit
newcommit=$(git rev-parse HEAD)

# Rebase the starting branch onto the new commit
echo "Checking out $BRANCH_NAME"
git checkout "$BRANCH_NAME"
echo "Rebasing"
git rebase --committer-date-is-author-date -X theirs "$newcommit"

break
fi

# Update nextious commit variables
next_commit_hash=$commit_hash
next_commit_message=$commit_message
done <<< "$commits"

18 changes: 18 additions & 0 deletions src/old/scripts/reset_committer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
print(commit.author_name, commit.committer_name, commit.author_name.decode('utf-8') == 'GitHub Actions' and commit.author_name != commit.committer_name)

if commit.author_name.decode('utf-8') == 'GitHub Actions' and commit.author_name != commit.committer_name:
print(f'Commit {commit.id} has different author and committer: {commit.author_name} != {commit.committer_name}')
commit.committer_name = commit.author_name
commit.committer_email = commit.author_email
commit.committer_date = commit.author_date


# def handle(commit):
# 'Reset the timezone of all commits.'
# date_str = commit.author_date.decode('utf-8')
# [seconds, timezone] = date_str.split()
# new_date = f'{seconds} +0000'
# commit.author_date = new_date.encode('utf-8')


# handle(commit)
4 changes: 4 additions & 0 deletions src/old/scripts/reset_committer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
git filter-repo --commit-callback "$(cat src/scripts/reset_committer.py)"
git remote add origin "[email protected]:npanuhin/Bing-Wallpaper-Archive.git"
git fetch origin
git branch --set-upstream-to=origin/master master
11 changes: 11 additions & 0 deletions src/old/scripts/reset_committer_branch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
clear
set FILTER_BRANCH_SQUELCH_WARNING=1
git filter-branch -f --commit-filter '
if [[ $(git show -s --format=%an "$GIT_COMMIT") == "GitHub Actions" && $(git show -s --format=%ae "$GIT_COMMIT") == $(git show -s --format=%ce "$GIT_COMMIT") ]];
then
echo "$(git show -s --format=%an "$GIT_COMMIT")";
GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME";
GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL";
GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE";
fi
git commit-tree "$@";' HEAD

0 comments on commit 65a3348

Please sign in to comment.