Skip to content

Commit 363618c

Browse files
committed
ci: add workflows
1 parent 4d299d6 commit 363618c

9 files changed

Lines changed: 4159 additions & 0 deletions

.github/workflows/deploy-clean.yml

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
# #
2+
# @type github workflow
3+
# @author Aetherinox
4+
# @url https://github.com/Aetherinox
5+
# @usage cleans up the list of deployments in the environment history
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/deploy-clean.yml -P ubuntu-latest=catthehacker/ubuntu:full-22.04
33+
# act -W .github/workflows/deploy-clean.yml -s TOKEN_CL=XXXXXXXXXX --pull=false
34+
# #
35+
36+
# #
37+
38+
name: '🧹 Deployments › Clean'
39+
run-name: '🧹 Deployments › Clean'
40+
41+
# #
42+
# triggers
43+
# #
44+
45+
on:
46+
47+
# #
48+
# Trigger > Workflow Dispatch
49+
# #
50+
51+
workflow_dispatch:
52+
inputs:
53+
54+
# #
55+
# Deployment Environment Name
56+
#
57+
# this is the name of the deployment item
58+
# #
59+
60+
DEPLOYMENT_ENV:
61+
description: '📦 Deployment Environment'
62+
required: true
63+
default: 'orion'
64+
type: string
65+
66+
# #
67+
# Delay
68+
#
69+
# Milliseconds to wait between cleaning up each action in history. Avoids secondary rate limit. Default: 500
70+
# #
71+
72+
DEPLOYMENT_DELAY:
73+
description: '🕛 Delete Delay'
74+
required: true
75+
default: '1000'
76+
type: string
77+
78+
# #
79+
# environment variables
80+
# #
81+
82+
env:
83+
DEPLOYMENT_ENV: ${{ github.event.inputs.DEPLOYMENT_ENV || 'orion' }}
84+
DEPLOYMENT_DELAY: ${{ github.event.inputs.DEPLOYMENT_DELAY || '1000' }}
85+
BOT_NAME_1: EuropaServ
86+
BOT_NAME_2: BinaryServ
87+
BOT_NAME_DEPENDABOT: dependabot[bot]
88+
BOT_NAME_RENOVATE: renovate[bot]
89+
90+
# #
91+
# jobs
92+
# #
93+
94+
jobs:
95+
cleanup:
96+
name: >-
97+
🧹 Deployments › Clean
98+
runs-on: ubuntu-latest
99+
# runs-on: apollo-x64
100+
timeout-minutes: 5
101+
permissions: write-all
102+
103+
steps:
104+
105+
# #
106+
# Cleanup › Set Env Variables
107+
# #
108+
109+
- name: >-
110+
🕛 Get Timestamp
111+
id: task_cleanup_set_timestamp
112+
run: |
113+
echo "YEAR=$(date +'%Y')" >> $GITHUB_ENV
114+
echo "NOW=$(date +'%m-%d-%Y %H:%M:%S')" >> $GITHUB_ENV
115+
echo "NOW_SHORT=$(date +'%m-%d-%Y')" >> $GITHUB_ENV
116+
echo "NOW_LONG=$(date +'%m-%d-%Y %H:%M')" >> $GITHUB_ENV
117+
echo "NOW_DOCKER_LABEL=$(date +'%Y%m%d')" >> $GITHUB_ENV
118+
119+
# #
120+
# Release › Github › Checkout › Arm64
121+
# #
122+
123+
- name: >-
124+
✅ Checkout
125+
id: task_cleanup_gh_checkout
126+
uses: actions/checkout@v4
127+
with:
128+
fetch-depth: 0
129+
130+
# #
131+
# Cleanup › Start
132+
# #
133+
134+
- name: >-
135+
⚙️ Deployments › Clean
136+
id: task_cleanup_start
137+
uses: Aetherinox/delete-deploy-env-action@v3
138+
with:
139+
token: ${{ secrets.SELF_TOKEN_CL }}
140+
environment: '${{ env.DEPLOYMENT_ENV }}'
141+
onlyRemoveDeployments: true
142+
delay: "${{ env.DEPLOYMENT_DELAY }}"
143+
144+
# #
145+
# Cleanup › Get Weekly Commits
146+
# #
147+
148+
- name: >-
149+
🕛 Get Weekly Commit List
150+
id: task_cleanup_set_weekly_commit_list
151+
run: |
152+
echo 'WEEKLY_COMMITS<<EOF' >> $GITHUB_ENV
153+
git log --format="[\`%h\`](${{ github.server_url }}/${{ github.repository }}/commit/%H) %s - %an" --since=7.days >> $GITHUB_ENV
154+
echo 'EOF' >> $GITHUB_ENV
155+
Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
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

Comments
 (0)