-
Notifications
You must be signed in to change notification settings - Fork 3
123 lines (104 loc) · 4 KB
/
main.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
name: Checks
on:
push:
branches:
- '**'
workflow_dispatch:
# BOT_TOKEN is what I want to use most of the times,
# But deploy hates is for no reason, so I use
# GITHUB_TOKEN just for the deploy job
jobs:
format_repo:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }} # Make sure PR is checked out
- name: Install Prettier
run: npm install prettier
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Create Virtual Environment
run: python -m venv venv
- name: Activate venv
run: source venv/bin/activate
- name: Run pre_commit.py
run: python pys/pre_commit.py --format
- name: Commit changes
run: |
git config --global user.name "NSPBot911"
git config --global user.email ${{ secrets.BOT_EMAIL }}
git add -A
if git diff-index --quiet HEAD --; then
echo "No changes to commit"
else
git commit -m "[actions] Post Commit Checks Completed" -m "$(git log -1 --pretty=format:'%an') forgot to run pre_commit.py --format" -m "skip-checks: true"
git push
fi
env:
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
deploy_page:
needs: format_repo
if: github.ref == 'refs/heads/main' && !contains(github.event.head_commit.message, 'skip-deploy')
runs-on: ubuntu-latest
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Replace server IP in JavaScript
run: |
sed -i 's|const serverip = "localhost";|const serverip = "${{ secrets.IP_FOR_SERVER }}";|g' webUI/app.js
- name: Upload Artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./webUI
retention-days: 1
- name: Deploy to GitHub Pages
uses: actions/deploy-pages@v4
- name: Get Artifact ID
run: |
artifacts=$(curl -s -H "Authorization: token ${{ secrets.BOT_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/actions/artifacts)
artifact_id=$(echo "$artifacts" | jq -r '.artifacts[0] | select(.name == "github-pages") | .id')
echo "Artifact ID: $artifact_id"
echo "artifact_id=$artifact_id" >> $GITHUB_ENV
- name: Delete Artifact
if: env.artifact_id != ''
run: |
curl -X DELETE -H "Authorization: token ${{ secrets.BOT_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/actions/artifacts/$artifact_id
- name: Notify Discord
uses: sarisia/[email protected]
with:
webhook: ${{ secrets.LOG_HOOK }}
title: Page Deployed!
description: "Online at https://becomtweaks.github.io/resource-packs/"
avatar_url: "https://avatars.githubusercontent.com/u/176916861?v=4"
username: "NSPBot911"
nodetail: true
update_server:
needs: format_repo
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && !contains(github.event.head_commit.message, 'skip-update') && contains(github.event.head_commit.message, 'pack')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get latest commit title
id: get_commit
run: |
echo "commit_title=$(git log -1 --pretty=%s)" >> $GITHUB_ENV
- name: Trigger server-backend workflow
run: |
curl -X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${{ secrets.BOT_TOKEN }}" \
https://api.github.com/repos/BEComTweaks/server-backend/actions/workflows/106751072/dispatches \
-d "{\"ref\":\"main\", \"inputs\":{\"title\":\"resource-packs: ${{ env.commit_title }}\"}}"