-
Notifications
You must be signed in to change notification settings - Fork 1.1k
167 lines (148 loc) · 6.14 KB
/
packer.yml
File metadata and controls
167 lines (148 loc) · 6.14 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
name: Packer
on:
workflow_dispatch:
push:
branches: [ main ]
paths:
- 'src/**'
- 'config/packer/**'
- 'projects/**'
- '.github/workflows/packer.yml'
jobs:
build-packer:
name: Build / Cache Packer
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
sparse-checkout: src
# 缓存程序。一方面,在不同job之间需要这么做;另一方面,大约可以改善运行时间?
# actions/cache的逻辑会在job末尾缓存打包程序;如果不命中,就自行构造程序。
- name: Cache Packer
id: cache-packer
uses: actions/cache@v4
with:
key: ${{ runner.os }}-Packer-${{ hashFiles('src/Packer/**') }}
path: |
build/Packer.exe
build/git2-*.dll
lookup-only: true
# 构造程序
- name: Build Packer if not cached
if: steps.cache-packer.outputs.cache-hit != 'true'
# dotnet/sdk#51806 Console Projects fail to compile with <ArtifactsPath>$(MSBuildThisFileDirectory)
run: dotnet publish .\src\Packer\Packer.csproj -o ./build -r win-x64
build-uploader:
if: github.repository == 'CFPAOrg/Minecraft-Mod-Language-Package'
name: Build / Cache Uploader
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
sparse-checkout: src
# 缓存程序。一方面,在不同job之间需要这么做;另一方面,大约可以改善运行时间?
# actions/cache的逻辑会在job末尾缓存打包程序;如果不命中,就自行构造程序。
- name: Cache Uploader
id: cache-uploader
uses: actions/cache@v4
with:
key: ${{ runner.os }}-Uploader-${{ hashFiles('src/Uploader/**') }}
path: build/Uploader.exe
lookup-only: true
# 构造程序
- name: Build Uploader if not cached
if: steps.cache-uploader.outputs.cache-hit != 'true'
# dotnet/sdk#51806 Console Projects fail to compile with <ArtifactsPath>$(MSBuildThisFileDirectory)
run: dotnet publish .\src\Uploader\Uploader.csproj -o ./build -r win-x64
pack:
name: Pack Resources and Upload Artifacts/Releases
needs: [ build-packer ]
strategy:
fail-fast: false
matrix:
# 版本列表。将对这里的每个版本判断,按需打包。
# 如需添加新版本,在这里添加即可。
version: [ "1.12.2", "1.16", "1.16-fabric", "1.18", "1.18-fabric", "1.19", "1.20", "1.20-fabric", "1.21", "1.21-fabric" ]
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 20 # 显然,需要有提交历史才能比较提交。20这个数是任意的。
# 由于Github的限制,这里需要重新拉取打包程序。
- name: Restore Packer
id: cache-restore
uses: actions/cache/restore@v4
with:
key: ${{ runner.os }}-Packer-${{ hashFiles('src/Packer/**') }}
path: |
build/Packer.exe
build/git2-*.dll
fail-on-cache-miss: true # 应由前序保证
# dotnet/sdk#51806 Console Projects fail to compile with <ArtifactsPath>$(MSBuildThisFileDirectory)
- run: mv ./build/* .
shell: bash
- name: Check changed path on ${{ matrix.version }}
uses: MarceloPrado/has-changed-path@v1.0
id: check-changes
with:
# 判断位置:该版本文件、该版本配置、代码
paths: >
.github/workflows/packer.yml
projects/${{ matrix.version }}
config/packer/${{ matrix.version }}.json
src/**
- name: Run Packer for ${{ matrix.version }}
# 分发包中应当包含全部内容
run: ./Packer --version="${{ matrix.version }}"
# 运行逻辑:内容有更改 或 手动运行
if: steps.check-changes.outputs.changed == 'true' || github.event_name == 'workflow_dispatch'
# Artifact 上传内容:每个版本一个压缩包,包含了资源包和md5校验文件
- name: Upload Artifact for ${{ matrix.version }}
uses: actions/upload-artifact@v4
with:
name: Minecraft-Mod-Language-Modpack-${{ matrix.version }}
path: |
Minecraft-Mod-Language-Modpack-${{ matrix.version }}.zip
${{ matrix.version }}.md5
if: steps.check-changes.outputs.changed == 'true' || github.event_name == 'workflow_dispatch'
upload:
concurrency:
group: packer-upload
cancel-in-progress: false
if: github.repository == 'CFPAOrg/Minecraft-Mod-Language-Package'
name: Upload Resource Packs to Various places
needs: [ pack, build-uploader ]
runs-on: windows-latest
steps:
- uses: actions/checkout@v4 # 计算 cache key 需要
with:
fetch-depth: 1
sparse-checkout: src
- name: Restore Uploader
id: cache-restore
uses: actions/cache/restore@v4
with:
key: ${{ runner.os }}-Uploader-${{ hashFiles('src/Uploader/**') }}
path: |
build/Uploader.exe
fail-on-cache-miss: true # 应由前序保证
# dotnet/sdk#51806 Console Projects fail to compile with <ArtifactsPath>$(MSBuildThisFileDirectory)
- run: mv ./build/* .
shell: bash
# 还原artifact(资源包)
- name: Restore Artifacts
uses: actions/download-artifact@v4
with:
path: artifacts/
# feat: UTC 20:00~21:00 取消上传(避开远程服务器的4:00-4:10)
- name: Fail at inappropriate time
run: if [ `date -u +%H` -eq 20 ]; then exit -1; fi
shell: bash
- name: Run Uploader
run: .\Uploader --host="${{ secrets.SSH_IP }}" --name="${{ secrets.SSH_USER }}" --password="${{ secrets.SSH_PWD }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SHA: ${{ github.sha }}
REPO_ID: ${{ github.repository_id }}