-
Notifications
You must be signed in to change notification settings - Fork 2
67 lines (57 loc) · 2.03 KB
/
auto-update.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Automated Resource Update Workflow
name: Automated Resource Update Workflow
# Define when the workflow should run.
on:
# Scheduled to run daily.
schedule:
- cron: "0 0 * * *"
# Triggered when changes are pushed to specified paths.
push:
paths:
- "assets/**"
# Triggered manually by workflow_dispatch event.
workflow_dispatch:
jobs:
update_resources:
name: Update and Manage Resources
runs-on: ubuntu-latest
steps:
# Step 1: Check out the repository code.
- name: Check out code
uses: actions/checkout@v4
# Step 2: Set up Go environment based on go.mod file.
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
cache: true
check-latest: true
# Step 3: Download dependencies using Go modules.
- name: Get dependencies
run: go mod download
# Step 4: Build the Go application.
- name: Build Application
run: go build .
# Step 5: Generate new resources using content-blocker tool.
- name: Generate New Resources
run: ./content-blocker -update -logs
# Step 6: Commit and push updates to the repository.
- name: Commit and Push Updates
run: |
# Set GitHub Actions bot as the commit author.
git config --global user.name "${{ github.actor }}"
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
# Stage all changes.
git add .
# Commit changes with a timestamp.
git commit -m "Automated update: $(date)"
# Fetch the latest changes from the remote main branch.
git fetch
# Rebase local changes on top of the fetched changes to avoid conflicts.
git rebase origin/main
# Push the changes to the main branch if rebase was successful.
if [ $? -eq 0 ]; then
git push origin HEAD:refs/heads/main
else
echo "Rebase failed. Please resolve conflicts manually."
fi