Skip to content

Commit

Permalink
Workflow experiments
Browse files Browse the repository at this point in the history
  • Loading branch information
negrutiu committed Jun 6, 2024
1 parent 235fe88 commit 9cf7569
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 16 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on:
jobs:
build:
name: Build
outputs:
# accessible from other jobs as ${{needs.experiments.outputs.version}}
version: ${{steps.version.outputs.VERSION}}

strategy:
matrix:
os: [windows-latest]
Expand All @@ -22,6 +26,16 @@ jobs:
shell: cmd

steps:
- id: version
name: 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:
fout.write(f"version={date.year}.{date.month}.{date.day}.${{github.run_number}}")
- name: Upgrade msys2/mingw32
if: matrix.arch == 'x86'
uses: msys2/setup-msys2@v2
Expand Down Expand Up @@ -72,6 +86,10 @@ jobs:
with:
submodules: 'true'

- name: Patch version
run: |
py -3 src/nscurl/_set_version.py --version=${{steps.version.outputs.version}}
- name: Build
run: |
_build.bat mingw release ${{matrix.arch}} ${{matrix.charset}}
Expand Down
7 changes: 2 additions & 5 deletions src/nscurl/Makefile.windows
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ RCFLAGS += \
$(CUSTOM_RCFLAGS)


.PHONY: clean all-before all all-after nsis-sdk curl-ca-bundle update-file-version vcpkg-install
.PHONY: clean all-before all all-after nsis-sdk curl-ca-bundle vcpkg-install

clean:
cmd /c if exist $(OUTDIR) rd /S /Q $(OUTDIR)

all: all-before nsis-sdk curl-ca-bundle update-file-version vcpkg-install $(_BIN) all-after
all: all-before nsis-sdk curl-ca-bundle vcpkg-install $(_BIN) all-after

all-before:
cmd /c if not exist $(OUTDIR) mkdir $(OUTDIR)
Expand All @@ -136,9 +136,6 @@ nsis-sdk:
curl-ca-bundle:
py -3 _get_curl-ca-bundle.py

update-file-version:
py -3 _update_resource_version.py

vcpkg-install:
cmd /c call ..\..\_install_vcpkg.bat $(_arch) mingw static

Expand Down
8 changes: 4 additions & 4 deletions src/nscurl/NScurl.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
<AdditionalDependencies>version.lib;libcurl-d.lib;libcrypto.lib;libssl.lib;nghttp2.lib;zlibd.lib;zstd.lib;brotlicommon.lib;brotlidec.lib;ws2_32.lib;Wldap32.lib;Crypt32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PreBuildEvent>
<Command>call py -3 _get_nsis_sdk.py &amp;&amp; py -3 _get_curl-ca-bundle.py &amp;&amp; call py -3 _update_resource_version.py &amp;&amp; call "$(SolutionDir)_install_vcpkg.bat" $(Platform) msbuild static
<Command>call py -3 _get_nsis_sdk.py &amp;&amp; py -3 _get_curl-ca-bundle.py &amp;&amp; call "$(SolutionDir)_install_vcpkg.bat" $(Platform) msbuild static
</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
Expand All @@ -105,7 +105,7 @@
<AdditionalDependencies>version.lib;libcurl-d.lib;libcrypto.lib;libssl.lib;nghttp2.lib;zlibd.lib;zstd.lib;brotlicommon.lib;brotlidec.lib;ws2_32.lib;Wldap32.lib;Crypt32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PreBuildEvent>
<Command>call py -3 _get_nsis_sdk.py &amp;&amp; py -3 _get_curl-ca-bundle.py &amp;&amp; call py -3 _update_resource_version.py &amp;&amp; call "$(SolutionDir)_install_vcpkg.bat" $(Platform) msbuild static
<Command>call py -3 _get_nsis_sdk.py &amp;&amp; py -3 _get_curl-ca-bundle.py &amp;&amp; call "$(SolutionDir)_install_vcpkg.bat" $(Platform) msbuild static
</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
Expand All @@ -125,7 +125,7 @@
<AdditionalDependencies>version.lib;libcurl.lib;libcrypto.lib;libssl.lib;nghttp2.lib;zlib.lib;zstd.lib;brotlicommon.lib;brotlidec.lib;ws2_32.lib;Wldap32.lib;Crypt32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PreBuildEvent>
<Command>call py -3 _get_nsis_sdk.py &amp;&amp; py -3 _get_curl-ca-bundle.py &amp;&amp; call py -3 _update_resource_version.py &amp;&amp; call "$(SolutionDir)_install_vcpkg.bat" $(Platform) msbuild static
<Command>call py -3 _get_nsis_sdk.py &amp;&amp; py -3 _get_curl-ca-bundle.py &amp;&amp; call "$(SolutionDir)_install_vcpkg.bat" $(Platform) msbuild static
</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
Expand All @@ -144,7 +144,7 @@
<AdditionalDependencies>version.lib;libcurl.lib;libcrypto.lib;libssl.lib;nghttp2.lib;zlib.lib;zstd.lib;brotlicommon.lib;brotlidec.lib;ws2_32.lib;Wldap32.lib;Crypt32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PreBuildEvent>
<Command>call py -3 _get_nsis_sdk.py &amp;&amp; py -3 _get_curl-ca-bundle.py &amp;&amp; call py -3 _update_resource_version.py &amp;&amp; call "$(SolutionDir)_install_vcpkg.bat" $(Platform) msbuild static
<Command>call py -3 _get_nsis_sdk.py &amp;&amp; py -3 _get_curl-ca-bundle.py &amp;&amp; call "$(SolutionDir)_install_vcpkg.bat" $(Platform) msbuild static
</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
import subprocess
from datetime import datetime
from datetime import datetime, timezone
import re
import argparse

# github workflow calls us with --version=1.2.3.4
parser = argparse.ArgumentParser()
parser.add_argument("-v", "--version", type=str, default="")
args = parser.parse_args()
if not args.version:
date = datetime.now(tz=timezone.utc)
args.version = f"{date.year}.{date.month}.{date.day}.0"
print(f"-- version is {args.version}")

v = args.version.split('.')
if len(v) != 4: raise ValueError(f"invalid version {args.version}")

'''
# execute: git log -1 --format=%ai
# output: b'2024-05-31 17:00:52 +0300\n'
output = subprocess.check_output(["git", "log", "-1", "--format=%ai"])
commit = datetime.fromisoformat(output.decode('utf-8').replace('\n', ''))
print(f"-- last commit was on {commit}")
date = datetime.fromisoformat(output.decode('utf-8').replace('\n', ''))
print(f"-- last commit was on {date}")
'''

# Replace strings in file
majver = 1
regexes = {
re.compile(r'^\s*FILEVERSION\s+([\d \t,]+)*$') : f"{majver},{commit.year},{commit.month},{commit.day}",
re.compile(r'^\s*VALUE\s+"FileVersion"\s*,\s*"([\d\.]+)"\s*$') : f"{majver}.{commit.year}.{commit.month}.{commit.day}",
re.compile(r'^\s*VALUE\s+"LegalCopyright"\s*,\s*"\D+\d+-(\d+).*$') : f"{commit.year}"
re.compile(r'^\s*FILEVERSION\s+([\d \t,]+)*$') : f"{v[0]},{v[1]},{v[2]},{v[3]}",
re.compile(r'^\s*VALUE\s+"FileVersion"\s*,\s*"([\d\.]+)"\s*$') : f"{v[0]}.{v[1]}.{v[2]}.{v[3]}",
re.compile(r'^\s*VALUE\s+"LegalCopyright"\s*,\s*"\D+\d+-(\d+).*$') : f"{datetime.now().year}"
}

lines = []
Expand Down

0 comments on commit 9cf7569

Please sign in to comment.