Skip to content

Commit

Permalink
Stable extension builds using pet from Azure Feed (microsoft#24063)
Browse files Browse the repository at this point in the history
  • Loading branch information
karthiknadig authored Sep 6, 2024
1 parent 223eca9 commit 34dac5c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 94 deletions.
45 changes: 24 additions & 21 deletions build/azure-pipeline.stable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,27 +92,30 @@ extends:
- script: npx gulp prePublishBundle
displayName: Build

- script: nox --session azure_pet_checkout
displayName: Checkout python-environment-tools
env:
PYTHON_ENV_TOOLS_DEST: $(Build.SourcesDirectory)
PYTHON_ENV_TOOLS_REF: release/2024.14
PYTHON_ENV_TOOLS_TEMP: $(Agent.TempDirectory)

- script: nox --session azure_pet_build_before
displayName: Enable cargo config for azure

- template: azure-pipelines/extension/templates/steps/build-extension-rust-package.yml@templates
parameters:
vsceTarget: $(vsceTarget)
binaryName: pet
signing: true
workingDirectory: $(Build.SourcesDirectory)/python-env-tools
buildWasm: false
runTest: false

- script: nox --session azure_pet_build_after
displayName: Move bin to final location
- bash: |
mkdir -p $(Build.SourcesDirectory)/python-env-tools/bin
chmod +x $(Build.SourcesDirectory)/python-env-tools/bin
displayName: Make Directory for python-env-tool binary
- task: DownloadPipelineArtifact@2
inputs:
buildType: 'specific'
project: 'Monaco'
definition: 593
buildVersionToDownload: 'latestFromBranch'
branchName: 'refs/heads/release/2024.14'
targetPath: '$(Build.SourcesDirectory)/python-env-tools/bin'
artifactName: 'bin-$(vsceTarget)'
itemPattern: |
pet.exe
pet
ThirdPartyNotices.txt
- bash: |
ls -lf ./python-env-tools/bin
chmod +x ./python-env-tools/bin/pet*
ls -lf ./python-env-tools/bin
displayName: Set chmod for pet binary
- script: python -c "import shutil; shutil.rmtree('.nox', ignore_errors=True)"
displayName: Clean up Nox
Expand Down
74 changes: 1 addition & 73 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def delete_dir(path: pathlib.Path, ignore_errors=None):

shutil.rmtree(os.fspath(path))


@nox.session()
def install_python_libs(session: nox.Session):
requirements = [
Expand Down Expand Up @@ -63,79 +64,6 @@ def install_python_libs(session: nox.Session):
if pathlib.Path("./python_files/lib/temp").exists():
shutil.rmtree("./python_files/lib/temp")

@nox.session()
def azure_pet_checkout(session: nox.Session):
branch = os.getenv("PYTHON_ENV_TOOLS_REF", "main")

# dest dir should be <vscode-python repo root>/python-env-tools
dest_dir = (pathlib.Path(os.getenv("PYTHON_ENV_TOOLS_DEST")) / "python-env-tools").resolve()

# temp dir should be <agent temp dir>
temp_dir = (pathlib.Path(os.getenv("PYTHON_ENV_TOOLS_TEMP")) / "python-env-tools").resolve()
session.log(f"Cloning python-environment-tools to {temp_dir}")
temp_dir.mkdir(0o766, parents=True, exist_ok=True)

try:
with session.cd(temp_dir):
session.run("git", "init", external=True)
session.run(
"git",
"remote",
"add",
"origin",
"https://github.com/microsoft/python-environment-tools",
external=True,
)
session.run("git", "fetch", "origin", branch, external=True)
session.run(
"git", "checkout", "--force", "-B", branch, f"origin/{branch}", external=True
)
delete_dir(temp_dir / ".git")
delete_dir(temp_dir / ".github")
delete_dir(temp_dir / ".vscode")
(temp_dir / "CODE_OF_CONDUCT.md").unlink()
shutil.move(os.fspath(temp_dir), os.fspath(dest_dir))
except PermissionError as e:
print(f"Permission error: {e}")
if not dest_dir.exists():
raise
finally:
delete_dir(temp_dir, ignore_errors=True)


@nox.session()
def azure_pet_build_before(session: nox.Session):
source_dir = pathlib.Path(pathlib.Path.cwd() / "python-env-tools").resolve()
config_toml_disabled = source_dir / ".cargo" / "config.toml.disabled"
config_toml = source_dir / ".cargo" / "config.toml"
if config_toml_disabled.exists() and not config_toml.exists():
config_toml.write_bytes(config_toml_disabled.read_bytes())


@nox.session()
def azure_pet_build_after(session: nox.Session):
source_dir = pathlib.Path(pathlib.Path.cwd() / "python-env-tools").resolve()
ext = sysconfig.get_config_var("EXE") or ""
bin_name = f"pet{ext}"

abs_bin_path = None
for root, _, files in os.walk(os.fspath(source_dir / "target")):
bin_path = pathlib.Path(root) / "release" / bin_name
if bin_path.exists():
abs_bin_path = bin_path.absolute()
break

assert abs_bin_path

dest_dir = pathlib.Path(pathlib.Path.cwd() / "python-env-tools").resolve()
if not pathlib.Path(dest_dir / "bin").exists():
pathlib.Path(dest_dir / "bin").mkdir()
bin_dest = dest_dir / "bin" / bin_name
shutil.copyfile(abs_bin_path, bin_dest)

if sys.platform != "win32":
os.chmod(os.fspath(bin_dest), 0o755)


@nox.session()
def native_build(session: nox.Session):
Expand Down

0 comments on commit 34dac5c

Please sign in to comment.