Skip to content

Commit

Permalink
fix: update build script
Browse files Browse the repository at this point in the history
Signed-off-by: Junjie Gao <[email protected]>
  • Loading branch information
JeyJeyGao committed Mar 29, 2024
1 parent 16d9221 commit 4a9f916
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 64 deletions.
26 changes: 12 additions & 14 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,32 +51,28 @@ jobs:
run: make test
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
- name: Build bianry for E2E testing
- name: Build Linux Binary
run: |
./scripts/build.sh v0.0.1 linux-x64
./scripts/build.sh v0.0.1 win-x64
./scripts/build.sh v0.0.1 osx-x64
# the binary will be shared on E2E test
python3 ./scripts/build.py v0.0.1 linux-x64 --enable-aot
- name: Upload Linux artifact
if: github.event.pull_request.head.repo.full_name == github.repository || github.event_name == 'push'
uses: actions/upload-artifact@v2
with:
name: linux-amd64-binary
path: ./bin/artifacts/notation-azure-kv_0.0.1_linux_amd64.tar.gz
retention-days: 1
- name: Build macOS Binary
run: |
# the binary will be shared on E2E test
python3 ./scripts/build.py v0.0.1 osx-x64
- name: Upload macOS artifact
if: github.event.pull_request.head.repo.full_name == github.repository || github.event_name == 'push'
uses: actions/upload-artifact@v2
with:
name: darwin-amd64-binary
path: ./bin/artifacts/notation-azure-kv_0.0.1_darwin_amd64.tar.gz
retention-days: 1
- name: Upload Windows artifact
if: github.event.pull_request.head.repo.full_name == github.repository || github.event_name == 'push'
uses: actions/upload-artifact@v2
with:
name: win-amd64-binary
path: ./bin/artifacts/notation-azure-kv_0.0.1_windows_amd64.zip
retention-days: 1
e2e-mariner-container:
name: E2E testing for Mariner container
runs-on: ubuntu-latest
Expand Down Expand Up @@ -144,10 +140,12 @@ jobs:
steps:
- name: Check out code into the project directory
uses: actions/checkout@v3
- uses: actions/download-artifact@v3
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
name: win-amd64-binary
path: ./bin/artifacts
dotnet-version: '8.0.x'
- name: Build Windows Binary
run: python3 ./scripts/build.py v0.0.1 win-x64 --enable-aot
- name: Run download server locally
run: |
# wsl bash
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ coverage.txt
.vscode/
.idea/
.devcontainer
.mono

# binary output
bin/
Expand Down
71 changes: 71 additions & 0 deletions scripts/build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import argparse
import os
import subprocess
import tarfile
import zipfile

def main():
parser = argparse.ArgumentParser()
parser.add_argument('version', help='The version tag, starts with v')
parser.add_argument('runtime', help='The runtime environment, e.g. win-x64, linux-x64, osx-x64, linux-arm64, osx-arm64')
parser.add_argument('--enable-aot', action='store_true', help='Enable AOT compilation')
args = parser.parse_args()

version = args.version.lstrip('v')
project_name = 'notation-azure-kv'
output_dir = os.path.join('.', 'bin', 'publish')
os.makedirs(output_dir, exist_ok=True)
artifacts_dir = os.path.join('.', 'bin', 'artifacts')
os.makedirs(artifacts_dir, exist_ok=True)

# Get the latest commit hash
commit_hash = subprocess.check_output(['git', 'log', '--pretty=format:%h', '-n', '1']).decode('utf-8')
print(f'Commit hash: {commit_hash}')

# Prepare the dotnet publish command
publish_command = [
'dotnet', 'publish', './Notation.Plugin.AzureKeyVault',
'--configuration', 'Release',
'--self-contained', 'true',
f'-p:CommitHash={commit_hash}',
f'-p:Version={version}',
'-r', args.runtime,
'-o', f'{output_dir}/{args.runtime}'
]

if args.enable_aot:
publish_command.append('-p:PublishAot=true')
else:
publish_command.append('-p:PublishSingleFile=true')

# Publish for each runtime
subprocess.run(publish_command, check=True)

# Determine the target platform
if args.runtime.startswith('win'):
ext = 'zip'
binary_name = f'{project_name}.exe'
else:
ext = 'tar.gz'
binary_name = project_name

# Apply the runtime name mapping
mapped_runtime = args.runtime.replace('x64', 'amd64')
mapped_runtime = mapped_runtime.replace('win', 'windows')
mapped_runtime = mapped_runtime.replace('osx', 'darwin')
mapped_runtime = mapped_runtime.replace('-', '_')
artifact_name = f'{artifacts_dir}/{project_name}_{version}_{mapped_runtime}.{ext}'
binary_dir = f'{output_dir}/{args.runtime}'

# Create the artifact
if ext == 'zip':
with zipfile.ZipFile(artifact_name, 'w', zipfile.ZIP_DEFLATED) as zipf:
zipf.write(os.path.join(binary_dir, binary_name), arcname=binary_name)
zipf.write('LICENSE')
else:
with tarfile.open(artifact_name, 'w:gz') as tar:
tar.add(os.path.join(binary_dir, binary_name), arcname=binary_name)
tar.add('LICENSE')

if __name__ == '__main__':
main()
50 changes: 0 additions & 50 deletions scripts/build.sh

This file was deleted.

0 comments on commit 4a9f916

Please sign in to comment.