-
Notifications
You must be signed in to change notification settings - Fork 56
130 lines (115 loc) · 4.59 KB
/
nightly-build.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
124
125
126
127
128
129
130
name: Nightly Build
on:
workflow_dispatch:
schedule:
# 中国时间每天凌晨 2 点
- cron: '0 18 * * *'
env:
PARATRANZ_TOKEN: ${{ secrets.PARATRANZ_TOKEN }}
PARATRANZ_PROJECT_ID: ${{ secrets.PARATRANZ_PROJECT_ID }}
GIT_AUTHOR: MuXiu1997 <muxiu1997@gmail.com>
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
nightly-build:
name: Nightly Build
runs-on: ubuntu-latest
steps:
- name: Checkout MuXiu1997/GTNH-translation-compare
uses: actions/checkout@v3
with:
repository: MuXiu1997/GTNH-translation-compare
ref: main
- name: Ensure Dependencies
uses: ./.github/actions/ensure-dependencies
- name: Checkout
uses: actions/checkout@v3
with:
path: repo
- name: Setup Datetime Related Envs
shell: python
run: |
import os
from datetime import datetime, timezone, timedelta
local_date = datetime.now(timezone(timedelta(hours=8))).strftime("%Y-%m-%d")
local_time = datetime.now(timezone(timedelta(hours=8))).strftime("%H:%M:%S")
with open(os.environ['GITHUB_ENV'], 'a') as f:
print(f'NB_LOCAL_DATE={local_date}', file=f)
print(f'NB_LOCAL_TIME={local_time}', file=f)
print(f'NB_TAG=0-nightly-build/{local_date}', file=f)
- name: ParaTranz To Quest Book
run: >-
poetry run python main.py action paratranz-to-quest-book
--repo-path='repo'
- name: ParaTranz To Lang And zs
run: >-
poetry run python main.py action paratranz-to-lang-and-zs
--repo-path='repo'
- name: ParaTranz To GT Lang
run: >-
poetry run python main.py action paratranz-to-gt-lang
--repo-path='repo'
- name: Ensure Temp Dir
run: mkdir -p temp
- name: Ensure Assets Dir
run: mkdir -p assets
- name: Pack
run: |
python repo/.github/scripts/pack.py
rm temp/GregTech_US.lang
- name: Zip
uses: edgarrc/action-7z@v1
with:
args: 7z a -t7z -mx=9 ./repo/assets/nightly-${{ env.NB_LOCAL_DATE }}.7z ./temp/*
- name: Push tag
working-directory: repo
run: |
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
git checkout --orphan temp
git reset HEAD -- .
git commit --allow-empty -m "Nightly Build ${{ env.NB_LOCAL_DATE }} ${{ env.NB_LOCAL_TIME }}"
git tag ${{ env.NB_TAG }}
git push --delete origin ${{ env.NB_TAG }} || true
git push origin ${{ env.NB_TAG }}
- name: Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ env.NB_TAG }}
name: 每日构建 - ${{ env.NB_LOCAL_DATE }}
body: |
请阅读主页ReadMe以获知详细用法
自动构建于 ${{ env.NB_LOCAL_DATE }} ${{ env.NB_LOCAL_TIME }}
files: |
./repo/assets/nightly-${{ env.NB_LOCAL_DATE }}.7z
cleanup-outdated-nightly-builds:
name: Cleanup Outdated Nightly Builds
runs-on: ubuntu-latest
steps:
- name: Setup Datetime Related Envs
shell: python
run: |
import os
from datetime import datetime, timezone, timedelta
local_date = datetime.now(timezone(timedelta(hours=8))).strftime("%Y-%m-%d")
local_time = datetime.now(timezone(timedelta(hours=8))).strftime("%H:%M:%S")
with open(os.environ['GITHUB_ENV'], 'a') as f:
print(f'NB_LOCAL_DATE={local_date}', file=f)
print(f'NB_LOCAL_TIME={local_time}', file=f)
print(f'NB_TAG=0-nightly-build/{local_date}', file=f)
- name: Cleanup Outdated Nightly Builds
uses: MuXiu1997/run-zx@v0.2.1
with:
# language=javascript
script: |
import * as core from '@actions/core'
const repo = '${{ github.repository }}'
const listReleases = await $`gh release list --repo ${repo}`
const tags = listReleases.stdout.trim().split('\n')
.map(r => r.split('\t')[2])
.filter(t => t.startsWith('0-nightly-build'))
.filter(t => t !== '${{ env.NB_TAG }}')
const tagsToDelete = [...new Set(tags)].sort().slice(0, -2)
core.info(`Tags to delete: [${tagsToDelete.join(', ')}]`)
for (const tag of tagsToDelete) {
await $`gh release delete ${tag} --repo ${repo} --yes`
}