Skip to content

Commit 0b11963

Browse files
committed
Extract building Windows Package to reusable workflow
1 parent a38f678 commit 0b11963

File tree

3 files changed

+133
-98
lines changed

3 files changed

+133
-98
lines changed

.github/actions/windows/prepare-build/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ runs:
4141
- name: Enable Developer Command Prompt
4242
uses: ilammy/msvc-dev-cmd@v1
4343
with:
44-
arch: ${{ matrix.arch }}
44+
arch: ${{ inputs.arch }}
4545
toolset: ${{ steps.setup-php.outputs.toolset }}
4646

4747
- name: phpize
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
name: "Build Windows Package"
2+
run-name: "Build Windows Package for ${{ inputs.ref }} (PHP ${{ inputs.php }} ${{ inputs.arch }} ${{ inputs.ts }})"
3+
4+
on:
5+
workflow_call:
6+
inputs:
7+
version:
8+
description: "The version being built"
9+
type: string
10+
required: true
11+
ref:
12+
description: "The git reference to build"
13+
type: string
14+
required: true
15+
php:
16+
description: "The PHP version to build for"
17+
type: string
18+
required: true
19+
arch:
20+
description: "The architecture to build for (x64 or x86)"
21+
type: string
22+
required: true
23+
ts:
24+
description: "Thread safety (ts or nts)"
25+
type: string
26+
required: true
27+
upload_release_asset:
28+
description: "Whether to upload a release asset"
29+
type: boolean
30+
default: false
31+
32+
jobs:
33+
build:
34+
name: "Build DLL"
35+
# windows-latest is required to use enableCrossOsArchive with Ubuntu in the
36+
# next step. See https://github.com/actions/cache/blob/main/tips-and-workarounds.md#cross-os-cache
37+
runs-on: windows-latest
38+
defaults:
39+
run:
40+
shell: cmd
41+
42+
steps:
43+
- uses: actions/checkout@v4
44+
with:
45+
submodules: true
46+
ref: ${{ inputs.ref }}
47+
48+
- name: "Build Driver"
49+
id: build-driver
50+
uses: ./.github/actions/windows/build
51+
with:
52+
version: ${{ inputs.php }}
53+
arch: ${{ inputs.arch }}
54+
ts: ${{ inputs.ts }}
55+
56+
- name: "Copy DLL and PDB files to CWD"
57+
run: |
58+
cp %BUILD_DIR%\php_mongodb.dll .
59+
cp %BUILD_DIR%\php_mongodb.pdb .
60+
env:
61+
BUILD_DIR: ${{ steps.build-driver.outputs.build-dir }}
62+
63+
- name: "Cache build artifacts for subsequent builds"
64+
uses: actions/cache/save@v4
65+
with:
66+
key: ${{ github.sha }}-${{ inputs.php }}-${{ inputs.ts }}-${{ inputs.arch }}
67+
enableCrossOsArchive: true
68+
path: |
69+
php_mongodb.dll
70+
php_mongodb.pdb
71+
72+
sign-and-package:
73+
environment: release
74+
name: "Sign and create package"
75+
needs: [build]
76+
# ubuntu-latest is required to use enableCrossOsArchive
77+
# See https://github.com/actions/cache/blob/main/tips-and-workarounds.md#cross-os-cache
78+
runs-on: "ubuntu-latest"
79+
permissions:
80+
id-token: write
81+
82+
steps:
83+
- name: "Generate token and checkout repository"
84+
uses: mongodb-labs/drivers-github-tools/secure-checkout@v2
85+
with:
86+
app_id: ${{ vars.APP_ID }}
87+
private_key: ${{ secrets.APP_PRIVATE_KEY }}
88+
ref: ${{ inputs.ref }}
89+
90+
- name: "Set up drivers-github-tools"
91+
uses: mongodb-labs/drivers-github-tools/setup@v2
92+
with:
93+
aws_role_arn: ${{ secrets.AWS_ROLE_ARN }}
94+
aws_region_name: ${{ vars.AWS_REGION_NAME }}
95+
aws_secret_id: ${{ secrets.AWS_SECRET_ID }}
96+
97+
- name: Restore cached build artifacts
98+
id: cache-build-artifacts
99+
uses: actions/cache/restore@v4
100+
with:
101+
fail-on-cache-miss: true
102+
key: ${{ github.sha }}-${{ inputs.php }}-${{ inputs.ts }}-${{ inputs.arch }}
103+
enableCrossOsArchive: true
104+
path: |
105+
php_mongodb.dll
106+
php_mongodb.pdb
107+
108+
- name: "Create detached DLL signature"
109+
uses: mongodb-labs/drivers-github-tools/gpg-sign@v2
110+
with:
111+
filenames: php_mongodb.dll
112+
113+
# Copy the signature file from the release asset directory to avoid directory issues in the ZIP file
114+
- name: "Copy signature file"
115+
run: cp ${RELEASE_ASSETS}/php_mongodb.dll.sig .
116+
117+
- name: "Create and upload release asset"
118+
if: ${{ inputs.upload_release_asset }}
119+
run: |
120+
ARCHIVE=php_mongodb-${{ inputs.version }}-${{ inputs.php }}-${{ inputs.ts }}-${{ inputs.arch }}.zip
121+
zip ${ARCHIVE} php_mongodb.dll php_mongodb.dll.sig php_mongodb.pdb CREDITS CONTRIBUTING.md LICENSE README.md THIRD_PARTY_NOTICES
122+
gh release upload ${{ inputs.version }} ${ARCHIVE}

.github/workflows/package-release.yml

Lines changed: 10 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -84,107 +84,20 @@ jobs:
8484
run: gh release upload ${{ inputs.version }} ${{ env.PACKAGE_FILE }} ${{ env.PACKAGE_FILE }}.sig
8585

8686
build-windows:
87-
name: "Create Windows package"
88-
# windows-latest is required to use enableCrossOsArchive with Ubuntu in the
89-
# next step. See https://github.com/actions/cache/blob/main/tips-and-workarounds.md#cross-os-cache
90-
runs-on: windows-latest
91-
defaults:
92-
run:
93-
shell: cmd
94-
95-
strategy:
96-
fail-fast: false
97-
matrix:
98-
# Note: keep this in sync with the Windows matrix in windows-tests.yml
99-
php: [ "7.4", "8.0", "8.1", "8.2", "8.3" ]
100-
arch: [ x64, x86 ]
101-
ts: [ ts, nts ]
102-
103-
steps:
104-
- uses: actions/checkout@v4
105-
with:
106-
submodules: true
107-
ref: ${{ inputs.ref }}
108-
109-
- name: "Build Driver"
110-
id: build-driver
111-
uses: ./.github/actions/windows/build
112-
with:
113-
version: ${{ matrix.php }}
114-
arch: ${{ matrix.arch }}
115-
ts: ${{ matrix.ts }}
116-
117-
- name: "Copy DLL and PDB files to CWD"
118-
run: |
119-
cp %BUILD_DIR%\php_mongodb.dll .
120-
cp %BUILD_DIR%\php_mongodb.pdb .
121-
env:
122-
BUILD_DIR: ${{ steps.build-driver.outputs.build-dir }}
123-
124-
- name: "Cache build artifacts for subsequent builds"
125-
uses: actions/cache/save@v4
126-
with:
127-
key: ${{ github.sha }}-${{ matrix.php }}-${{ matrix.ts }}-${{ matrix.arch }}
128-
enableCrossOsArchive: true
129-
path: |
130-
php_mongodb.dll
131-
php_mongodb.pdb
132-
133-
sign-and-publish-windows:
134-
environment: release
135-
name: "Sign and Publish Windows package"
136-
needs: [build-windows]
137-
# ubuntu-latest is required to use enableCrossOsArchive
138-
# See https://github.com/actions/cache/blob/main/tips-and-workarounds.md#cross-os-cache
139-
runs-on: "ubuntu-latest"
140-
permissions:
141-
id-token: write
142-
87+
name: "Create Windows packages"
88+
uses: ./.github/workflows/build-windows-package.yml
89+
with:
90+
version: ${{ inputs.version }}
91+
ref: refs/tags/${{ inputs.version }}
92+
php: ${{ matrix.php }}
93+
arch: ${{ matrix.arch }}
94+
ts: ${{ matrix.ts }}
95+
upload_release_asset: true
96+
secrets: inherit
14397
strategy:
14498
fail-fast: false
14599
matrix:
146100
# Note: keep this in sync with the Windows matrix in windows-tests.yml
147101
php: [ "7.4", "8.0", "8.1", "8.2", "8.3" ]
148102
arch: [ x64, x86 ]
149103
ts: [ ts, nts ]
150-
151-
steps:
152-
- name: "Generate token and checkout repository"
153-
uses: mongodb-labs/drivers-github-tools/secure-checkout@v2
154-
with:
155-
app_id: ${{ vars.APP_ID }}
156-
private_key: ${{ secrets.APP_PRIVATE_KEY }}
157-
ref: ${{ inputs.ref }}
158-
159-
- name: "Set up drivers-github-tools"
160-
uses: mongodb-labs/drivers-github-tools/setup@v2
161-
with:
162-
aws_role_arn: ${{ secrets.AWS_ROLE_ARN }}
163-
aws_region_name: ${{ vars.AWS_REGION_NAME }}
164-
aws_secret_id: ${{ secrets.AWS_SECRET_ID }}
165-
166-
- name: Restore cached build artifacts
167-
id: cache-build-artifacts
168-
uses: actions/cache/restore@v4
169-
with:
170-
fail-on-cache-miss: true
171-
key: ${{ github.sha }}-${{ matrix.php }}-${{ matrix.ts }}-${{ matrix.arch }}
172-
enableCrossOsArchive: true
173-
path: |
174-
php_mongodb.dll
175-
php_mongodb.pdb
176-
177-
- name: "Create detached DLL signature"
178-
uses: mongodb-labs/drivers-github-tools/gpg-sign@v2
179-
with:
180-
filenames: php_mongodb.dll
181-
182-
# Copy the signature file from the release asset directory to avoid directory issues in the ZIP file
183-
- name: "Copy signature file"
184-
run: cp ${RELEASE_ASSETS}/php_mongodb.dll.sig .
185-
186-
- name: "Create and upload release artifact"
187-
run: |
188-
ARCHIVE=php_mongodb-${{ inputs.version }}-${{ matrix.php }}-${{ matrix.ts }}-${{ matrix.arch }}.zip
189-
zip ${ARCHIVE} php_mongodb.dll php_mongodb.dll.sig php_mongodb.pdb CREDITS CONTRIBUTING.md LICENSE README.md THIRD_PARTY_NOTICES
190-
gh release upload ${{ inputs.version }} ${ARCHIVE}

0 commit comments

Comments
 (0)