Skip to content

Commit

Permalink
Improved GitHub workflows (#27)
Browse files Browse the repository at this point in the history
* GH-21: Release improvements
* GH-21: Generate `versions.json` and do the proper replacements in release notes
* GH-21: Dynamically download the latest NSIS-negrutiu
  • Loading branch information
negrutiu authored Jun 9, 2024
1 parent 4126d79 commit f347c0a
Show file tree
Hide file tree
Showing 6 changed files with 195 additions and 175 deletions.
106 changes: 50 additions & 56 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
- master
- 'feature/**'
- 'bugfix/**'
- 'github/**'

workflow_dispatch:

jobs:
Expand All @@ -13,6 +15,7 @@ jobs:
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:
Expand Down Expand Up @@ -60,27 +63,6 @@ jobs:
update: true
install: mingw-w64-x86_64-toolchain

- name: Print environment
if: failure()
run: |
echo ----------------------------------------------------
set
echo ----------------------------------------------------
dir /OG %SystemDrive%\
echo ----------------------------------------------------
dir /s /b c:\msys64\*.exe
echo ----------------------------------------------------
echo -- 1 && %SystemDrive%\msys64\mingw32\bin\gcc.exe -v
echo -- 2 && %SystemDrive%\msys64\mingw64\bin\gcc.exe -v
echo -- 3 && %SystemDrive%\mingw32\bin\gcc.exe -v
echo -- 4 && %SystemDrive%\mingw64\bin\gcc.exe -v
echo -- 5 && gcc.exe -v
echo ====================================================
py -0p
echo ----------------------------------------------------
py -3 -V
py -3 -m pip list
- name: Checkout
uses: actions/checkout@v4
with:
Expand All @@ -102,13 +84,23 @@ jobs:
path: vcpkg/archives
key: ${{runner.os}}-${{matrix.arch}}-${{matrix.charset}}-${{hashFiles('vcpkg/overlay_*', 'vcpkg/clone/ports/curl', 'vcpkg/clone/ports/openssl', 'vcpkg/clone/ports/nghttp2', 'vcpkg/clone/ports/zlib', 'vcpkg/clone/ports/brotli', 'vcpkg/clone/ports/zstd')}}

# -----------------------------------------------------------------------
- name: Build
run: _build.bat mingw release ${{matrix.arch}} ${{matrix.charset}}
# -----------------------------------------------------------------------

- name: Print packages
run: dir /s /b /a-d packages

- name: Upload
- 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
uses: actions/upload-artifact@v4
with:
name: package-${{matrix.arch}}-${{matrix.charset}}
Expand All @@ -119,12 +111,16 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: curl-${{matrix.arch}}
path: packages/Release-mingw-${{matrix.arch}}-curl/*
path: packages/Release-mingw-${{matrix.arch}}-${{matrix.charset}}-curl/*

package:
name: Package
name: Final Package
needs: build
runs-on: windows-latest
defaults:
run:
shell: cmd

steps:
- name: Download artifacts
uses: actions/download-artifact@v4
Expand All @@ -139,46 +135,41 @@ jobs:
name: NScurl
path: artifacts/*

# Install an NSIS fork with amd64 support
# note: NSIS-negrutiu sits in C:\Program Files\NSIS
# note: NSIS-official sits in C:\Program Files (x86)\NSIS
# Download an NSIS fork with amd64 support
- name: Install NSIS-negrutiu
shell: cmd
shell: python
run: |
setlocal enabledelayedexpansion
set version=3.10.7422.0
set arch=amd64
curl -L --fail -o nsis-%version%-negrutiu-%arch%.exe https://github.com/negrutiu/nsis/releases/download/v%version%/nsis-%version%-negrutiu-%arch%.exe || exit /b !errorlevel!
echo installing...
nsis-%version%-negrutiu-%arch%.exe /S
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)
shell: cmd
run: |
set PATH=%ProgramFiles%\NSIS;%PATH%
makensis.exe /V4 /DPLUGIN_DIR=..\..\Plugins\x86-unicode artifacts\Examples\NScurl\NScurl-Test.nsi
run: makensis.exe /V4 /DPLUGIN_DIR=..\..\Plugins\x86-unicode artifacts\Examples\NScurl\NScurl-Test.nsi

- name: Build NSIS example (x86-ansi)
shell: cmd
run: |
set PATH=%ProgramFiles%\NSIS;%PATH%
makensis.exe /V4 /DPLUGIN_DIR=..\..\Plugins\x86-ansi /DANSI artifacts\Examples\NScurl\NScurl-Test.nsi
run: makensis.exe /V4 /DPLUGIN_DIR=..\..\Plugins\x86-ansi /DANSI artifacts\Examples\NScurl\NScurl-Test.nsi

- name: Build NSIS example (amd64-unicode)
shell: cmd
run: |
set PATH=%ProgramFiles%\NSIS;%PATH%
makensis.exe /V4 /DPLUGIN_DIR=..\..\Plugins\amd64-unicode /DAMD64 artifacts\Examples\NScurl\NScurl-Test.nsi
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-Tests
name: NScurl-Examples
path: artifacts/Examples/NScurl/NScurl-Test-*.exe

release:
name: Release
if: github.ref == 'refs/heads/master'
name: Release Draft
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/github/')
needs: [build, package]
runs-on: ubuntu-latest
permissions:
Expand All @@ -193,7 +184,9 @@ jobs:
uses: dawidd6/action-download-artifact@v5
with:
path: artifacts
name: NScurl
name: ^NScurl$|^NScurl-Examples$
name_is_regexp: true
run_id: ${{github.run_id}}
skip_unpack: true

- name: Prepare release notes
Expand All @@ -202,8 +195,9 @@ jobs:
lines = []
with open(".github/workflows/release-body.md") as fin:
line = fin.read()
#line = line.replace('{version-libs}', 'libcurl/todo, OpenSSL/todo, zlib/todo, brotli/todo, zstd/todo, nghttp2/todo')
#line = line.replace('{version-gcc}', 'todo')
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:
Expand All @@ -223,4 +217,4 @@ jobs:
allowUpdates: true
updateOnlyUnreleased: true
artifactErrorsFailBuild: true
replacesArtifacts: true
removeArtifacts: true
24 changes: 23 additions & 1 deletion .github/workflows/experiments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ jobs:
run: |
echo ----------------------------------------------------
set
echo ----------------------------------------------------
where gcc.exe
gcc.exe -v
echo ====================================================
py -0p
echo ----------------------------------------------------
Expand Down Expand Up @@ -93,4 +96,23 @@ jobs:
allowUpdates: true
updateOnlyUnreleased: true
artifactErrorsFailBuild: true
replacesArtifacts: true
replacesArtifacts: true

jsons:
runs-on: ubuntu-latest
steps:
- name: Read versions.json
id: versions
shell: python
run: |
import os
with open('versions.json', 'w') as fout:
fout.write('{"value1":1, "value2":"2"}')
with open('versions.json') as fin:
with open(os.getenv('GITHUB_OUTPUT'), "a") as fout:
fout.write(f"versions_json={fin.read()}")
- name: Use versions.json
shell: python
run: |
print(f"-- value1 is \"${{fromJson(steps.versions.outputs.versions_json).value1}}\"")
print(f"-- value2 is \"${{fromJson(steps.versions.outputs.versions_json).value2}}\"")
2 changes: 1 addition & 1 deletion .github/workflows/release-body.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## Release Notes

* {version-libs}
* {version-engines}, `cacert/{version-cacert}`
* Built with mingw-w64 `gcc/{version-gcc}`
* GitHub workflow run: {url-workflow}
* Contains `amd64-unicode`, `x86-unicode`, `x86-ansi` binaries
Expand Down
55 changes: 24 additions & 31 deletions _build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -117,52 +117,45 @@ exit /b

:package
echo.
set outdir=packages\%configuration%-%compiler%-%platform_nsis%-%charset%
rmdir /s /q %outdir% 2> nul

call :copy README.md %outdir%\README.md
call :copy LICENSE.md %outdir%\LICENSE.md
call :copy vcpkg\clone\installed\%triplet%\share\brotli\copyright %outdir%\LICENSE.brotli.md
call :copy vcpkg\clone\installed\%triplet%\share\curl\copyright %outdir%\LICENSE.curl.md
call :copy vcpkg\clone\installed\%triplet%\share\nghttp2\copyright %outdir%\LICENSE.nghttp2.md
call :copy vcpkg\clone\installed\%triplet%\share\openssl\copyright %outdir%\LICENSE.openssl.md
call :copy vcpkg\clone\installed\%triplet%\share\zlib\copyright %outdir%\LICENSE.zlib.md
call :copy vcpkg\clone\installed\%triplet%\share\zstd\copyright %outdir%\LICENSE.zstd.md
set bindir=Release-%compiler%-%platform_nsis%-%charset%
set pkgdir=packages\%configuration%-%compiler%-%platform_nsis%-%charset%
set curldir=packages\%configuration%-%compiler%-%platform_nsis%-%charset%-curl
set vcpkginstdir=vcpkg\clone\installed\%triplet%

call :copy Release-%compiler%-%platform_nsis%-%charset%\NScurl.dll %outdir%\Plugins\%platform_nsis%-%charset%\
rmdir /s /q %pkgdir% 2> nul

call :copy tests\NScurl-Test.nsi %outdir%\Examples\NScurl\
call :copy tests\NScurl-Test-build.bat %outdir%\Examples\NScurl\
call :copy README.md %pkgdir%\README.md
call :copy LICENSE.md %pkgdir%\LICENSE.md
call :copy %vcpkginstdir%\share\brotli\copyright %pkgdir%\LICENSE.brotli.md
call :copy %vcpkginstdir%\share\curl\copyright %pkgdir%\LICENSE.curl.md
call :copy %vcpkginstdir%\share\nghttp2\copyright %pkgdir%\LICENSE.nghttp2.md
call :copy %vcpkginstdir%\share\openssl\copyright %pkgdir%\LICENSE.openssl.md
call :copy %vcpkginstdir%\share\zlib\copyright %pkgdir%\LICENSE.zlib.md
call :copy %vcpkginstdir%\share\zstd\copyright %pkgdir%\LICENSE.zstd.md

call :copy src\nscurl\NScurl.readme.md %outdir%\Docs\NScurl\
call :copy tests\NScurl-Test-build.bat %outdir%\Examples\NScurl\
call :copy %bindir%\NScurl.dll %pkgdir%\Plugins\%platform_nsis%-%charset%\

call :copy tests\NScurl-Test.nsi %pkgdir%\Examples\NScurl\
call :copy tests\NScurl-Test-build.bat %pkgdir%\Examples\NScurl\

call :copy src\nscurl\NScurl.readme.md %pkgdir%\Docs\NScurl\
call :copy tests\NScurl-Test-build.bat %pkgdir%\Examples\NScurl\
:end_package

:curl_package
if /i "%charset%" neq "unicode" goto :end_curl_package
echo.
set outdir=packages\%configuration%-%compiler%-%platform_nsis%-curl
call :copy vcpkg\clone\installed\%triplet%\tools\curl\curl.exe %outdir%\
call :copy src\nscurl\curl-ca-bundle.crt %outdir%\
call :copy %vcpkginstdir%\tools\curl\curl.exe %curldir%\
call :copy src\nscurl\curl-ca-bundle.crt %curldir%\
:end_curl_package

:versions
echo.
echo --------------------------------------------------------

echo.
echo NScurl
powershell -C "(Get-Item 'Release-%compiler%-%platform_nsis%-%charset%\NScurl.dll').VersionInfo.FileVersion"

echo.
echo curl.exe
vcpkg\clone\installed\%triplet%\tools\curl\curl.exe -V

echo.
echo curl-ca-bundle.crt
type src\nscurl\curl-ca-bundle.crt | findstr /C:"as of:"

if "%compiler%" equ "mingw" echo.&& gcc --version
py -3 _versions.py --indent=2 --curl=%curldir%\curl.exe --gcc=gcc.exe> "%bindir%\versions.json"
type %bindir%\versions.json
:end_versions

echo all done. errorlevel %errorlevel%
Expand Down
86 changes: 0 additions & 86 deletions _build_package.bat

This file was deleted.

Loading

0 comments on commit f347c0a

Please sign in to comment.