Skip to content

Commit

Permalink
Use external web server as vcpkg binary cache provider
Browse files Browse the repository at this point in the history
`VCPKG_BINARY_CACHE_URL` and `VCPKG_BINARY_CACHE_AUTH_HEADER` must be defined as project secrets
  • Loading branch information
negrutiu committed Oct 8, 2024
1 parent a359589 commit f9cbb57
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 72 deletions.
40 changes: 32 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ jobs:
shell: cmd

steps:
- id: version
name: Version
- name: Version
id: version
shell: python
run: |
import os
Expand All @@ -52,7 +52,7 @@ jobs:
msystem: mingw32
release: false
update: true
install: git mingw-w64-i686-toolchain
install: mingw-w64-i686-toolchain

- name: Upgrade msys2/mingw64
if: matrix.arch == 'amd64'
Expand All @@ -78,17 +78,41 @@ jobs:
repository: 'Microsoft/vcpkg'
path: vcpkg/repository

- name: Setup vcpkg cache
uses: actions/cache@v4
# Use `GitHub Actions Cache` (x-gha) as vcpkg binary cache provider
# Cache entries are removed 7d after the last cache hit
# https://learn.microsoft.com/en-us/vcpkg/consume/binary-caching-github-actions-cache
# - 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 || '');

# Use an external web server as vcpkg binary cache provider
# https://learn.microsoft.com/en-us/vcpkg/reference/binarycaching
- name: Export vcpkg cache server variables
env:
VCPKG_BINARY_CACHE_URL: ${{secrets.VCPKG_BINARY_CACHE_URL}}
VCPKG_BINARY_CACHE_AUTH_HEADER: ${{secrets.VCPKG_BINARY_CACHE_AUTH_HEADER}}
uses: actions/github-script@v7
with:
path: vcpkg/archives
key: ${{runner.os}}-${{matrix.arch}}-${{matrix.charset}}-${{hashFiles('vcpkg/overlay_*', 'vcpkg/repository/ports/curl', 'vcpkg/repository/ports/openssl', 'vcpkg/repository/ports/nghttp2', 'vcpkg/repository/ports/zlib', 'vcpkg/repository/ports/brotli', 'vcpkg/repository/ports/zstd')}}
script: |
core.exportVariable('VCPKG_BINARY_CACHE_URL', process.env.VCPKG_BINARY_CACHE_URL || '');
core.exportVariable('VCPKG_BINARY_CACHE_AUTH_HEADER', process.env.VCPKG_BINARY_CACHE_AUTH_HEADER || '');
# -----------------------------------------------------------------------
- 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
Expand All @@ -100,7 +124,7 @@ jobs:
print( f"versions_json={data}")
fout.write(f"versions_json={data}")
- name: Upload plugin
- name: Upload plugin binaries
uses: actions/upload-artifact@v4
with:
name: package-${{matrix.arch}}-${{matrix.charset}}
Expand Down
124 changes: 61 additions & 63 deletions .github/workflows/experiments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,80 @@ jobs:
# with:
# submodules: 'true'

- name: Print environment (before)
shell: cmd
run: |
echo ----------------------------------------------------
set
echo ----------------------------------------------------
for %%d in (%SystemDrive%\msys64\mingw32 %SystemDrive%\msys64\mingw64 %SystemDrive%\mingw32 %SystemDrive%\mingw64) do (
if exist "%%d\bin\gcc.exe" echo ---------- %%d\bin\gcc.exe ---------- && "%%d\bin\gcc.exe" -v
)
echo ----------------------------------------------------
dir /b /s %SystemDrive%\msys64\*.exe
echo ----------------------------------------------------
where gcc.exe
gcc.exe -v
echo ====================================================
py -0p
echo ----------------------------------------------------
py -3 -V
py -3 -m pip list
# [note] Pulls latest mingw-w64 (14.2.0) using msys2/pacman
# [note] Quite slow (4-5m)
# - name: Setup msys2/mingw32
# id: setup-msys2-mingw32
# uses: msys2/setup-msys2@v2
# with:
# msystem: mingw32
# release: false
# update: true
# install: mingw-w64-i686-toolchain

# - name: Setup msys2/mingw64
# id: setup-msys2-mingw64
# uses: msys2/setup-msys2@v2
# with:
# msystem: mingw64
# release: false
# update: true
# install: mingw-w64-x86_64-toolchain

# [note] Downloads an older mingw-w64 (13.2.0) with Chocolately
# [note] Runtime error: Cannot find path 'C:\ProgramData\chocolatey\lib\mingw\tools\install\mingw32\i686-w64-mingw32\lib\libpthread.dll.a' because it does not exist
# - name: Setup mingw32
# id: setup-mingw32
# uses: egor-tensin/setup-mingw@v2
# with:
# platform: x86

# - name: Setup mingw64
# id: setup-mingw64
# uses: egor-tensin/setup-mingw@v2
# with:
# platform: x64

- name: Print environment
shell: cmd
run: |
echo ----------------------------------------------------
set
echo ----------------------------------------------------
for %%d in (%SystemDrive%\msys64\mingw32 %SystemDrive%\msys64\mingw64 %SystemDrive%\mingw32 %SystemDrive%\mingw64) do (
if exist "%%d\bin\gcc.exe" echo ---------- %%d\bin\gcc.exe ---------- && "%%d\bin\gcc.exe" -v
)
echo ----------------------------------------------------
dir /b /s %SystemDrive%\msys64\*.exe
echo ----------------------------------------------------
where gcc.exe
gcc.exe -v
echo ====================================================
py -0p
echo ----------------------------------------------------
py -3 -V
py -3 -m pip list
- id: version
name: Version
shell: python
Expand All @@ -54,65 +114,3 @@ jobs:
shell: cmd
run: |
echo previous version=${{needs.experiments.outputs.version}}
release:
runs-on: ubuntu-latest
needs: experiments
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Download artifacts
shell: python
run: |
with open("test.txt", "w") as fout:
fout.write(f"Artifact sample for version ${{needs.experiments.outputs.version}}")
- name: Prepare release notes
shell: python
run: |
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('{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)
- uses: ncipollo/release-action@v1
with:
# note: `tag` is the release key
tag: release-candidate
name: v${{needs.experiments.outputs.version}}
artifacts: "test.txt"
bodyFile: .github/workflows/release-body.md
draft: true
makeLatest: true
allowUpdates: true
updateOnlyUnreleased: true
artifactErrorsFailBuild: 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}}\"")
10 changes: 9 additions & 1 deletion vcpkg/build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ set vcpkg_packages=%vcpkg_dir%\packages
REM set vcpkg_archives=%vcpkg_dir%\archives
set vcpkg_archives=%~dp0archives

rem | Optional GitHub Actions cache
rem | https://learn.microsoft.com/en-us/vcpkg/consume/binary-caching-github-actions-cache
if defined GITHUB_ACTIONS if defined ACTIONS_CACHE_URL if defined ACTIONS_RUNTIME_TOKEN set vcpkg_cache_gha=x-gha,readwrite&& echo --- using GitHub Actions as cache provider

rem | Optional external webserver cache
rem | https://learn.microsoft.com/en-us/vcpkg/reference/binarycaching
if defined VCPKG_BINARY_CACHE_URL if defined VCPKG_BINARY_CACHE_AUTH_HEADER set vcpkg_cache_http=http,%VCPKG_BINARY_CACHE_URL%,readwrite,Authorization: %VCPKG_BINARY_CACHE_AUTH_HEADER%&& echo --- using external web server as cache provider

echo -------------------------------------------------------------------------
echo Build ^& install vcpkg ...
echo -------------------------------------------------------------------------
Expand All @@ -76,7 +84,7 @@ vcpkg.exe ^
--x-install-root="%vcpkg_installed%" ^
--downloads-root="%vcpkg_downloads%" ^
--x-buildtrees-root="%vcpkg_buildtrees%" ^
--binarysource=clear;files,"%vcpkg_archives%",readwrite ^
--binarysource="clear;files,%vcpkg_archives%,readwrite;%vcpkg_cache_gha%;%vcpkg_cache_http%" ^
--x-packages-root="%vcpkg_packages%" ^
--no-print-usage

Expand Down

0 comments on commit f9cbb57

Please sign in to comment.