|
| 1 | +# # |
| 2 | +# @type github workflow |
| 3 | +# @author Aetherinox |
| 4 | +# @url https://github.com/Aetherinox |
| 5 | +# @usage cleans all commit history for a repository |
| 6 | +# edit the 'environment:' to determine which deployment to keep clean |
| 7 | +# - can be ran manually |
| 8 | +# |
| 9 | +# @secrets secrets.SELF_TOKEN self github personal access token (fine-grained) |
| 10 | +# secrets.SELF_TOKEN_CL self github personal access token (classic) |
| 11 | +# secrets.NPM_TOKEN self npmjs access token |
| 12 | +# secrets.PYPI_API_TOKEN self Pypi API token (production site) - https://pypi.org/ |
| 13 | +# secrets.PYPI_API_TEST_TOKEN self Pypi API token (test site) - https://test.pypi.org/ |
| 14 | +# secrets.SELF_DOCKERHUB_TOKEN self Dockerhub token |
| 15 | +# secrets.ORG_TOKEN org github personal access token (fine-grained) |
| 16 | +# secrets.ORG_TOKEN_CL org github personal access token (classic) |
| 17 | +# secrets.ORG_DOCKERHUB_TOKEN org dockerhub secret |
| 18 | +# secrets.ORG_GITEA_TOKEN org gitea personal access token (classic) with package:write permission |
| 19 | +# secrets.BOT_GPG_KEY_ASC bot gpg private key (armored) | BEGIN PGP PRIVATE KEY BLOCK |
| 20 | +# secrets.BOT_GPG_PASSPHRASE bot gpg private key passphrase |
| 21 | +# secrets.DISCORD_WEBHOOK_CHAN_GITHUB_RELEASES discord webhook to report release notifications from github to discord |
| 22 | +# secrets.DISCORD_WEBHOOK_CHAN_GITHUB_WORKFLOWS discord webhook to report workflow notifications from github to discord |
| 23 | +# secrets.DISCORD_WEBHOOK_CHAN_GITHUB_UPDATES discord webhook to report activity notifications from github to discord |
| 24 | +# |
| 25 | +# |
| 26 | +# @local these workflows can be tested locally through the use of `act` |
| 27 | +# https://github.com/nektos/act |
| 28 | +# Extract act to folder |
| 29 | +# Add system env var with path to act.exe |
| 30 | +# Run the commands: |
| 31 | +# git pull https://github.com/username/repo |
| 32 | +# act -W .github/workflows/history-clean.yml -P ubuntu-latest=catthehacker/ubuntu:full-22.04 |
| 33 | +# act -W .github/workflows/history-clean.yml -s TOKEN_CL=XXXXXXXXXX --pull=false |
| 34 | +# # |
| 35 | + |
| 36 | +name: '🧹 History › Clean' |
| 37 | +run-name: '🧹 History › Clean' |
| 38 | + |
| 39 | +# # |
| 40 | +# triggers |
| 41 | +# # |
| 42 | + |
| 43 | +on: |
| 44 | + |
| 45 | + # # |
| 46 | + # Trigger > Workflow Dispatch |
| 47 | + # # |
| 48 | + |
| 49 | + workflow_dispatch: |
| 50 | + inputs: |
| 51 | + |
| 52 | + # # |
| 53 | + # Commit Label |
| 54 | + # |
| 55 | + # the label to use when repository is cleaned |
| 56 | + # # |
| 57 | + |
| 58 | + COMMIT_LABEL: |
| 59 | + description: '🏷️ Commit Label' |
| 60 | + required: true |
| 61 | + default: 'cleanup' |
| 62 | + type: string |
| 63 | + |
| 64 | + # # |
| 65 | + # Main Branch |
| 66 | + # |
| 67 | + # main branch re-recreate |
| 68 | + # # |
| 69 | + |
| 70 | + BRANCH_MAIN: |
| 71 | + description: '🌳 Main Branch' |
| 72 | + required: true |
| 73 | + default: 'main' |
| 74 | + type: string |
| 75 | + |
| 76 | + # # |
| 77 | + # Deployment Environment Name |
| 78 | + # |
| 79 | + # this is the name of the deployment item |
| 80 | + # # |
| 81 | + |
| 82 | + DEPLOYMENT_ENV: |
| 83 | + description: '📦 Deployment Environment' |
| 84 | + required: true |
| 85 | + default: 'orion' |
| 86 | + type: string |
| 87 | + |
| 88 | +# # |
| 89 | +# environment variables |
| 90 | +# # |
| 91 | + |
| 92 | +env: |
| 93 | + COMMIT_LABEL: ${{ github.event.inputs.COMMIT_LABEL || 'cleanup' }} |
| 94 | + BRANCH_MAIN: ${{ github.event.inputs.BRANCH_MAIN || 'main' }} |
| 95 | + DEPLOYMENT_ENV: ${{ github.event.inputs.DEPLOYMENT_ENV || 'orion' }} |
| 96 | + BOT_NAME_1: EuropaServ |
| 97 | + BOT_NAME_2: BinaryServ |
| 98 | + BOT_NAME_DEPENDABOT: dependabot[bot] |
| 99 | + BOT_NAME_RENOVATE: renovate[bot] |
| 100 | + |
| 101 | +# # |
| 102 | +# jobs |
| 103 | +# # |
| 104 | + |
| 105 | +jobs: |
| 106 | + history-clean: |
| 107 | + name: >- |
| 108 | + 🧹 History › Clean |
| 109 | + runs-on: ubuntu-latest |
| 110 | + # runs-on: apollo-x64 |
| 111 | + timeout-minutes: 5 |
| 112 | + steps: |
| 113 | + |
| 114 | + # # |
| 115 | + # History › Clean › Set TImestamps |
| 116 | + # # |
| 117 | + |
| 118 | + - name: >- |
| 119 | + 🕛 Get Timestamp |
| 120 | + id: task_history_clean_set_timestamp |
| 121 | + run: | |
| 122 | + echo "YEAR=$(date +'%Y')" >> $GITHUB_ENV |
| 123 | + echo "NOW=$(date +'%m-%d-%Y %H:%M:%S')" >> $GITHUB_ENV |
| 124 | + echo "NOW_SHORT=$(date +'%m-%d-%Y')" >> $GITHUB_ENV |
| 125 | + echo "NOW_LONG=$(date +'%m-%d-%Y %H:%M')" >> $GITHUB_ENV |
| 126 | + echo "NOW_DOCKER_LABEL=$(date +'%Y%m%d')" >> $GITHUB_ENV |
| 127 | +
|
| 128 | + # # |
| 129 | + # History › Clean › Checkout |
| 130 | + # # |
| 131 | + |
| 132 | + - name: >- |
| 133 | + ✅ Checkout |
| 134 | + id: task_history_clean_gh_checkout |
| 135 | + uses: actions/checkout@v4 |
| 136 | + with: |
| 137 | + fetch-depth: 0 |
| 138 | +
|
| 139 | + # # |
| 140 | + # History › Clean › Git Identify |
| 141 | + # # |
| 142 | + |
| 143 | + - name: >- |
| 144 | + 🪪 Configure Git Identity |
| 145 | + id: task_history_clean_git_ident |
| 146 | + run: | |
| 147 | + git config --local user.email "github-actions[bot]@users.noreply.github.com" |
| 148 | + git config --local user.name "github-actions[bot]" |
| 149 | +
|
| 150 | + # # |
| 151 | + # History › Clean › Pre-Commit |
| 152 | + # # |
| 153 | + |
| 154 | + - name: >- |
| 155 | + 📦 Commit › Pre-commit |
| 156 | + id: task_history_clean_commit_pre |
| 157 | + run: | |
| 158 | + now=$(date -u '+%m/%d/%Y %H:%M') |
| 159 | + commit_label="${{ env.COMMIT_LABEL }}" >> $GITHUB_ENV |
| 160 | + echo -e "$commit_label" |
| 161 | + commit_message="\\\`️️🧹 $commit_label 🧹\\\` \\\`$now UTC\\\`" >> $GITHUB_ENV |
| 162 | + echo -e "$commit_message" |
| 163 | + echo "COMMIT_MESSAGE=$(echo $commit_message)" >> $GITHUB_ENV |
| 164 | + echo "NOW=$(echo $now)" >> $GITHUB_ENV |
| 165 | +
|
| 166 | + # # |
| 167 | + # History › Clean › Pre-Commit › Debug |
| 168 | + # # |
| 169 | + |
| 170 | + - name: >- |
| 171 | + 📦 Commit › Pre-commit › Debug |
| 172 | + id: task_history_clean_commit_debug |
| 173 | + run: | |
| 174 | + echo -e "―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――" |
| 175 | + echo -e " Printing Values" |
| 176 | + echo -e "―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――" |
| 177 | + echo -e " env.COMMIT_LABEL .................... ${{ env.COMMIT_LABEL }}" |
| 178 | + echo -e " env.COMMIT_MESSAGE .................. ${{ env.COMMIT_MESSAGE }}" |
| 179 | + echo -e " env.NOW ............................. ${{ env.NOW }}" |
| 180 | +
|
| 181 | + # # |
| 182 | + # History › Clean › Start |
| 183 | + # # |
| 184 | + |
| 185 | + - name: >- |
| 186 | + 🧹 Clean Repo History |
| 187 | + id: task_history_clean_history |
| 188 | + run: | |
| 189 | + # Create a new orphan branch |
| 190 | + git checkout --orphan temp-branch |
| 191 | +
|
| 192 | + # Add all files to the new branch |
| 193 | + git add -A |
| 194 | +
|
| 195 | + # Commit the files to the new branch |
| 196 | + git commit -m "${{ env.COMMIT_MESSAGE }}" |
| 197 | +
|
| 198 | + # Delete the old main branch |
| 199 | + git branch -D ${{ env.BRANCH_MAIN }} |
| 200 | +
|
| 201 | + # Rename the new orphan branch to main |
| 202 | + git branch -m ${{ env.BRANCH_MAIN }} |
| 203 | +
|
| 204 | + # Force push the new main branch to the remote repository |
| 205 | + git push -f origin ${{ env.BRANCH_MAIN }} |
| 206 | +
|
| 207 | + # # |
| 208 | + # History › Clean › References |
| 209 | + # # |
| 210 | + |
| 211 | + - name: >- |
| 212 | + 🗑️ Clean References |
| 213 | + id: task_history_clean_references |
| 214 | + run: | |
| 215 | + # Remove remote-tracking references to deleted branches (optional) |
| 216 | + git fetch origin --prune |
| 217 | +
|
| 218 | + git reflog expire --expire=now --all |
| 219 | + git gc --prune=now --aggressive |
| 220 | +
|
| 221 | + # # |
| 222 | + # History › Clean › Commit |
| 223 | + # # |
| 224 | + |
| 225 | + - name: >- |
| 226 | + 📦 Commit › Execute |
| 227 | + id: task_history_clean_commit_execute |
| 228 | + uses: stefanzweifel/git-auto-commit-action@v5 |
| 229 | + with: |
| 230 | + commit_message: ${{ env.COMMIT_MESSAGE }} |
0 commit comments