Skip to content

Commit 3d8a0fe

Browse files
andreidanila1AlexandraTrifan
authored andcommitted
tools/pkggenerator: Generate workflows.
Signed-off-by: andreidanila1 <[email protected]>
1 parent 0b562ad commit 3d8a0fe

File tree

7 files changed

+487
-0
lines changed

7 files changed

+487
-0
lines changed

tools/packagegenerator/package_generator.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from mako.template import Template
88
import subprocess
99
import platform
10+
import stat
1011

1112
if platform.system() != "Windows":
1213
MODE = 0o775
@@ -27,6 +28,12 @@
2728
"tool_src": os.path.join("templates", "plugin", "tool_src.mako"),
2829
"pkg_cmake": os.path.join("templates", "package", "pkg_cmakelists.mako"),
2930
"manifest": os.path.join("templates", "package", "manifest_cmakein.mako"),
31+
"ubuntu_build": os.path.join("templates", "ci", "ubuntu22_build.mako"),
32+
"windows_build": os.path.join("templates", "ci", "windows_build.mako"),
33+
"arm64_build": os.path.join("templates", "ci", "arm64_build.mako"),
34+
"armhf_build": os.path.join("templates", "ci", "armhf_build.mako"),
35+
"windows_script": os.path.join("templates", "ci", "build_mingw_pkg.mako"),
36+
"macOS_build": os.path.join("templates", "ci", "macOS_build.mako"),
3037
"pdk_header": os.path.join("templates", "pdk", "pdk_header.mako"),
3138
"pdk_src": os.path.join("templates", "pdk", "pdk_src.mako"),
3239
"pdk_cmake": os.path.join("templates", "pdk", "pdk_cmakelists.mako"),
@@ -588,6 +595,8 @@ def init_submodule_and_generate_pkg(packages_path, config, args):
588595

589596
# Generate the package in the submodule
590597
generate_pkg(packages_path, config, args)
598+
# Generate workflows
599+
generate_workflows(submodule_path)
591600

592601
def add_existing_git_submodule(packages_path, repo_url):
593602
"""
@@ -619,6 +628,39 @@ def add_existing_git_submodule(packages_path, repo_url):
619628

620629
print(f"Added existing repository as submodule at {submodule_path}.")
621630

631+
def generate_workflows(package_path):
632+
"""
633+
Generates GitHub Actions workflow files from Mako templates.
634+
Args:
635+
package_path (str): Path to the package directory.
636+
"""
637+
# Define the workflows directory
638+
workflows_path = os.path.join(package_path, ".github", "workflows")
639+
create_directory(workflows_path)
640+
# Create scripts directory
641+
scripts_path = os.path.join(package_path, "scripts")
642+
create_directory(scripts_path)
643+
644+
# Generate the Windows script
645+
windows_script_path = os.path.join(scripts_path, "build_mingw_pkg.sh")
646+
create_file_from_template(TEMPLATES["windows_script"], windows_script_path)
647+
648+
# Set executable permissions for non-Windows platforms
649+
if platform.system() != "Windows":
650+
os.chmod(windows_script_path, stat.S_IRWXU)
651+
652+
# Define the templates and their output filenames
653+
workflows = {
654+
TEMPLATES["ubuntu_build"]: os.path.join(workflows_path, "ubuntu22_build.yml"),
655+
TEMPLATES["windows_build"]: os.path.join(workflows_path, "windows_build.yml"),
656+
TEMPLATES["arm64_build"]: os.path.join(workflows_path, "arm64_build.yml"),
657+
TEMPLATES["armhf_build"]: os.path.join(workflows_path, "armhf_build.yml"),
658+
TEMPLATES["macOS_build"]: os.path.join(package_path, "azure-pipelines.yml")
659+
}
660+
for template_path, output_path in workflows.items():
661+
# Generate the workflow file from the template
662+
create_file_from_template(template_path, output_path)
663+
622664
if __name__ == "__main__":
623665
args = get_args()
624666
src_dir = args.src or os.path.curdir
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
2+
name: Build Scopy Package (AppImage-arm64)
3+
4+
on:
5+
push:
6+
pull_request:
7+
8+
env:
9+
BUILD_HOST: ubuntu-22.04
10+
USERNAME: github-actions
11+
12+
jobs:
13+
build_arm64_package:
14+
runs-on: ubuntu-22.04
15+
steps:
16+
- name: Checkout Package Repository (this repo)
17+
uses: actions/checkout@v4
18+
with:
19+
set-safe-directory: 'true'
20+
fetch-depth: 0
21+
path: package
22+
23+
- name: Clone Scopy Repository
24+
uses: actions/checkout@v4
25+
with:
26+
set-safe-directory: 'true'
27+
repository: analogdevicesinc/scopy
28+
path: scopy
29+
ref: main-pkg-manager
30+
31+
- name: Check package generator
32+
run: |
33+
cd $GITHUB_WORKSPACE/scopy/tools/packagegenerator
34+
pip3 install -r requirements.txt
35+
python3 ./package_generator.py -h
36+
37+
- name: Pull the Docker Image
38+
run: docker pull cristianbindea/scopy2-arm64-appimage:latest
39+
40+
- name: Get Repository Name
41+
id: repo
42+
run: echo "REPO_NAME=$(basename $GITHUB_REPOSITORY)" >> $GITHUB_ENV
43+
44+
- name: Build package
45+
shell: bash
46+
run: |
47+
echo 'Copy package to scopy/packages'
48+
mkdir -p $GITHUB_WORKSPACE/scopy/packages/$REPO_NAME
49+
cp -r $GITHUB_WORKSPACE/package/* $GITHUB_WORKSPACE/scopy/packages/$REPO_NAME/
50+
51+
cd $GITHUB_WORKSPACE/scopy
52+
sudo apt update
53+
./ci/arm/create_sysroot.sh arm64 install_packages
54+
./ci/arm/arm_build_process.sh arm64 generate_ci_envs
55+
<%text>
56+
docker run \
57+
--mount type=bind,source="$GITHUB_WORKSPACE/scopy",target=/home/runner/scopy \
58+
--env-file $GITHUB_WORKSPACE/scopy/ci/general/gh-actions.envs \
59+
--env REPO_NAME=$REPO_NAME \
60+
cristianbindea/scopy2-arm64-appimage:latest \
61+
/bin/bash -c 'cd $HOME && \
62+
sudo chown -R runner:runner scopy && \
63+
cd $HOME/scopy && \
64+
./ci/arm/arm_build_process.sh arm64 install_packages move_tools move_sysroot build_scopy'
65+
</%text>
66+
- name: Set short git commit SHA
67+
shell: bash
68+
run: echo "commit_sha=$(git rev-parse --short ${"${{ github.sha }}"})" >> "$GITHUB_ENV"
69+
- name: Archive using package generator
70+
run: |
71+
cd $GITHUB_WORKSPACE/scopy/tools/packagegenerator
72+
python3 ./package_generator.py -a --src=$GITHUB_WORKSPACE/scopy/build/packages/$REPO_NAME --dest=$GITHUB_WORKSPACE/
73+
- uses: actions/upload-artifact@v4
74+
with:
75+
name: linux-arm64-${"${{ env.REPO_NAME }}"}
76+
path: ${"${{ github.workspace }}"}/${"${{ env.REPO_NAME }}"}.zip
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
2+
name: Build Scopy Package (AppImage-armhf)
3+
4+
on:
5+
push:
6+
pull_request:
7+
8+
env:
9+
BUILD_HOST: ubuntu-22.04
10+
USERNAME: github-actions
11+
12+
jobs:
13+
build_armhf_package:
14+
runs-on: ubuntu-22.04
15+
steps:
16+
- name: Checkout Package Repository (this repo)
17+
uses: actions/checkout@v4
18+
with:
19+
set-safe-directory: 'true'
20+
fetch-depth: 0
21+
path: package
22+
23+
- name: Clone Scopy Repository
24+
uses: actions/checkout@v4
25+
with:
26+
set-safe-directory: 'true'
27+
repository: analogdevicesinc/scopy
28+
path: scopy
29+
ref: main-pkg-manager
30+
31+
- name: Check package generator
32+
run: |
33+
cd $GITHUB_WORKSPACE/scopy/tools/packagegenerator
34+
pip3 install -r requirements.txt
35+
python3 ./package_generator.py -h
36+
37+
- name: Pull the Docker Image
38+
run: docker pull cristianbindea/scopy2-armhf-appimage:latest
39+
40+
- name: Get Repository Name
41+
id: repo
42+
run: echo "REPO_NAME=$(basename $GITHUB_REPOSITORY)" >> $GITHUB_ENV
43+
44+
- name: Build package
45+
shell: bash
46+
run: |
47+
echo 'Copy package to scopy/packages'
48+
mkdir -p $GITHUB_WORKSPACE/scopy/packages/$REPO_NAME
49+
cp -r $GITHUB_WORKSPACE/package/* $GITHUB_WORKSPACE/scopy/packages/$REPO_NAME/
50+
51+
cd $GITHUB_WORKSPACE/scopy
52+
sudo apt update
53+
./ci/arm/create_sysroot.sh arm32 install_packages
54+
./ci/arm/arm_build_process.sh arm32 generate_ci_envs
55+
<%text>
56+
docker run \
57+
--mount type=bind,source="$GITHUB_WORKSPACE/scopy",target=/home/runner/scopy \
58+
--env-file $GITHUB_WORKSPACE/scopy/ci/general/gh-actions.envs \
59+
--env REPO_NAME=$REPO_NAME \
60+
cristianbindea/scopy2-armhf-appimage:latest \
61+
/bin/bash -c 'cd $HOME && \
62+
sudo chown -R runner:runner scopy && \
63+
cd $HOME/scopy && \
64+
./ci/arm/arm_build_process.sh arm32 install_packages move_tools move_sysroot build_scopy'
65+
</%text>
66+
- name: Set short git commit SHA
67+
shell: bash
68+
run: echo "commit_sha=$(git rev-parse --short ${"${{ github.sha }}"})" >> "$GITHUB_ENV"
69+
- name: Archive using package generator
70+
run: |
71+
cd $GITHUB_WORKSPACE/scopy/tools/packagegenerator
72+
python3 ./package_generator.py -a --src=$GITHUB_WORKSPACE/scopy/build/packages/$REPO_NAME --dest=$GITHUB_WORKSPACE/
73+
- uses: actions/upload-artifact@v4
74+
with:
75+
name: linux-armhf-${"${{ env.REPO_NAME }}"}
76+
path: ${"${{ github.workspace }}"}/${"${{ env.REPO_NAME }}"}.zip
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env bash
2+
3+
## Set STAGING
4+
USE_STAGING=OFF
5+
6+
echo "Navigating to the package generator directory..."
7+
cd /home/docker/scopy/scopy/tools/packagegenerator
8+
9+
echo "Installing Python dependencies..."
10+
pip3 install -r requirements.txt
11+
12+
echo "Testing the package generator script..."
13+
python3 ./package_generator.py -h
14+
15+
echo "Creating package directory for the repository..."
16+
mkdir -p /home/docker/scopy/scopy/packages/$GITHUB_REPOSITORY
17+
18+
echo "Copying package files to the repository directory..."
19+
cp -r /home/docker/scopy/package/* /home/docker/scopy/scopy/packages/$GITHUB_REPOSITORY/
20+
21+
echo "Building scopy.."
22+
cd /home/docker/scopy/scopy
23+
24+
echo "Creating and navigating to the build directory..."
25+
mkdir -p build && cd build
26+
27+
source /home/docker/scopy/scopy/ci/windows/mingw_toolchain.sh $USE_STAGING
28+
29+
$CMAKE .. $RC_COMPILER_OPT -DPYTHON_EXECUTABLE=$STAGING_DIR/bin/python3.exe -DENABLE_TESTING=OFF
30+
$MAKE_BIN $JOBS
31+
32+
echo "Returning to the package generator directory..."
33+
cd /home/docker/scopy/scopy/tools/packagegenerator
34+
35+
echo "Running the package generator script to create the final artifact..."
36+
$STAGING_DIR/bin/python3.exe ./package_generator.py -a --src=/home/docker/scopy/scopy/build/packages/$GITHUB_REPOSITORY --dest=/home/docker/artifact_x86_64
37+
38+
echo "Build and packaging process completed successfully!"
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
variables:
2+
QT_FORMULAE: qt@5
3+
REPO_SLUG: $(Build.Repository.Name)
4+
CURRENT_COMMIT: $(Build.SourceVersion)
5+
6+
resources:
7+
repositories:
8+
- repository: scopy
9+
type: github
10+
endpoint: put_endpoint_here
11+
name: analogdevicesinc/scopy
12+
ref: pkg-man-test
13+
14+
trigger:
15+
branches:
16+
include:
17+
- main
18+
tags:
19+
include:
20+
- v*
21+
22+
pr:
23+
branches:
24+
include:
25+
- main
26+
27+
stages:
28+
- stage: Builds
29+
jobs:
30+
- job: macOSBuilds
31+
strategy:
32+
matrix:
33+
macOS_13:
34+
vmImage: 'macOS-13'
35+
artifactName: 'macOS-13'
36+
macOS_14:
37+
vmImage: 'macOS-14'
38+
artifactName: 'macOS-14'
39+
macOS_15:
40+
vmImage: 'macOS-15'
41+
artifactName: 'macOS-15'
42+
43+
pool:
44+
vmImage: $[ variables['vmImage'] ]
45+
steps:
46+
- checkout: self
47+
path: package
48+
fetchDepth: 0
49+
clean: true
50+
- checkout: scopy
51+
path: scopy
52+
fetchDepth: 0
53+
clean: true
54+
- script: |
55+
PKG_NAME=$(echo $(Build.Repository.Name) | awk -F "/" '{print $2}')
56+
echo "##vso[task.setvariable variable=PKG_NAME]$PKG_NAME"
57+
displayName: 'Extract Repository Name'
58+
- script: |
59+
mkdir -p scopy/packages/$(PKG_NAME)
60+
cp -r package/* scopy/packages/$(PKG_NAME)/
61+
echo "ls scopy/packages"
62+
ls scopy/packages
63+
echo "ls scopy/packages/$(PKG_NAME)"
64+
ls scopy/packages/$(PKG_NAME)/
65+
displayName: 'Copy $(PKG_NAME) to Scopy'
66+
workingDirectory: $(Build.Repository.LocalPath)/..
67+
- script: ./ci/macOS/install_macos_deps.sh
68+
displayName: 'Build and Install Dependencies'
69+
workingDirectory: $(Build.Repository.LocalPath)/../scopy
70+
- script: |
71+
pip3 install -r requirements.txt
72+
python3 ./package_generator.py -h
73+
displayName: 'Check package generator and install dependencies'
74+
workingDirectory: $(Build.Repository.LocalPath)/../scopy/tools/packagegenerator
75+
- script: |
76+
export BUILD_HOST="$(vmImage)"
77+
export ACCOUNT_NAME=`echo $[ resources.repositories.scopy.name ] | awk -F "/" '{print $1}'`
78+
export PROJECT_NAME=`echo $[ resources.repositories.scopy.name ] | awk -F "/" '{print $2}'`
79+
export USERNAME="azure-pipelines"
80+
export BUILD_REPO_URL=$[ resources.repositories.scopy.url ]
81+
export RUN_ID=$(Build.BuildId)
82+
export RUN_NUMBER=$(Build.BuildNumber)
83+
export JOB_ID=$(System.JobId)
84+
export JOB_NAME=$(System.JobName)
85+
export RUNNER_ARCH=$(Agent.OSArchitecture)
86+
export MACOSX_DEPLOYMENT_TARGET=11.0
87+
./ci/macOS/build_azure_macos.sh
88+
displayName: 'Build Scopy'
89+
workingDirectory: $(Build.Repository.LocalPath)/../scopy
90+
- script: |
91+
ls -R build
92+
cp build/Scopy.app/Contents/MacOS/Users/runner/work/1/scopy/build/packages/$(PKG_NAME)/plugins/*.dylib build/packages/$(PKG_NAME)/plugins
93+
displayName: 'Copy plugin library to the package'
94+
workingDirectory: $(Build.Repository.LocalPath)/../scopy
95+
- script: |
96+
python3 ./package_generator.py -a --src=$(Build.Repository.LocalPath)/../scopy/build/packages/$(PKG_NAME) --dest=$(Build.ArtifactStagingDirectory)
97+
displayName: 'Create package zip'
98+
workingDirectory: $(Build.Repository.LocalPath)/../scopy/tools/packagegenerator
99+
- task: GithubRelease@1
100+
displayName: 'Push to continuous release'
101+
condition: and(succeeded(), and(ne(variables['Build.Reason'], 'PullRequest'), eq(variables['Build.SourceBranch'], 'refs/heads/master')))
102+
inputs:
103+
githubConnection: put_your_github_connection_here
104+
repositoryName: $(Build.Repository.Name)
105+
action: edit
106+
tag: continous
107+
assets: $(Build.ArtifactStagingDirectory)/*.zip
108+
assetUploadMode: replace
109+
isPreRelease: true
110+
addChangeLog: false
111+
- task: PublishPipelineArtifact@1
112+
displayName: 'Publish Package Artifact'
113+
inputs:
114+
targetPath: '$(Build.ArtifactStagingDirectory)'
115+
artifactName: '$(artifactName)'

0 commit comments

Comments
 (0)