Skip to content

Commit 5490f70

Browse files
committed
refactor: build workflows
1 parent def4fd1 commit 5490f70

File tree

3 files changed

+69
-166
lines changed

3 files changed

+69
-166
lines changed

.github/workflows/build.yml

Lines changed: 26 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ jobs:
2222
id: create_release
2323
if: '${{ github.event.inputs.do_release == ''yes'' }}'
2424
with:
25+
allowUpdates: true
2526
tag: '${{ github.event.inputs.release }}'
2627
name: '${{ github.event.inputs.release }}'
2728
draft: false
@@ -31,6 +32,8 @@ jobs:
3132
compile:
3233
needs: prepare
3334
runs-on: ubuntu-latest
35+
permissions:
36+
contents: write
3437
continue-on-error: true
3538
strategy:
3639
matrix:
@@ -85,142 +88,51 @@ jobs:
8588
- x86_64-linux-muslx32
8689
repo:
8790
- richfelker/musl-cross-make
88-
- pmmp/musl-cross-make
91+
- nginxui/pmmp-musl-cross-make
8992
env:
90-
TARGET: '${{ matrix.target }}'
91-
REPO: '${{ matrix.repo }}'
93+
TARGET: ${{ matrix.target }}
94+
REPO: ${{ matrix.repo == 'nginxui/pmmp-musl-cross-make' && 'pmmp/musl-cross-make' || matrix.repo }}
9295
steps:
93-
- uses: actions/checkout@v3
96+
- name: Checkout
97+
uses: actions/checkout@v3
98+
9499
- name: 'Clone ${{ matrix.repo }}'
95100
run: 'git clone https://github.com/${{ matrix.repo }} mcm'
101+
96102
- name: 'Build ${{ matrix.target }}'
97103
run: |-
98104
make -j4
99105
make install
100106
ls output
101107
working-directory: mcm
108+
102109
- name: 'Package ${{ matrix.target }}'
103110
id: package
104111
run: |-
105112
tar -czvf ../output-${{ matrix.target }}.tar.gz output/
106113
echo "source_escaped=${REPO%%/*}_${REPO##*/}" >> $GITHUB_OUTPUT
107114
working-directory: mcm
108-
- id: upload-artifacts-0
109-
name: Upload artifacts 0
115+
116+
- id: upload-artifacts
117+
name: Upload artifacts
110118
if: '${{ success() }}'
111-
continue-on-error: false
112-
uses: actions/upload-artifact@v3
119+
uses: cytopia/[email protected]
113120
with:
114121
path: 'output-${{ matrix.target }}.tar.gz'
115122
name: '${{ matrix.target }}-${{ steps.package.outputs.source_escaped }}'
116-
- id: upload-releases-0
117-
name: Upload to releases 0
118-
uses: actions/upload-release-asset@v1
123+
124+
- name: Rename artifact
125+
run: mv output-${{ matrix.target }}.tar.gz output-${{ matrix.target }}-${{ steps.package.outputs.source_escaped }}.tar.gz
126+
127+
- id: upload-releases
128+
name: Upload to releases
129+
uses: ncipollo/release-action@v1
119130
if: '${{ github.event.inputs.do_release == ''yes'' }}'
120-
continue-on-error: false
121-
with:
122-
asset_path: 'output-${{ matrix.target }}.tar.gz'
123-
asset_name: >-
124-
output-${{ matrix.target }}-${{ steps.package.outputs.source_escaped
125-
}}.tar.gz
126-
upload_url: '${{ needs.prepare.outputs.upload_url }}'
127-
asset_content_type: application/gzip
128-
env:
129-
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
130-
- id: upload-artifacts-1
131-
name: Upload artifacts 1
132-
if: '${{ steps.upload-artifacts-0.outcome == ''failure'' }}'
133-
continue-on-error: false
134-
uses: actions/upload-artifact@v3
135-
with:
136-
path: 'output-${{ matrix.target }}.tar.gz'
137-
name: '${{ matrix.target }}-${{ steps.package.outputs.source_escaped }}'
138-
- id: upload-releases-1
139-
name: Upload to releases 1
140-
uses: actions/upload-release-asset@v1
141-
if: >-
142-
${{ github.event.inputs.do_release == 'yes' &&
143-
steps.upload-releases-0.outcome == 'failure' }}
144-
continue-on-error: false
145-
with:
146-
asset_path: 'output-${{ matrix.target }}.tar.gz'
147-
asset_name: >-
148-
output-${{ matrix.target }}-${{ steps.package.outputs.source_escaped
149-
}}.tar.gz
150-
upload_url: '${{ needs.prepare.outputs.upload_url }}'
151-
asset_content_type: application/gzip
152-
env:
153-
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
154-
- id: upload-artifacts-2
155-
name: Upload artifacts 2
156-
if: '${{ steps.upload-artifacts-1.outcome == ''failure'' }}'
157-
continue-on-error: false
158-
uses: actions/upload-artifact@v3
159131
with:
160-
path: 'output-${{ matrix.target }}.tar.gz'
161-
name: '${{ matrix.target }}-${{ steps.package.outputs.source_escaped }}'
162-
- id: upload-releases-2
163-
name: Upload to releases 2
164-
uses: actions/upload-release-asset@v1
165-
if: >-
166-
${{ github.event.inputs.do_release == 'yes' &&
167-
steps.upload-releases-1.outcome == 'failure' }}
168-
continue-on-error: false
169-
with:
170-
asset_path: 'output-${{ matrix.target }}.tar.gz'
171-
asset_name: >-
172-
output-${{ matrix.target }}-${{ steps.package.outputs.source_escaped
173-
}}.tar.gz
174-
upload_url: '${{ needs.prepare.outputs.upload_url }}'
175-
asset_content_type: application/gzip
176-
env:
177-
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
178-
- id: upload-artifacts-3
179-
name: Upload artifacts 3
180-
if: '${{ steps.upload-artifacts-2.outcome == ''failure'' }}'
181-
continue-on-error: false
182-
uses: actions/upload-artifact@v3
183-
with:
184-
path: 'output-${{ matrix.target }}.tar.gz'
185-
name: '${{ matrix.target }}-${{ steps.package.outputs.source_escaped }}'
186-
- id: upload-releases-3
187-
name: Upload to releases 3
188-
uses: actions/upload-release-asset@v1
189-
if: >-
190-
${{ github.event.inputs.do_release == 'yes' &&
191-
steps.upload-releases-2.outcome == 'failure' }}
192-
continue-on-error: false
193-
with:
194-
asset_path: 'output-${{ matrix.target }}.tar.gz'
195-
asset_name: >-
196-
output-${{ matrix.target }}-${{ steps.package.outputs.source_escaped
197-
}}.tar.gz
198-
upload_url: '${{ needs.prepare.outputs.upload_url }}'
199-
asset_content_type: application/gzip
200-
env:
201-
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
202-
- id: upload-artifacts-4
203-
name: Upload artifacts 4
204-
if: '${{ steps.upload-artifacts-3.outcome == ''failure'' }}'
205-
continue-on-error: true
206-
uses: actions/upload-artifact@v3
207-
with:
208-
path: 'output-${{ matrix.target }}.tar.gz'
209-
name: '${{ matrix.target }}-${{ steps.package.outputs.source_escaped }}'
210-
- id: upload-releases-4
211-
name: Upload to releases 4
212-
uses: actions/upload-release-asset@v1
213-
if: >-
214-
${{ github.event.inputs.do_release == 'yes' &&
215-
steps.upload-releases-3.outcome == 'failure' }}
216-
continue-on-error: true
217-
with:
218-
asset_path: 'output-${{ matrix.target }}.tar.gz'
219-
asset_name: >-
220-
output-${{ matrix.target }}-${{ steps.package.outputs.source_escaped
221-
}}.tar.gz
222-
upload_url: '${{ needs.prepare.outputs.upload_url }}'
223-
asset_content_type: application/gzip
132+
allowUpdates: true
133+
tag: '${{ github.event.inputs.release }}'
134+
artifacts: 'output-${{ matrix.target }}*.tar.gz'
135+
artifactContentType: application/gzip
224136
env:
225137
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
226138

builder/build.js

Lines changed: 37 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const targets = fs
88
.trim()
99
.split(/[\r\n]+/);
1010
//console.log(targets);
11-
const repositories = ["richfelker/musl-cross-make", "pmmp/musl-cross-make"];
11+
const repositories = ["richfelker/musl-cross-make", "nginxui/pmmp-musl-cross-make"];
1212

1313
const data = {
1414
name: "Build cross compilers",
@@ -32,6 +32,9 @@ const data = {
3232
jobs: {
3333
prepare: {
3434
"runs-on": "ubuntu-latest",
35+
permissions: {
36+
contents: "write",
37+
},
3538
outputs: {
3639
upload_url: "${{ steps.create_release.outputs.upload_url }}",
3740
},
@@ -55,6 +58,9 @@ const data = {
5558
},
5659
compile: {
5760
needs: "prepare",
61+
permissions: {
62+
contents: "write",
63+
},
5864
"runs-on": "ubuntu-latest",
5965
"continue-on-error": true,
6066
strategy: {
@@ -65,7 +71,7 @@ const data = {
6571
},
6672
env: {
6773
TARGET: "${{ matrix.target }}",
68-
REPO: "${{ matrix.repo }}",
74+
REPO: "${{ matrix.repo == 'nginxui/pmmp-musl-cross-make' && 'pmmp/musl-cross-make' || matrix.repo }}",
6975
},
7076
steps: [
7177
{ uses: "actions/checkout@v2" },
@@ -86,53 +92,38 @@ const data = {
8692
),
8793
"working-directory": "mcm",
8894
},
95+
{
96+
id: "upload-artifacts",
97+
name: "Upload artifacts",
98+
if: "\${{ success() }}",
99+
uses: "cytopia/[email protected]",
100+
with: {
101+
path: "output-${{ matrix.target }}.tar.gz",
102+
name: "${{ matrix.target }}-${{ steps.package.outputs.source_escaped }}",
103+
},
104+
},
105+
{
106+
name: "Rename artifact",
107+
run: "mv output-${{ matrix.target }}.tar.gz output-${{ matrix.target }}-${{ steps.package.outputs.source_escaped }}.tar.gz"
108+
},
109+
{
110+
id: "upload-releases",
111+
name: "Upload to releases",
112+
uses: "ncipollo/release-action@v1",
113+
if: "\${{ github.event.inputs.do_release == 'yes' }}",
114+
with: {
115+
allowUpdates: true,
116+
tag: "${{ github.event.inputs.release }}",
117+
artifacts: "output-${{ matrix.target }}*.tar.gz",
118+
artifactContentType: "application/gzip",
119+
},
120+
env: {
121+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}",
122+
},
123+
},
89124
],
90125
},
91126
},
92127
};
93128

94-
const retries = 5;
95-
for (let i = 0; i < retries; i++) {
96-
let artifactsIf, releasesIf, continueOnError;
97-
if (i == 0) {
98-
artifactsIf = `\${{ success() }}`;
99-
releasesIf = `\${{ github.event.inputs.do_release == 'yes' }}`;
100-
} else {
101-
artifactsIf = `\${{ steps.upload-artifacts-${i - 1}.outcome == 'failure' }}`;
102-
releasesIf = `\${{ github.event.inputs.do_release == 'yes' && steps.upload-releases-${i - 1}.outcome == 'failure' }}`;
103-
}
104-
continueOnError = i == retries - 1;
105-
const uploadSteps = [
106-
{
107-
id: `upload-artifacts-${i}`,
108-
name: `Upload artifacts ${i}`,
109-
if: artifactsIf,
110-
"continue-on-error": continueOnError,
111-
uses: "actions/upload-artifact@v2",
112-
with: {
113-
path: "output-${{ matrix.target }}.tar.gz",
114-
name: "${{ matrix.target }}-${{ steps.package.outputs.source_escaped }}",
115-
},
116-
},
117-
{
118-
id: `upload-releases-${i}`,
119-
name: `Upload to releases ${i}`,
120-
uses: "actions/upload-release-asset@v1",
121-
if: releasesIf,
122-
"continue-on-error": continueOnError,
123-
with: {
124-
asset_path: "output-${{ matrix.target }}.tar.gz",
125-
asset_name: "output-${{ matrix.target }}-${{ steps.package.outputs.source_escaped }}.tar.gz",
126-
upload_url: "${{ needs.prepare.outputs.upload_url }}",
127-
asset_content_type: "application/gzip",
128-
},
129-
env: {
130-
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}",
131-
},
132-
},
133-
];
134-
135-
data.jobs.compile.steps.push(...uploadSteps);
136-
}
137-
138129
console.log(yaml.dump(data));

index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,21 @@ const tags = {
2929
let ret = await exec.exec("sudo", ["apt", "update"], {
3030
ignoreReturnCode: true,
3131
});
32-
if (ret != 0) {
32+
if (ret !== 0) {
3333
console.error(`apt update failed with code ${ret}`);
3434
}
3535

3636
ret = await exec.exec("sudo", ["apt", "install", "--reinstall", "gcc", "g++", "cpp-11", "cpp-9"], {
3737
ignoreReturnCode: true,
3838
});
39-
if (ret != 0) {
39+
if (ret !== 0) {
4040
console.error(`apt install failed with code ${ret}`);
4141
}
4242

4343
ret = await exec.exec("git", ["clone", `https://github.com/${variant}.git`, destDir], {
4444
ignoreReturnCode: true,
4545
});
46-
if (ret != 0) {
46+
if (ret !== 0) {
4747
throw new Error(`git clone failed with code ${ret}`);
4848
}
4949

@@ -54,7 +54,7 @@ const tags = {
5454
TARGET: target,
5555
},
5656
});
57-
if (ret != 0) {
57+
if (ret !== 0) {
5858
throw new Error(`make -j4 failed with code ${ret}`);
5959
}
6060

@@ -65,7 +65,7 @@ const tags = {
6565
TARGET: target,
6666
},
6767
});
68-
if (ret != 0) {
68+
if (ret !== 0) {
6969
throw new Error(`make install failed with code ${ret}`);
7070
}
7171
cachedPath = destDir;
@@ -86,7 +86,7 @@ const tags = {
8686
core.setOutput("path", cachedPath);
8787
} catch (e) {
8888
if (build) {
89-
console.log("Build error occured and uploading build directory as artifacts");
89+
console.log("Build error occurred and uploading build directory as artifacts");
9090
await exec.exec("tar", ["-czf", "/opt/mcm.tar.gz", buildDir]);
9191
const artifact = require("@actions/artifact");
9292
const artifactClient = artifact.create();

0 commit comments

Comments
 (0)