Skip to content

Commit 21a0137

Browse files
authored
Build Linux wrappers on docker (#2603)
1 parent 3f6c966 commit 21a0137

File tree

8 files changed

+115
-54
lines changed

8 files changed

+115
-54
lines changed

.github/templates/codeql.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
#@ load("@ytt:template", "template")
2-
#@ load("common.lib.yml", "configuration", "nugetPackages", "checkoutCode", "setupVcpkg")
2+
#@ load("common.lib.yml", "configuration", "nugetPackages", "checkoutCode", "setupVcpkg", "actionCodeQLInit", "actionCodeQLAnalyze", "actionSetupMSBuild")
33

44
#@ def runCodeQL(language, buildSteps = []):
55
- name: Initialize CodeQL
6-
uses: github/codeql-action/init@v1
6+
uses: #@ actionCodeQLInit
77
with:
88
languages: #@ language
99
queries: security-and-quality
1010
#@ for step in buildSteps:
1111
- #@ template.replace(step)
1212
#@ end
1313
- name: Perform CodeQL Analysis
14-
uses: github/codeql-action/analyze@v1
14+
uses: #@ actionCodeQLAnalyze
1515
#@ end
1616

1717
#@ def buildWrappers():
@@ -21,7 +21,7 @@
2121

2222
#@ def buildPackages():
2323
- name: Add msbuild to PATH
24-
uses: microsoft/setup-msbuild@v1.0.2
24+
uses: #@ actionSetupMSBuild
2525
#@ for pkgName in nugetPackages:
2626
- name: #@ "Build " + pkgName
2727
run: #@ "msbuild Realm/" + pkgName + " -p:UseSharedCompilation=false -restore -p:Configuration=" + configuration

.github/templates/common.lib.yml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
11
#@ configuration = "Release"
22
#@ nugetPackages = [ 'Realm.Fody', 'Realm', 'Realm.UnityUtils', 'Realm.UnityWeaver' ]
3+
#@ actionCheckout = "actions/checkout@v2"
4+
#@ actionCache = "actions/cache@v2"
5+
#@ actionUploadArtifact = "actions/upload-artifact@v2"
6+
#@ actionDownloadArtifact = "actions/download-artifact@v2"
7+
#@ actionSetupMSBuild = "microsoft/setup-msbuild@v1.0.2"
8+
#@ actionSetupDotnet = "actions/setup-dotnet@v1"
9+
#@ actionRuniOSSimulator = "realm/ci-actions/run-ios-simulator@v1"
10+
#@ actionCodeQLInit = "github/codeql-action/init@v1"
11+
#@ actionCodeQLAnalyze = "github/codeql-action/analyze@v1"
12+
#@ actionSetupNode = "actions/setup-node@v2"
13+
#@ actionAWSConfigureCredentials = "aws-actions/configure-aws-credentials@v1"
14+
15+
#@ actionDockerLayerCaching = "satackey/action-docker-layer-caching@cc3f3828e75cbb45f0cf5139b95329c88480aa97" #! 0.0.11
16+
#@ actionDockerBuild = "docker/build-push-action@375f72aff65b645c51f122f04a776df8416b222b" #! 2.7.0
17+
#@ actionDockerRun = "addnab/docker-run-action@3e77f186b7a929ef010f183a9e24c0f9955ea609" #! v3
18+
#@ actionCoveralls = "coverallsapp/github-action@9ba913c152ae4be1327bfb9085dc806cedb44057" #! v1.1.3
19+
#@ actionDeleteArtifact = "geekyeggo/delete-artifact@56e063d7d8bf9972ac54aca4454d3a6675917f44" #! v1
20+
#@ actionGithubRelease = "ncipollo/release-action@a4f828a4e5777f12a55454900a18d3e60d8803fd" #! v1
21+
#@ actionDownloadAllArtifacts = "dawidd6/action-download-artifact@d0f291cf39bd21965ea9c4c6e210fc355c3844ed" #! v2.14.1
322

423
#@ def checkoutCode(submodules=False, registerProblemMatchers=True):
524
- name: Checkout code
6-
uses: actions/checkout@v2
25+
uses: #@ actionCheckout
726
with:
827
submodules: #@ submodules
928
ref: ${{ github.event.pull_request.head.sha }}
@@ -18,7 +37,7 @@
1837
#@ def setupVcpkg(ifCondition = "true"):
1938
- name: Check Vcpkg cache
2039
id: check-vcpkg-cache
21-
uses: actions/cache@v2
40+
uses: #@ actionCache
2241
with:
2342
path: 'C:\src'
2443
key: vcpkg

.github/templates/main.yml

Lines changed: 62 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,53 @@
11
#@ load("@ytt:template", "template")
22
#@ load("@ytt:overlay", "overlay")
3-
#@ load("common.lib.yml", "configuration", "nugetPackages", "checkoutCode", "setupVcpkg")
3+
#@ load("common.lib.yml", "configuration", "nugetPackages", "checkoutCode", "setupVcpkg", "actionCache", "actionUploadArtifact", "actionDownloadArtifact", "actionSetupMSBuild", "actionSetupDotnet", "actionRuniOSSimulator", "actionDockerLayerCaching", "actionDockerBuild", "actionDockerRun", "actionCoveralls", "actionDeleteArtifact")
44

55
#@ androidABIs = [ 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64' ]
66
#@ windowsArchs = [ 'Win32', 'x64' ]
77
#@ windowsUWPArchs = [ 'Win32', 'x64', 'ARM' ]
88
#@ wrappersCacheCondition = "steps.check-cache.outputs.cache-hit != 'true'"
99
#@ dotnetRuntime = "${{ (runner.os == 'macOS' && 'osx-x64') || (runner.os == 'Windows' && 'win-x64') || (runner.os == 'Linux' && 'linux-x64') || '???' }}"
1010

11-
#@ def checkCache(key):
11+
#@ def getWrapperBuildCommand(cmd):
12+
#@ configurationParam = " --configuration=" + configuration
13+
#@ ltoParam = " -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=${{ github.event_name != 'pull_request' && 'ON' || 'OFF' }}"
14+
#@ if cmd.startswith("powershell"):
15+
#@ configurationParam = " -Configuration " + configuration
16+
#@ ltoParam = "${{ github.event_name != 'pull_request' && ' -EnableLTO' || '' }}"
17+
#@ end
18+
#@ return cmd + configurationParam + ltoParam
19+
#@ end
20+
21+
#@ def checkCache(outputVar):
22+
#@ key = outputVar + "-" + configuration + "-${{ github.event_name != 'pull_request' && 'ON' || 'OFF' }}-${{hashFiles('./wrappers/**')}}"
1223
name: Check cache
1324
id: check-cache
14-
uses: actions/cache@v2
25+
uses: #@ actionCache
1526
with:
1627
path: ./wrappers/build/**
1728
key: #@ key
1829
#@ end
1930

20-
#@ def buildWrappers(cmd, outputVar, intermediateSteps = []):
21-
#@ configurationParam = " --configuration=" + configuration
22-
#@ ltoParam = " -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=${{ github.event_name != 'pull_request' && 'ON' || 'OFF' }}"
23-
#@ if cmd.startswith("powershell"):
24-
#@ configurationParam = " -Configuration " + configuration
25-
#@ ltoParam = "${{ github.event_name != 'pull_request' && ' -EnableLTO' || '' }}"
31+
#@ def storeWrapperBinaries(outputVar):
32+
name: Store artifacts
33+
uses: #@ actionUploadArtifact
34+
with:
35+
name: #@ outputVar
36+
path: wrappers/build/**
37+
retention-days: 1
2638
#@ end
27-
#@ cacheKey = outputVar + "-" + configuration + "-${{ github.event_name != 'pull_request' && 'ON' || 'OFF' }}-${{hashFiles('./wrappers/**')}}"
28-
#@ actualCommand = cmd + configurationParam + ltoParam
2939

40+
#@ def buildWrappers(cmd, outputVar, intermediateSteps = []):
3041
steps:
3142
- #@ template.replace(checkoutCode("recursive"))
32-
- #@ checkCache(cacheKey)
43+
- #@ checkCache(outputVar)
3344
#@ for step in intermediateSteps:
3445
- #@ template.replace(step)
3546
#@ end
3647
- name: Build wrappers
37-
run: #@ actualCommand
48+
run: #@ getWrapperBuildCommand(cmd)
3849
if: #@ wrappersCacheCondition
39-
- name: Store artifacts
40-
uses: actions/upload-artifact@v2
41-
with:
42-
name: #@ outputVar
43-
path: wrappers/build/**
44-
retention-days: 1
50+
- #@ storeWrapperBinaries(outputVar)
4551
#@ end
4652

4753
#@ def setupWin81SDK():
@@ -62,7 +68,7 @@ steps:
6268

6369
#@ def msbuildOnWin(projectPath, **properties):
6470
- name: Add msbuild to PATH
65-
uses: microsoft/setup-msbuild@v1.0.2
71+
uses: #@ actionSetupMSBuild
6672
- #@ msbuild(projectPath, RestoreConfigFile="Tests/Test.NuGet.Config", UseRealmNupkgsWithVersion="${{ needs.build-packages.outputs.package_version }}", **properties)
6773
#@ end
6874

@@ -71,7 +77,7 @@ steps:
7177
- name: #@ "Build Unity"
7278
run: #@ "dotnet run --project Tools/SetupUnityPackage/ -- realm --packages-path Realm/packages --pack"
7379
- name: Store Unity artifacts
74-
uses: actions/upload-artifact@v2
80+
uses: #@ actionUploadArtifact
7581
with:
7682
name: #@ finalPkgName
7783
path: #@ "${{ github.workspace }}/Realm/Realm.Unity/" + finalPkgName
@@ -84,7 +90,7 @@ steps:
8490
- name: Check Docfx cache
8591
id: check-docfx-cache
8692
if: #@ docsCondition
87-
uses: actions/cache@v2
93+
uses: #@ actionCache
8894
with:
8995
path: 'C:\docfx'
9096
key: docfx
@@ -101,7 +107,7 @@ steps:
101107
Compress-Archive -Path Docs/_site -DestinationPath "Realm/packages/Docs.zip"
102108
- name: Store docs artifacts
103109
if: #@ docsCondition
104-
uses: actions/upload-artifact@v2
110+
uses: #@ actionUploadArtifact
105111
with:
106112
name: Docs.zip
107113
path: ${{ github.workspace }}/Realm/packages/Docs.zip
@@ -112,7 +118,7 @@ steps:
112118
#@ for pkgName in [ 'Realm.Fody', 'Realm' ]:
113119
#@ finalPkgName = pkgName + ".${{ steps.find-nupkg-version.outputs.package_version }}"
114120
- name: #@ "Store artifacts for " + pkgName
115-
uses: actions/upload-artifact@v2
121+
uses: #@ actionUploadArtifact
116122
with:
117123
name: #@ finalPkgName
118124
path: #@ "${{ github.workspace }}/Realm/packages/" + finalPkgName + ".*nupkg"
@@ -123,7 +129,7 @@ steps:
123129
#@ def fetchPackageArtifacts():
124130
#@ for pkg in [ "Realm", "Realm.Fody" ]:
125131
- name: #@ "Fetch " + pkg
126-
uses: actions/download-artifact@v2
132+
uses: #@ actionDownloadArtifact
127133
with:
128134
name: #@ pkg + ".${{ needs.build-packages.outputs.package_version }}"
129135
path: ${{ github.workspace }}/Realm/packages/
@@ -148,7 +154,7 @@ steps:
148154
#@ def fetchWrapperBinaries():
149155
#@ for platform in getWrapperBinaryNames():
150156
- name: #@ "Fetch artifacts for " + platform
151-
uses: actions/download-artifact@v2
157+
uses: #@ actionDownloadArtifact
152158
with:
153159
name: #@ "wrappers-" + platform
154160
path: wrappers/build
@@ -240,9 +246,30 @@ jobs:
240246
name: Wrappers iOS
241247
_: #@ template.replace(buildWrappers("./wrappers/build-ios.sh", "wrappers-ios"))
242248
build-wrappers-linux:
243-
runs-on: ubuntu-20.04
249+
runs-on: ubuntu-latest
244250
name: Wrappers Linux
245-
_: #@ template.replace(buildWrappers("./wrappers/build.sh", "wrappers-linux"))
251+
steps:
252+
- #@ template.replace(checkoutCode("recursive"))
253+
- #@ checkCache("wrappers-linux")
254+
- uses: #@ actionDockerLayerCaching
255+
continue-on-error: true
256+
if: #@ wrappersCacheCondition
257+
- name: Build CentOS image
258+
uses: #@ actionDockerBuild
259+
with:
260+
tags: wrappers-centos:latest
261+
file: ./wrappers/centos.Dockerfile
262+
push: false
263+
if: #@ wrappersCacheCondition
264+
- name: Build wrappers
265+
uses: #@ actionDockerRun
266+
with:
267+
image: wrappers-centos:latest
268+
shell: bash
269+
options: -v ${{ github.workspace }}:/work
270+
run: #@ getWrapperBuildCommand("/work/wrappers/build.sh")
271+
if: #@ wrappersCacheCondition
272+
- #@ storeWrapperBinaries("wrappers-linux")
246273
build-wrappers-android:
247274
runs-on: ubuntu-20.04
248275
name: Wrappers Android
@@ -278,7 +305,7 @@ jobs:
278305
package_version: ${{ steps.find-nupkg-version.outputs.package_version }}
279306
steps:
280307
- name: Add msbuild to PATH
281-
uses: microsoft/setup-msbuild@v1.0.2
308+
uses: #@ actionSetupMSBuild
282309
- #@ template.replace(checkoutCode())
283310
- name: Set version suffix
284311
id: set-version-suffix
@@ -367,7 +394,7 @@ jobs:
367394
steps:
368395
- #@ template.replace(checkoutCode())
369396
- #@ template.replace(fetchPackageArtifacts())
370-
- uses: actions/setup-dotnet@v1
397+
- uses: #@ actionSetupDotnet
371398
if: matrix.targetFramework == 'net6.0'
372399
with:
373400
dotnet-version: '6.0.x'
@@ -394,7 +421,7 @@ jobs:
394421
- #@ template.replace(fetchPackageArtifacts())
395422
- #@ msbuild("Tests/Tests.iOS", TargetFrameworkVersion="v1.0", Platform="iPhoneSimulator", RestoreConfigFile="Tests/Test.NuGet.Config", UseRealmNupkgsWithVersion="${{ needs.build-packages.outputs.package_version }}")
396423
- name: Run the tests
397-
uses: realm/ci-actions/run-ios-simulator@v1
424+
uses: #@ actionRuniOSSimulator
398425
with:
399426
appPath: 'Tests/Tests.iOS/bin/iPhoneSimulator/Release/Tests.iOS.app'
400427
bundleId: 'io.realm.dotnettests'
@@ -417,7 +444,7 @@ jobs:
417444
steps:
418445
- #@ template.replace(checkoutCode())
419446
- #@ template.replace(fetchWrapperBinaries())
420-
- uses: actions/setup-dotnet@v1
447+
- uses: #@ actionSetupDotnet
421448
with:
422449
dotnet-version: '5.0.x'
423450
- name: Setup Coverlet & Report Generator
@@ -428,7 +455,7 @@ jobs:
428455
- #@ template.replace(dotnetPublishAndRunCoverage("net5.0"))
429456
- name: Publish Coverage
430457
id: publish-coveralls
431-
uses: coverallsapp/github-action@9ba913c152ae4be1327bfb9085dc806cedb44057 #! v1.1.3
458+
uses: #@ actionCoveralls
432459
with:
433460
github-token: ${{ secrets.GITHUB_TOKEN }}
434461
path-to-lcov: ./report.lcov
@@ -443,7 +470,7 @@ jobs:
443470
steps:
444471
#@ for platform in getWrapperBinaryNames():
445472
- name: #@ "Delete artifacts for " + platform
446-
uses: geekyeggo/delete-artifact@56e063d7d8bf9972ac54aca4454d3a6675917f44 #! v1
473+
uses: #@ actionDeleteArtifact
447474
with:
448475
name: #@ "wrappers-" + platform
449476
#@ end
@@ -470,7 +497,7 @@ jobs:
470497
dashboard-path: dashboard.charts
471498
nuget-package: ${{ github.workspace }}/Realm/packages/Realm.${{ needs.build-packages.outputs.package_version }}.nupkg
472499
- name: Upload Charts Dashboard File
473-
uses: actions/upload-artifact@v2
500+
uses: #@ actionUploadArtifact
474501
with:
475502
name: dashboard.charts
476503
path: ${{ github.workspace }}/dashboard.charts

.github/templates/publish-release.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#@ load("@ytt:template", "template")
2+
#@ load("common.lib.yml", "checkoutCode", "actionDownloadAllArtifacts", "actionSetupNode", "actionAWSConfigureCredentials", "actionGithubRelease")
23

34
#@ def uploadToNuget(packageName, includeSymbols = False):
45
- name: #@ "NuGet Publish " + packageName + ".${{ steps.get-version.outputs.version }}"
@@ -11,7 +12,7 @@
1112
#@ end
1213

1314
#@ def uploadToNpm(packageName):
14-
- uses: actions/setup-node@v2
15+
- uses: #@ actionSetupNode
1516
with:
1617
node-version: '12.x'
1718
registry-url: 'https://registry.npmjs.org'
@@ -23,7 +24,7 @@
2324

2425
#@ def publishGithubRelease():
2526
- name: Create Github Release
26-
uses: ncipollo/release-action@v1
27+
uses: #@ actionGithubRelease
2728
with:
2829
artifacts: ${{ github.workspace }}/Realm/packages/io.realm.unity-${{ steps.get-version.outputs.version }}.tgz/io.realm.unity-${{ steps.get-version.outputs.version }}.tgz
2930
bodyFile: ${{ steps.extract-release-notes.outputs.release-notes-path }}
@@ -36,7 +37,7 @@
3637

3738
#@ def uploadDocsToS3():
3839
- name: Configure AWS Credentials
39-
uses: aws-actions/configure-aws-credentials@v1
40+
uses: #@ actionAWSConfigureCredentials
4041
with:
4142
aws-access-key-id: ${{ secrets.DOCS_S3_ACCESS_KEY }}
4243
aws-secret-access-key: ${{ secrets.DOCS_S3_SECRET_KEY }}
@@ -60,12 +61,9 @@ jobs:
6061
runs-on: windows-latest
6162
environment: Production
6263
steps:
63-
- name: Checkout code
64-
uses: actions/checkout@v2
65-
with:
66-
submodules: false
64+
- #@ template.replace(checkoutCode(False, False))
6765
- name: Download all artifacts
68-
uses: dawidd6/action-download-artifact@v2
66+
uses: #@ actionDownloadAllArtifacts
6967
with:
7068
workflow: main.yml
7169
commit: ${{ github.sha }}

.github/workflows/main.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
path: wrappers/build/**
6666
retention-days: 1
6767
build-wrappers-linux:
68-
runs-on: ubuntu-20.04
68+
runs-on: ubuntu-latest
6969
name: Wrappers Linux
7070
steps:
7171
- name: Checkout code
@@ -83,8 +83,23 @@ jobs:
8383
with:
8484
path: ./wrappers/build/**
8585
key: wrappers-linux-Release-${{ github.event_name != 'pull_request' && 'ON' || 'OFF' }}-${{hashFiles('./wrappers/**')}}
86+
- uses: satackey/action-docker-layer-caching@cc3f3828e75cbb45f0cf5139b95329c88480aa97
87+
continue-on-error: true
88+
if: steps.check-cache.outputs.cache-hit != 'true'
89+
- name: Build CentOS image
90+
uses: docker/build-push-action@375f72aff65b645c51f122f04a776df8416b222b
91+
with:
92+
tags: wrappers-centos:latest
93+
file: ./wrappers/centos.Dockerfile
94+
push: false
95+
if: steps.check-cache.outputs.cache-hit != 'true'
8696
- name: Build wrappers
87-
run: ./wrappers/build.sh --configuration=Release -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=${{ github.event_name != 'pull_request' && 'ON' || 'OFF' }}
97+
uses: addnab/docker-run-action@3e77f186b7a929ef010f183a9e24c0f9955ea609
98+
with:
99+
image: wrappers-centos:latest
100+
shell: bash
101+
options: -v ${{ github.workspace }}:/work
102+
run: /work/wrappers/build.sh --configuration=Release -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=${{ github.event_name != 'pull_request' && 'ON' || 'OFF' }}
88103
if: steps.check-cache.outputs.cache-hit != 'true'
89104
- name: Store artifacts
90105
uses: actions/upload-artifact@v2

0 commit comments

Comments
 (0)