Pull upstream / Make a nightly build on Win [cron + manual] #233
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Pull upstream / Make a nightly build on Win [cron + manual] | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '0 0 * * *' | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event.schedule || github.ref }} | |
cancel-in-progress: true | |
permissions: | |
contents: write | |
defaults: | |
run: | |
shell: cmd | |
jobs: | |
build: | |
name: Prepare and build on Windows Server VM (2019) | |
runs-on: windows-2019 | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Pull changes from original repo | |
run: | | |
git config --global user.name "BH_build_bot" | |
git config --global user.email "spectatorBH@outlook.com" | |
git pull https://github.com/pascalabcnet/pascalabcnet.git master | |
git push | |
- name: Install dependencies into Virtual Environment | |
run: _RegisterHelixNUnit.bat | |
- name: Build C# project in release-mode / compile Pas-units / run tests | |
run: _GenerateAllSetupsForGitHubActions.bat | |
timeout-minutes: 40 | |
env: | |
PABCNET_BUILD_MODE: Release | |
PABCNET_RUN_TESTS: false | |
PABCNET_INC_BUILD: false | |
PABCNET_VERBOSE: false | |
- name: Prepare GitHub extra scripting packages | |
run: npm install @actions/exec | |
- name: Create GitHub pre-Release | |
uses: actions/github-script@main | |
with: | |
script: | | |
const tag = "nightly-build-synced"; // Git tag name (preferably different from branch name) | |
const release_name = "Nightly build (upstream synced)"; // GitHub release display name | |
const mark_pre_release = true; | |
console.log('environment', process.versions); | |
sha = ''; | |
await require('@actions/exec').exec('git', ['rev-parse', 'HEAD'], { | |
listeners: { | |
stdout: data => { | |
sha += data.toString().trim(); | |
}, | |
stderr: data => { | |
sha += data.toString().trim(); | |
} | |
} | |
}); | |
const { repo: { owner, repo } } = context; | |
console.log({ owner, repo, sha }); | |
// Check if the release already exists | |
const existingReleases = await github.rest.repos.listReleases({ owner, repo }); | |
for (const existingRelease of existingReleases.data) { | |
if (existingRelease.tag_name === tag) { | |
console.log('deleting old release', { existingRelease }); | |
await github.rest.repos.deleteRelease({ | |
owner, | |
repo, | |
release_id: existingRelease.id, | |
}); | |
break; | |
} | |
} | |
try { | |
await github.rest.git.deleteRef({ | |
owner: owner, | |
repo: repo, | |
ref: `tags/${tag}` | |
}); | |
console.log('Tag deleted successfully'); | |
} catch (error) { | |
console.error(`Error deleting tag: ${error}`); | |
} | |
const release = await github.rest.repos.createRelease({ | |
owner, repo, | |
tag_name: tag, | |
name: release_name, | |
draft: true, | |
prerelease: mark_pre_release, | |
target_commitish: sha | |
}); | |
console.log('created release', { release }); | |
const fs = require('fs').promises; | |
for (let file of await fs.readdir('Release')) { | |
console.log('uploading', file); | |
if (file.startsWith('.')) continue; | |
try { | |
await github.rest.repos.uploadReleaseAsset({ | |
owner, repo, | |
release_id: release.data.id, | |
name: file, | |
data: await fs.readFile(`./Release/${file}`) | |
}); | |
} catch (error) { | |
console.error(`Error uploading: ${error}`); | |
} | |
} | |
if (release.data.draft) { | |
console.log('finalizing draft release'); | |
await github.rest.repos.updateRelease({ | |
owner, | |
repo, | |
release_id: release.data.id, | |
draft: false, | |
}); | |
} |