Experiments #136
Workflow file for this run
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: Build | |
on: | |
push: | |
branches: | |
- master | |
- 'feature/**' | |
- 'bugfix/**' | |
- 'github/**' | |
workflow_dispatch: | |
jobs: | |
build: | |
name: Build | |
outputs: | |
# accessible from other jobs as ${{needs.experiments.outputs.version}} | |
version: ${{steps.version.outputs.version}} | |
versions_json: ${{steps.versions_json.outputs.versions_json}} | |
strategy: | |
matrix: | |
os: [windows-latest] | |
arch: [amd64, x86] | |
charset: [unicode] | |
include: | |
- os: windows-latest | |
arch: x86 | |
charset: ansi | |
runs-on: ${{matrix.os}} | |
defaults: | |
run: | |
shell: cmd | |
steps: | |
- name: Version | |
id: version | |
shell: python | |
run: | | |
import os | |
from datetime import datetime, timezone | |
date = datetime.now(tz=timezone.utc) | |
with open(os.getenv('GITHUB_OUTPUT'), "a") as fout: | |
print( f"version={date.year%100}.{date.month}.{date.day}.${{github.run_number}}") | |
fout.write(f"version={date.year%100}.{date.month}.{date.day}.${{github.run_number}}") | |
- name: Upgrade msys2/mingw32 | |
if: matrix.arch == 'x86' | |
uses: msys2/setup-msys2@v2 | |
with: | |
msystem: mingw32 | |
release: false | |
update: true | |
install: mingw-w64-i686-toolchain | |
- name: Upgrade msys2/mingw64 | |
if: matrix.arch == 'amd64' | |
uses: msys2/setup-msys2@v2 | |
with: | |
msystem: mingw64 | |
release: false | |
update: true | |
install: mingw-w64-x86_64-toolchain | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
submodules: 'true' | |
- name: Patch version | |
working-directory: src/nscurl | |
run: py -3 _set_version.py --version=${{steps.version.outputs.version}} | |
- name: Checkout vcpkg | |
uses: actions/checkout@v4 | |
with: | |
repository: 'Microsoft/vcpkg' | |
path: vcpkg/repository | |
# https://learn.microsoft.com/en-us/vcpkg/consume/binary-caching-github-actions-cache | |
# We'll use `x-gha,readwrite` as vcpkg binary cache provider, which requires ACTIONS_CACHE_URL and ACTIONS_RUNTIME_TOKEN envvars | |
# note: Github Actions cache entries are removed after 7d | |
- name: Export GitHub Actions cache environment variables | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || ''); | |
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || ''); | |
# ----------------------------------------------------------------------- | |
- name: Build | |
run: _build.bat mingw release ${{matrix.arch}} ${{matrix.charset}} | |
# ----------------------------------------------------------------------- | |
- name: Upload vcpkg error logs | |
if: ${{ failure() }} | |
uses: actions/upload-artifact@v4 | |
with: | |
name: "vcpkg_buildtrees_logs_${{matrix.os}}_${{matrix.arch}}_${{matrix.charset}}" | |
path: vcpkg/repository/buildtrees/**/*.log | |
compression-level: 9 # best | |
- name: Output versions.json | |
id: versions_json | |
shell: python | |
run: | | |
import os, json | |
with open('Release-mingw-${{matrix.arch}}-${{matrix.charset}}/versions.json') as fin: | |
with open(os.getenv('GITHUB_OUTPUT'), "a") as fout: | |
data = json.dumps(json.loads(fin.read())) # reformat as one liner | |
print( f"versions_json={data}") | |
fout.write(f"versions_json={data}") | |
- name: Upload plugin binaries | |
uses: actions/upload-artifact@v4 | |
with: | |
name: package-${{matrix.arch}}-${{matrix.charset}} | |
path: packages/Release-mingw-${{matrix.arch}}-${{matrix.charset}}/* | |
- name: Upload curl | |
if: matrix.charset == 'unicode' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: curl-${{matrix.arch}} | |
path: packages/Release-mingw-${{matrix.arch}}-${{matrix.charset}}-curl/* | |
package: | |
name: Final Package | |
needs: build | |
runs-on: windows-latest | |
defaults: | |
run: | |
shell: cmd | |
steps: | |
- name: Download artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
path: artifacts | |
pattern: package-* | |
merge-multiple: true | |
- name: Upload final package | |
uses: actions/upload-artifact@v4 | |
with: | |
name: NScurl | |
path: artifacts/* | |
# Download an NSIS fork with amd64 support | |
- name: Install NSIS-negrutiu | |
shell: python | |
run: | | |
from urllib import request | |
import json, re, subprocess | |
with request.urlopen('https://api.github.com/repos/negrutiu/nsis/releases/latest') as http: | |
for asset in json.loads(http.read())['assets']: | |
if (re.match(r'nsis-.*-x86.exe', asset['name'])): | |
print('download ' + asset['browser_download_url'] + ' ...') | |
with request.urlopen(asset['browser_download_url']) as http: | |
with open(asset['name'], 'wb') as fout: | |
fout.write(http.read()) | |
print('install ' + asset['name'] + ' ...') | |
subprocess.Popen([asset['name'], '/S']).wait() | |
exit() | |
- name: Build NSIS example (x86-unicode) | |
run: makensis.exe /V4 /DPLUGIN_DIR=..\..\Plugins\x86-unicode artifacts\Examples\NScurl\NScurl-Test.nsi | |
- name: Build NSIS example (x86-ansi) | |
run: makensis.exe /V4 /DPLUGIN_DIR=..\..\Plugins\x86-ansi /DANSI artifacts\Examples\NScurl\NScurl-Test.nsi | |
- name: Build NSIS example (amd64-unicode) | |
run: makensis.exe /V4 /DPLUGIN_DIR=..\..\Plugins\amd64-unicode /DAMD64 artifacts\Examples\NScurl\NScurl-Test.nsi | |
- name: Upload NSIS examples | |
uses: actions/upload-artifact@v4 | |
with: | |
name: NScurl-Examples | |
path: artifacts/Examples/NScurl/NScurl-Test-*.exe | |
release: | |
name: Release Draft | |
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/github/') | |
needs: [build, package] | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
# note: we're using dawidd6/action-download-artifact@v5 because of `skip_unpack` | |
- name: Download artifacts | |
uses: dawidd6/action-download-artifact@v5 | |
with: | |
path: artifacts | |
name: ^NScurl$|^NScurl-Examples$ | |
name_is_regexp: true | |
run_id: ${{github.run_id}} | |
skip_unpack: true | |
- name: Prepare release notes | |
shell: python | |
run: | | |
lines = [] | |
with open(".github/workflows/release-body.md") as fin: | |
line = fin.read() | |
line = line.replace('{version-cacert}', '${{fromJson(needs.build.outputs.versions_json).cacert}}') | |
line = line.replace('{version-engines}', '${{fromJson(needs.build.outputs.versions_json).curl_md}}') | |
line = line.replace('{version-gcc}', '${{fromJson(needs.build.outputs.versions_json).gcc}}') | |
line = line.replace('{url-workflow}', 'https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}') | |
lines.append(line) | |
with open(".github/workflows/release-body.md", "w") as fout: | |
for line in lines: | |
fout.write(line) | |
- name: Create GitHub release draft | |
uses: ncipollo/release-action@v1 | |
with: | |
# note: `tag` is the release key | |
tag: release-candidate | |
name: v${{needs.build.outputs.version}} | |
artifacts: artifacts/* | |
bodyFile: .github/workflows/release-body.md | |
draft: true | |
makeLatest: true | |
allowUpdates: true | |
updateOnlyUnreleased: true | |
artifactErrorsFailBuild: true | |
removeArtifacts: true |