Skip to content

Commit f87c68e

Browse files
committed
Add workflow to clean old GitHub Actions caches
Adds a scheduled GitHub Actions workflow (.github/workflows/cleanup_caches.yml) that runs weekly (and via workflow_dispatch) to delete Actions caches not accessed in the last 3 days. The job uses the gh CLI with the repository token and actions: write permission to list caches, filter by last_accessed_at against a 3-day cutoff, and delete matching cache IDs.
1 parent 687e8cf commit f87c68e

File tree

3 files changed

+43
-12
lines changed

3 files changed

+43
-12
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Cleanup Caches
2+
on:
3+
schedule:
4+
- cron: '0 3 * * 0' # every Sunday
5+
workflow_dispatch:
6+
7+
jobs:
8+
cleanup:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
actions: write
12+
steps:
13+
- name: Delete caches older than 3 days
14+
env:
15+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16+
run: |
17+
CUTOFF_DATE=$(date -d "3 days ago" -Ins --utc | sed 's/+0000/Z/')
18+
echo "Deleting caches older than: $CUTOFF_DATE"
19+
20+
CACHE_IDS=$(gh api --paginate repos/${{ github.repository }}/actions/caches \
21+
--jq ".actions_caches[] | select(.last_accessed_at < \"$CUTOFF_DATE\") | .id" 2>/dev/null)
22+
23+
if [ -z "$CACHE_IDS" ]; then
24+
echo "No old caches found to delete."
25+
else
26+
echo "$CACHE_IDS" | while read CACHE_ID; do
27+
echo "Deleting cache: $CACHE_ID"
28+
gh api -X DELETE repos/${{ github.repository }}/actions/caches/$CACHE_ID
29+
done
30+
echo "Old caches deleted successfully."
31+
fi

sub/subController.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package sub
33
import (
44
"encoding/base64"
55
"fmt"
6-
"strings"
76
"strconv"
7+
"strings"
88

99
"github.com/mhsanaei/3x-ui/v2/config"
1010

@@ -64,8 +64,8 @@ func NewSUBController(
6464
subEncrypt: encrypt,
6565
updateInterval: update,
6666

67-
subService: sub,
68-
subJsonService: NewSubJsonService(jsonFragment, jsonNoise, jsonMux, jsonRules, sub),
67+
subService: sub,
68+
subJsonService: NewSubJsonService(jsonFragment, jsonNoise, jsonMux, jsonRules, sub),
6969
}
7070
a.initRouter(g)
7171
return a
@@ -170,13 +170,13 @@ func (a *SUBController) subJsons(c *gin.Context) {
170170

171171
// ApplyCommonHeaders sets common HTTP headers for subscription responses including user info, update interval, and profile title.
172172
func (a *SUBController) ApplyCommonHeaders(
173-
c *gin.Context,
174-
header,
175-
updateInterval,
176-
profileTitle string,
173+
c *gin.Context,
174+
header,
175+
updateInterval,
176+
profileTitle string,
177177
profileSupportUrl string,
178-
profileUrl string,
179-
profileAnnounce string,
178+
profileUrl string,
179+
profileAnnounce string,
180180
profileEnableRouting bool,
181181
profileRoutingRules string,
182182
) {

web/service/tgbot.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2322,9 +2322,9 @@ func (t *Tgbot) buildSubscriptionURLs(email string) (string, string, error) {
23222322
// If pre-configured URIs are available, use them directly
23232323
if subURI != "" {
23242324
if !strings.HasSuffix(subURI, "/") {
2325-
subURI = subURI + "/"
2325+
subURI = subURI + "/"
23262326
}
2327-
subURL = fmt.Sprintf("%s%s", subURI, client.SubID)
2327+
subURL = fmt.Sprintf("%s%s", subURI, client.SubID)
23282328
} else {
23292329
subURL = fmt.Sprintf("%s://%s%s%s", scheme, host, subPath, client.SubID)
23302330
}
@@ -2333,7 +2333,7 @@ func (t *Tgbot) buildSubscriptionURLs(email string) (string, string, error) {
23332333
if !strings.HasSuffix(subJsonURI, "/") {
23342334
subJsonURI = subJsonURI + "/"
23352335
}
2336-
subJsonURL = fmt.Sprintf("%s%s", subJsonURI, client.SubID)
2336+
subJsonURL = fmt.Sprintf("%s%s", subJsonURI, client.SubID)
23372337
} else {
23382338

23392339
subJsonURL = fmt.Sprintf("%s://%s%s%s", scheme, host, subJsonPath, client.SubID)

0 commit comments

Comments
 (0)