Skip to content

Commit 10a1fd3

Browse files
committed
Add GitHub CI
1 parent 54be1c3 commit 10a1fd3

4 files changed

Lines changed: 177 additions & 0 deletions

File tree

.github/actions/build/action.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: "Build"
2+
3+
inputs:
4+
sln-path:
5+
description: "Path to the solution file relative to the repo root"
6+
required: false
7+
default: "Syringe.sln"
8+
build-config:
9+
description: "Configuration to build (Debug or Release)"
10+
required: true
11+
run-tests:
12+
description: "Run tests\\bin\\Tests.exe after building and fail on non-zero exit"
13+
required: false
14+
default: "false"
15+
artifact-name:
16+
description: "Artifact file name (empty = no upload)"
17+
required: false
18+
default: ''
19+
20+
runs:
21+
using: "composite"
22+
steps:
23+
- name: Add MSBuild to PATH
24+
uses: microsoft/setup-msbuild@v2
25+
with:
26+
vs-version: '[17.0,)' # v143 / VS 2022+
27+
28+
- uses: ammaraskar/msvc-problem-matcher@master
29+
30+
- name: Build
31+
working-directory: ${{ github.workspace }}
32+
# The Any CPU solution platform has no Build.0 entries, so Platform=Win32 must be explicit.
33+
run: msbuild /m /p:Configuration=${{ inputs.build-config }} /p:Platform=Win32 /v:q ${{ inputs.sln-path }}
34+
shell: cmd
35+
36+
- name: Run tests
37+
if: ${{ inputs.run-tests == 'true' }}
38+
working-directory: ${{ github.workspace }}
39+
run: tests\bin\Tests.exe
40+
shell: cmd
41+
42+
- name: Upload artifact
43+
if: ${{ success() && inputs.artifact-name != '' }}
44+
uses: actions/upload-artifact@v4
45+
with:
46+
name: ${{ inputs.artifact-name }}
47+
path: |
48+
LICENSE
49+
${{ inputs.build-config }}/Syringe.exe
50+
${{ inputs.build-config }}/Syringe.pdb
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: "Nightly Build"
2+
3+
on:
4+
push:
5+
branches: [master, main, develop]
6+
pull_request:
7+
8+
jobs:
9+
build:
10+
runs-on: windows-2022
11+
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
configuration: [Debug, Release]
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Build
21+
uses: ./.github/actions/build
22+
with:
23+
build-config: ${{ matrix.configuration }}
24+
run-tests: ${{ matrix.configuration == 'Release' }}
25+
artifact-name: Syringe-${{ matrix.configuration }}-${{ github.sha }}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: "Nightly Build Comment on Pull Request"
2+
on:
3+
workflow_run:
4+
workflows: ['Nightly Build']
5+
types: [completed]
6+
jobs:
7+
pr_comment:
8+
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Get the PR number
12+
run: |
13+
# Query the issue search API to get the PR associated with it
14+
PR_RAW=$(curl 'https://api.github.com/search/issues?q=${{ github.event.workflow_run.head_commit.id }}')
15+
# Get the event number from the search results, which will
16+
# be the PR number
17+
# Filter by PRs only in this repository, as a PR with an identical head commit may be made in another repository (e.g. a fork)
18+
# Assume the 0th index in the array of found PRs is the correct one (it seems to usually be the latest one)
19+
PR_NUM=$(echo $PR_RAW | jq '.items | map(select(.repository_url=="https://api.github.com/repos/${{ github.repository }}")) | .[0].number')
20+
echo "PR_NUM=${PR_NUM}" >> ${GITHUB_ENV}
21+
22+
- name: Comment on PR
23+
uses: actions/github-script@v7
24+
with:
25+
# This snippet is public-domain, taken from
26+
# https://github.com/oprypin/nightly.link/blob/master/.github/workflows/pr-comment.yml
27+
# and modified to allow comments on external PRs
28+
script: |
29+
async function upsertComment(owner, repo, issue_number, purpose, body) {
30+
const {data: comments} = await github.rest.issues.listComments(
31+
{owner, repo, issue_number});
32+
33+
const marker = `<!-- bot: ${purpose} -->`;
34+
body = marker + "\n" + body;
35+
36+
const existing = comments.filter((c) => c.body.includes(marker));
37+
if (existing.length > 0) {
38+
const last = existing[existing.length - 1];
39+
core.info(`Updating comment ${last.id}`);
40+
await github.rest.issues.updateComment({
41+
owner, repo,
42+
body,
43+
comment_id: last.id,
44+
});
45+
} else {
46+
core.info(`Creating a comment in issue / PR #${issue_number}`);
47+
await github.rest.issues.createComment({issue_number, body, owner, repo});
48+
}
49+
}
50+
51+
const {owner, repo} = context.repo;
52+
const run_id = ${{github.event.workflow_run.id}};
53+
54+
const artifacts = await github.paginate(
55+
github.rest.actions.listWorkflowRunArtifacts, {owner, repo, run_id});
56+
if (!artifacts.length) {
57+
return core.error(`No artifacts found`);
58+
}
59+
let body = `Nightly build for this pull request:\n`;
60+
for (const art of artifacts) {
61+
body += `\n* [${art.name}.zip](https://nightly.link/${owner}/${repo}/actions/artifacts/${art.id}.zip)`;
62+
}
63+
64+
body += `\nThese artifacts will expire in 90 days and will not be available for download after that time.`;
65+
body += `\n\n_This comment is automatic and is meant to allow guests to get latest nightly builds for this pull request without registering. It is updated on every successful build._`;
66+
67+
core.info("Review thread message body:", body);
68+
await upsertComment(owner, repo, ${{ env.PR_NUM }}, "nightly-link", body);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: "Release Build"
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
build:
9+
runs-on: windows-2022
10+
11+
env:
12+
ARCHIVE_NAME: Syringe-${{ github.ref_name }}.zip
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Build
18+
uses: ./.github/actions/build
19+
with:
20+
build-config: Release
21+
run-tests: 'true'
22+
23+
- name: Create an archive for the release
24+
run: >
25+
7z a ${{ env.ARCHIVE_NAME }}
26+
./LICENSE
27+
./Release/Syringe.exe
28+
./Release/Syringe.pdb
29+
30+
- name: Upload files to the release
31+
uses: softprops/action-gh-release@v2
32+
with:
33+
append_body: true
34+
files: ${{ env.ARCHIVE_NAME }}

0 commit comments

Comments
 (0)