Skip to content

Commit

Permalink
Update workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
Belonit committed Mar 9, 2024
1 parent ffa0f9f commit 0bb085a
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 61 deletions.
58 changes: 33 additions & 25 deletions .github/actions/build/action.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,45 @@
name: 'Build'
name: "Build"

inputs:
sln-path:
description: 'Path to the solution file relative to the root of the project'
description: "Path to the solution file relative to the root of the project"
required: false
default: '.'
default: "."
build-config:
description: 'Configuration to build'
description: "Configuration to build"
required: true
artifact-name:
description: "Artifact file name"
required: false
default: compiled-dll-${{ github.sha }}

runs:
using: "composite"
steps:
- name: Add MSBuild to PATH
uses: microsoft/setup-msbuild@v1
- name: Add MSBuild to PATH
uses: microsoft/setup-msbuild@v1

- name: Restore NuGet packages
working-directory: ${{env.GITHUB_WORKSPACE}}
run: nuget restore ${{inputs.sln-path}}
shell: cmd
- name: Restore NuGet packages
working-directory: ${{ env.GITHUB_WORKSPACE }}
run: nuget restore ${{ inputs.sln-path }}
shell: cmd

- uses: ammaraskar/msvc-problem-matcher@master
- uses: ammaraskar/msvc-problem-matcher@master

- name: Build
working-directory: ${{env.GITHUB_WORKSPACE}}
# Add additional options to the MSBuild command line here (like platform or verbosity level).
# See https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference
run: msbuild /m /p:Configuration=${{inputs.build-config}} /p:GitCommit=${{github.sha}} /p:GitBranch=${{github.ref}} ${{inputs.sln-path}}
shell: cmd
- name: Build
working-directory: ${{ env.GITHUB_WORKSPACE }}
# Add additional options to the MSBuild command line here (like platform or verbosity level).
# See https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference
run: msbuild /m /p:Configuration=${{inputs.build-config}} /p:GitCommit=${{github.sha}} /p:GitBranch=${{github.ref}} ${{inputs.sln-path}}
shell: cmd

- name: Upload Artifact
if: ${{success()}}
uses: actions/upload-artifact@v2
with:
name: compiled-dll-${{github.sha}}
path: |
${{inputs.sln-path}}/${{inputs.build-config}}/cncnet5.dll
${{inputs.sln-path}}/${{inputs.build-config}}/cncnet5.pdb
- name: Upload Artifact
if: ${{ success() }}
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.artifact-name }}
path: |
${{inputs.sln-path}}/${{inputs.build-config}}/cncnet5.dll
${{inputs.sln-path}}/${{inputs.build-config}}/cncnet5.pdb
./LICENSE.md
./README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: EditorConfig
name: "Editor Config Checker"

on:
pull_request:
Expand All @@ -12,6 +12,6 @@ jobs:
lint:
runs-on: windows-2019
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: editorconfig-checker
run: scripts/editorconfig-checker.bat
26 changes: 26 additions & 0 deletions .github/workflows/nightly-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: "Nightly Build"

on:
push:
branches:
- main
- develop

env:
SOLUTION_PATH: .
BUILD_CONFIGURATION: DevBuild

jobs:
build:
runs-on: windows-2019

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Build
uses: ./.github/actions/build
with:
sln-path: ${{ env.SOLUTION_PATH }}
build-config: ${{ env.BUILD_CONFIGURATION }}
34 changes: 0 additions & 34 deletions .github/workflows/nightly.yml

This file was deleted.

23 changes: 23 additions & 0 deletions .github/workflows/pr-nightly-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: "Pull Request Nightly Build"

on:
pull_request:

env:
SOLUTION_PATH: .
BUILD_CONFIGURATION: DevBuild

jobs:
build:
runs-on: windows-2019

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Build
uses: ./.github/actions/build
with:
sln-path: ${{ env.SOLUTION_PATH }}
build-config: ${{ env.BUILD_CONFIGURATION }}
68 changes: 68 additions & 0 deletions .github/workflows/pr-nightly-comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: "Nightly Build Comment on Pull Request"
on:
workflow_run:
workflows: ['Pull Request Nightly Build']
types: [completed]
jobs:
pr_comment:
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
steps:
- name: Get the PR number
run: |
# Query the issue search API to get the PR associated with it
PR_RAW=$(curl 'https://api.github.com/search/issues?q=${{ github.event.workflow_run.head_commit.id }}')
# Get the event number from the search results, which will
# be the PR number
# 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)
# Assume the 0th index in the array of found PRs is the correct one (it seems to usually be the latest one)
PR_NUM=$(echo $PR_RAW | jq '.items | map(select(.repository_url=="https://api.github.com/repos/${{ github.repository }}")) | .[0].number')
echo "PR_NUM=${PR_NUM}" >> ${GITHUB_ENV}
- name: Comment on PR
uses: actions/github-script@v7
with:
# This snippet is public-domain, taken from
# https://github.com/oprypin/nightly.link/blob/master/.github/workflows/pr-comment.yml
# and modified to allow comments on external PRs
script: |
async function upsertComment(owner, repo, issue_number, purpose, body) {
const {data: comments} = await github.rest.issues.listComments(
{owner, repo, issue_number});
const marker = `<!-- bot: ${purpose} -->`;
body = marker + "\n" + body;
const existing = comments.filter((c) => c.body.includes(marker));
if (existing.length > 0) {
const last = existing[existing.length - 1];
core.info(`Updating comment ${last.id}`);
await github.rest.issues.updateComment({
owner, repo,
body,
comment_id: last.id,
});
} else {
core.info(`Creating a comment in issue / PR #${issue_number}`);
await github.rest.issues.createComment({issue_number, body, owner, repo});
}
}
const {owner, repo} = context.repo;
const run_id = ${{github.event.workflow_run.id}};
const artifacts = await github.paginate(
github.rest.actions.listWorkflowRunArtifacts, {owner, repo, run_id});
if (!artifacts.length) {
return core.error(`No artifacts found`);
}
let body = `Nightly build for this pull request:\n`;
for (const art of artifacts) {
body += `\n* [${art.name}.zip](https://nightly.link/${owner}/${repo}/actions/artifacts/${art.id}.zip)`;
}
body += `\nThese artifacts will expire in 90 days and will not be available for download after that time.`;
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._`;
core.info("Review thread message body:", body);
await upsertComment(owner, repo, ${{ env.PR_NUM }}, "nightly-link", body);
62 changes: 62 additions & 0 deletions .github/workflows/release-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: "Release Build"

on:
push:
tags:
- "v*.*.*.*"

env:
RELEASE_NAME: ${{ github.ref_name }}
ARTIFACT_NAME: cncnet5_${{ github.ref_name }}.zip

SOLUTION_PATH: .
BUILD_CONFIGURATION: Release

jobs:
build:
runs-on: windows-2019

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Build
uses: ./.github/actions/build
with:
sln-path: ${{ env.SOLUTION_PATH }}
build-config: ${{ env.BUILD_CONFIGURATION }}

- name: Create Archive For Release
run: |
mkdir ./artifact
copy ./LICENSE.md ./artifact/LICENSE.md
copy ./README.md ./artifact/README.md
copy ./${{ env.BUILD_CONFIGURATION }}/cncnet5.pdb ./artifact/cncnet5.pdb
copy ./${{ env.BUILD_CONFIGURATION }}/cncnet5.dll ./artifact/cncnet5.dll
7z a ${{ env.ARTIFACT_NAME }} ./artifact/*
- name: Upload New Release
uses: softprops/action-gh-release@v2
with:
name: ${{ env.RELEASE_NAME }}
tag_name: ${{ env.RELEASE_NAME }}
body: ${{ env.RELEASE_NAME }}
append_body: true
draft: true
files: |
${{ env.ARTIFACT_NAME }}
request-anti-cheat-build:
needs: [build]
runs-on: ubuntu-latest
steps:
- name: Request AntiCheat Build
run: |
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.ACCESS_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/cncnet/yrpp-spawner-private/actions/workflows/release-build-by-request.yml/dispatches \
-d '{"ref":"main", "inputs":{"tag": "${{ github.ref_name }}"}}'

0 comments on commit 0bb085a

Please sign in to comment.