-
Notifications
You must be signed in to change notification settings - Fork 2
158 lines (151 loc) · 5.27 KB
/
ci.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
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
name: ci
on:
push:
schedule:
- cron: '00 01 * * *'
jobs:
test:
name: test
runs-on: ${{ matrix.os }}
env:
CARGO: cargo
TARGET:
strategy:
fail-fast: false
matrix:
build:
- linux-musl
- macos
- win-msvc
include:
- build: linux-musl
os: ubuntu-latest
target: x86_64-unknown-linux-musl
- build: macos
os: macos-latest
target: x86_64-apple-darwin
- build: win-msvc
os: windows-latest
target: x86_64-pc-windows-msvc
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v3
name: Clone tokens
with:
path: assets/
repository: pdx-tools/tokens
token: ${{secrets.GH_PAT}}
- name: Cache saves
uses: actions/cache@v3
with:
path: assets/saves
key: assets/saves
- name: Set cross environment variables
if: matrix.build != 'macos' && matrix.build != 'win-msvc'
run: |
echo "EU4_IRONMAN_TOKENS=/project/assets/tokens/eu4.txt" >> $GITHUB_ENV
echo "CK3_IRONMAN_TOKENS=/project/assets/tokens/ck3.txt" >> $GITHUB_ENV
echo "IMPERATOR_TOKENS=/project/assets/tokens/imperator.txt" >> $GITHUB_ENV
echo "HOI4_IRONMAN_TOKENS=/project/assets/tokens/hoi4.txt" >> $GITHUB_ENV
echo "VIC3_IRONMAN_TOKENS=/project/assets/tokens/vic3.txt" >> $GITHUB_ENV
- name: Set cargo environment variables
if: matrix.build == 'macos' || matrix.build == 'win-msvc'
shell: bash
run: |
echo "EU4_IRONMAN_TOKENS=$current_dir/assets/tokens/eu4.txt" >> $GITHUB_ENV
echo "CK3_IRONMAN_TOKENS=$current_dir/assets/tokens/ck3.txt" >> $GITHUB_ENV
echo "IMPERATOR_TOKENS=$current_dir/assets/tokens/imperator.txt" >> $GITHUB_ENV
echo "HOI4_IRONMAN_TOKENS=$current_dir/assets/tokens/hoi4.txt" >> $GITHUB_ENV
echo "VIC3_IRONMAN_TOKENS=$current_dir/assets/tokens/vic3.txt" >> $GITHUB_ENV
env:
current_dir: ${{ github.workspace }}
- name: Install Cross
if: matrix.build != 'macos' && matrix.build != 'win-msvc'
run: |
cargo install --version 0.2.1 cross
echo "CARGO=cross" >> $GITHUB_ENV
- name: Check work
run: |
echo "CARGO=${{ env.CARGO }}"
echo "EU4_IRONMAN_TOKENS=${{ env.EU4_IRONMAN_TOKENS }}"
echo "CK3_IRONMAN_TOKENS=${{ env.CK3_IRONMAN_TOKENS }}"
echo "IMPERATOR_TOKENS=${{ env.IMPERATOR_TOKENS }}"
echo "HOI4_IRONMAN_TOKENS=${{ env.HOI4_IRONMAN_TOKENS }}"
echo "VIC3_IRONMAN_TOKENS=${{ env.VIC3_IRONMAN_TOKENS }}"
- name: Build
run: ${{ env.CARGO }} build --verbose --target "${{ matrix.target }}"
- name: Test
run: ${{ env.CARGO }} test --verbose --target "${{ matrix.target }}"
- name: Build Release Artifact
run: ${{ env.CARGO }} build --release --verbose --target "${{ matrix.target }}"
- name: Stage Release
shell: bash
run: |
if [[ "${GITHUB_REF}" = *refs/tags/* ]]; then
VERSION="${GITHUB_REF#refs/tags/}"
else
VERSION="vnightly"
fi
echo "version is $VERSION"
STAGING="rakaly-${VERSION:1}-${{ matrix.target }}"
echo "STAGING DIR: $STAGING"
mkdir $STAGING
if [[ "${{ matrix.os }}" = windows* ]]; then
cp "target/${{ matrix.target }}/release/rakaly.exe" "$STAGING/"
else
strip "target/${{ matrix.target }}/release/rakaly"
cp "target/${{ matrix.target }}/release/rakaly" "$STAGING/"
fi
echo "ASSET=$STAGING" >> $GITHUB_ENV
- uses: actions/upload-artifact@v3
with:
path: ${{ env.ASSET }}
name: ${{ env.ASSET }}
if-no-files-found: error
release:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
path: artifacts-temp
- name: Flatten artifacts
run: |
mkdir artifacts
cd artifacts-temp
for i in *; do
if [[ "$i" = *windows* ]]; then
7z a "../artifacts/$(basename "$i").zip" "$i"
else
tar czf "../artifacts/$(basename "$i").tar.gz" "$i"
fi
done
ls -lR ../artifacts
- name: Create Release
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
console.log('environment', process.versions);
const fs = require('fs').promises;
const { repo: { owner, repo }, sha } = context;
console.log({ owner, repo, sha });
const tag_name = process.env.GITHUB_REF.split("/")[2];
const release = await github.rest.repos.createRelease({
owner, repo,
tag_name,
draft: false,
target_commitish: sha
});
console.log('created release', { release });
for (let file of await fs.readdir('artifacts')) {
console.log('uploading', file);
await github.rest.repos.uploadReleaseAsset({
owner, repo,
release_id: release.data.id,
name: file,
data: await fs.readFile(`artifacts/${file}`)
});
}