Skip to content

Commit 391cb63

Browse files
authored
devops(pipeline): resolve Maven and npm packages from DevDiv_PublicPackages feed (#1971)
1 parent 3823986 commit 391cb63

4 files changed

Lines changed: 71 additions & 20 deletions

File tree

.azure-pipelines/publish.yml

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ extends:
4545
env:
4646
CURRENT_BRANCH: ${{ variables['Build.SourceBranchName'] }}
4747
displayName: "Check the branch is a release branch"
48+
# Allow manual runs on any branch to exercise the build without publishing.
49+
condition: ne(variables['Build.Reason'], 'Manual')
4850
4951
- bash: |
5052
echo "importing GPG key:"
@@ -56,16 +58,47 @@ extends:
5658
GPG_PRIVATE_KEY_BASE64: $(GPG_PRIVATE_KEY_BASE64) # secret variable has to be mapped to an env variable
5759
displayName: "Import gpg key"
5860
61+
- task: UseNode@1
62+
inputs:
63+
version: '26.x'
64+
displayName: "Install Node.js"
65+
66+
- task: Bash@3
67+
displayName: "setup .npmrc"
68+
inputs:
69+
targetType: "inline"
70+
script: |
71+
echo "registry=https://devdiv.pkgs.visualstudio.com/DevDiv/_packaging/DevDiv_PublicPackages/npm/registry/" >> .npmrc
72+
73+
- task: npmAuthenticate@0
74+
displayName: "authenticate the private npm registry"
75+
inputs:
76+
workingFile: .npmrc
77+
5978
- bash: ./scripts/download_driver.sh
6079
displayName: 'Download driver'
61-
80+
81+
# Must run before MavenAuthenticate@0 so the credentials it injects into
82+
# ~/.m2/settings.xml are not overwritten by the copy.
83+
- bash: |
84+
mkdir -p ~/.m2
85+
cp .azure-pipelines/settings.xml ~/.m2/settings.xml
86+
displayName: 'Copy settings.xml (mirror Maven Central to DevDiv_PublicPackages)'
87+
88+
- task: MavenAuthenticate@0
89+
displayName: 'Authenticate to DevDiv_PublicPackages feed'
90+
inputs:
91+
artifactsFeeds: DevDiv_PublicPackages
92+
6293
- bash: mvn -B deploy -D skipTests --no-transfer-progress --activate-profiles release -D gpg.passphrase=$GPG_PASSPHRASE -DaltDeploymentRepository=snapshot-repo::default::file:$(Build.ArtifactStagingDirectory)/esrp-build
6394
displayName: 'Build and deploy to a local directory'
6495
env:
6596
GPG_PASSPHRASE: $(GPG_PASSPHRASE) # secret variable has to be mapped to an env variable
6697

6798
- job: Publish
6899
dependsOn: Build
100+
# Only publish from release tags; manual runs stop after Build.
101+
condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/v1.'))
69102
templateContext:
70103
type: releaseJob
71104
isProduction: true

.azure-pipelines/settings.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Maven settings used only by the Azure Pipelines release build (publish.yml).
4+
5+
Routes all remote artifact and plugin resolution through the DevDiv_PublicPackages
6+
Azure Artifacts feed instead of Maven Central, as required by SFI-ES4.2.4.
7+
The mirror id must match the feed name passed to MavenAuthenticate@0, which
8+
injects matching <server> credentials into this file on the build agent.
9+
-->
10+
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
11+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
12+
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
13+
<mirrors>
14+
<mirror>
15+
<id>DevDiv_PublicPackages</id>
16+
<url>https://pkgs.dev.azure.com/devdiv/DevDiv/_packaging/DevDiv_PublicPackages/maven/v1</url>
17+
<mirrorOf>*</mirrorOf>
18+
</mirror>
19+
</mirrors>
20+
</settings>

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ target/
2121
.idea
2222
*.iml
2323

24+
.npmrc

scripts/download_driver.sh

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,36 +37,30 @@ download() {
3737
}
3838

3939
DRIVER_VERSION=$(head -1 ./DRIVER_VERSION)
40+
ROOT="$(cd .. && pwd)"
4041

41-
# Resolve the exact upstream commit that produced this driver version, so that the
42-
# bundled Node.js version matches the driver exactly.
43-
GIT_HEAD=$(npm view playwright@"$DRIVER_VERSION" gitHead)
44-
if [[ -z "$GIT_HEAD" ]]; then
45-
echo "Failed to resolve upstream commit (gitHead) for playwright@$DRIVER_VERSION"
46-
exit 1
47-
fi
42+
# All npm commands run from the repository root so that a root-level .npmrc (e.g. the one
43+
# the release pipeline writes to point at the internal Azure Artifacts feed) is honoured.
44+
# Locally, NPM_CONFIG_REGISTRY=<url> can be used to the same effect.
45+
npm_at_root() {
46+
(cd "$ROOT" && npm "$@")
47+
}
4848

4949
# The Node.js version used to be pinned in the upstream driver build script. The script was
50-
# removed in microsoft/playwright#41518, so for newer versions we follow the same policy it
51-
# had: the latest Node.js LTS (see upstream utils/build/update-playwright-node.mjs).
52-
NODE_VERSION=$(curl -fsSL "https://raw.githubusercontent.com/microsoft/playwright/$GIT_HEAD/utils/build/build-playwright-driver.sh" 2>/dev/null \
53-
| sed -n 's/^NODE_VERSION="\([^"]*\)".*/\1/p')
50+
# removed in microsoft/playwright#41518, so we follow the same policy it had: the latest
51+
# Node.js LTS (see upstream utils/build/update-playwright-node.mjs).
52+
NODE_VERSION=$(curl -fsSL "https://nodejs.org/dist/index.json" \
53+
| node -e "let s='';process.stdin.on('data',d=>s+=d).on('end',()=>console.log(JSON.parse(s).find(r=>r.lts).version.slice(1)))")
5454
if [[ -z "$NODE_VERSION" ]]; then
55-
NODE_VERSION=$(curl -fsSL "https://nodejs.org/dist/index.json" \
56-
| node -e "let s='';process.stdin.on('data',d=>s+=d).on('end',()=>console.log(JSON.parse(s).find(r=>r.lts).version.slice(1)))")
57-
fi
58-
if [[ -z "$NODE_VERSION" ]]; then
59-
echo "Failed to determine Node.js version for playwright@$DRIVER_VERSION ($GIT_HEAD)"
55+
echo "Failed to determine the latest Node.js LTS version"
6056
exit 1
6157
fi
6258

6359
echo "Driver version: $DRIVER_VERSION"
64-
echo "Upstream commit: $GIT_HEAD"
6560
echo "Node.js version: $NODE_VERSION"
6661

6762
# The platform-independent driver code (playwright-core) is assembled once into the driver module;
6863
# the Node.js binary for each platform is assembled into the driver-bundle module. See issue #1196.
69-
ROOT="$(cd .. && pwd)"
7064
CORE_DEST="$ROOT/driver/src/main/resources/driver"
7165
NODE_DEST="$ROOT/driver-bundle/src/main/resources/driver"
7266

@@ -77,8 +71,11 @@ trap 'rm -rf "$TMP_DIR"' EXIT
7771
echo "Assembling playwright-core package to $CORE_DEST/package"
7872
rm -rf "$CORE_DEST/package"
7973
mkdir -p "$CORE_DEST"
74+
# Fetched via npm rather than a hard-coded registry URL so that the configured registry
75+
# (and its credentials) are used.
8076
CORE_TGZ="$TMP_DIR/playwright-core-$DRIVER_VERSION.tgz"
81-
download "https://registry.npmjs.org/playwright-core/-/playwright-core-$DRIVER_VERSION.tgz" "$CORE_TGZ"
77+
echo "Downloading playwright-core@$DRIVER_VERSION from $(npm_at_root config get registry)"
78+
npm_at_root pack "playwright-core@$DRIVER_VERSION" --pack-destination "$TMP_DIR" --silent > /dev/null
8279
# The npm tarball has a top-level package/ directory, so this creates $CORE_DEST/package.
8380
tar -xzf "$CORE_TGZ" -C "$CORE_DEST"
8481
rm -f "$CORE_TGZ"

0 commit comments

Comments
 (0)