Skip to content

Commit

Permalink
Add option to force using 32 bit cmake (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwlawson authored May 8, 2021
1 parent 8a432c4 commit 710e055
Show file tree
Hide file tree
Showing 11 changed files with 683 additions and 338 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/windows-32bit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
on:
push:
branches: [master]
pull_request:
branches: [master]


jobs:
check-win32:
runs-on: ${{ matrix.os }}
name: Check action on 32bit windows
strategy:
fail-fast: false
matrix:
os: [windows-latest]
cmake_ver: ['', '3.19.3', '3.15.1', '2.8']

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup cmake
uses: ./
id: setup
with:
cmake-version: ${{ matrix.cmake_ver }}
use-32bit: 'true'

- name: Run cmake --version
shell: bash
run: |
VERSION=`cmake --version`
echo $VERSION
[[ "$VERSION" =~ "${{ matrix.cmake_ver }}" ]]
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Setup cmake
uses: jwlawson/actions-setup-cmake@v1.8
uses: jwlawson/actions-setup-cmake@v1.9
with:
cmake-version: '3.16.x'
- name: Use cmake
Expand All @@ -25,7 +25,7 @@ jobs:
### Options
There are two options for the action:
There are three options for the action:
* `cmake-version` controls the version of CMake that is added to the path. This
can be a fully specified verison `3.3.0`, partly specified `3.2`, a wildcard
Expand All @@ -44,6 +44,12 @@ There are two options for the action:
- [GitHub API rate limiting]
- [GITHUB_TOKEN]

* `use-32bit' forces the use of a 32 bit binary, instead of first looking for a
64 bit binary. Note that more recent releases of cmake only have 32 bit
packages for windows and not for linux or macos, so this option may cause
failures in those cases.

Possible values are 'true' or 'false'. The default is 'false'.

### How it works

Expand Down
108 changes: 102 additions & 6 deletions __tests__/setup-cmake.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('When adding tool to cache', () => {
.get('/cmake-win32-x86_64.zip')
.replyWithFile(200, path.join(dataPath, 'empty.zip'));

await setup.addCMakeToToolCache(required_version);
await setup.addCMakeToToolCache(required_version, ['x86_64']);
expect(darwin_nock.isDone()).toBe(darwin);
expect(linux_nock.isDone()).toBe(linux);
expect(windows_nock.isDone()).toBe(windows);
Expand Down Expand Up @@ -147,7 +147,7 @@ describe('When using version 3.19.2 on macos', () => {
const archive_nock = nock('https://fakeaddress.com')
.get('/cmake-3.19.2-macos-universal.tar.gz')
.replyWithFile(200, path.join(dataPath, 'empty.tar.gz'));
await setup.addCMakeToToolCache(macos_version);
await setup.addCMakeToToolCache(macos_version, ['x86_64']);
expect(package_nock.isDone()).toBe(false);
expect(archive_nock.isDone()).toBe(true);
Object.defineProperty(process, 'platform', {
Expand Down Expand Up @@ -213,7 +213,7 @@ describe('When using version 2.8', () => {
const darwin64_nock = nock('https://fakeaddress.com')
.get('/cmake-2.8.12.2-Darwin64-universal.tar.gz')
.replyWithFile(200, path.join(dataPath, 'empty.tar.gz'));
await setup.addCMakeToToolCache(version);
await setup.addCMakeToToolCache(version, ['x86_64', 'x86']);
expect(darwin_nock.isDone()).toBe(false);
expect(darwin64_nock.isDone()).toBe(true);
Object.defineProperty(process, 'platform', {
Expand All @@ -231,7 +231,7 @@ describe('When using version 2.8', () => {
.get('/cmake-2.8.12.2-Linux-i386.tar.gz')
.replyWithFile(200, path.join(dataPath, 'empty.tar.gz'));

await setup.addCMakeToToolCache(version);
await setup.addCMakeToToolCache(version, ['x86_64', 'x86']);
expect(linux_nock.isDone()).toBe(true);
Object.defineProperty(process, 'platform', {
value: orig_platform,
Expand Down Expand Up @@ -300,7 +300,7 @@ describe('Using version 3.19.3', () => {
const aarch64_nock = nock('https://fakeaddress.com')
.get('/cmake-3.19.3-Linux-aarch64.tar.gz')
.replyWithFile(200, path.join(dataPath, 'empty.tar.gz'));
await setup.addCMakeToToolCache(version);
await setup.addCMakeToToolCache(version, ['x86_64']);
expect(x86_nock.isDone()).toBe(true);
expect(aarch64_nock.isDone()).toBe(false);
Object.defineProperty(process, 'platform', {
Expand All @@ -320,11 +320,107 @@ describe('Using version 3.19.3', () => {
const second_nock = nock('https://fakeaddress.com')
.get('/cmake-3.19.3-macos10.10-universal.tar.gz')
.replyWithFile(200, path.join(dataPath, 'empty.tar.gz'));
await setup.addCMakeToToolCache(version);
await setup.addCMakeToToolCache(version, ['x86_64']);
expect(first_nock.isDone()).toBe(true);
expect(second_nock.isDone()).toBe(false);
Object.defineProperty(process, 'platform', {
value: orig_platform,
});
});
});

describe('Using a version with both x86_64 and x86 binaries', () => {
const version: vi.VersionInfo = {
name: '3.20.2',
assets: [
{
name: 'cmake-3.20.2-windows-i386.msi',
platform: 'win32',
arch: 'x86',
filetype: 'package',
url: 'https://url.test/cmake-3.20.2-windows-i386.msi',
},
{
name: 'cmake-3.20.2-windows-i386.zip',
platform: 'win32',
arch: 'x86',
filetype: 'archive',
url: 'https://url.test/cmake-3.20.2-windows-i386.zip',
},
{
name: 'cmake-3.20.2-windows-x86_64.msi',
platform: 'win32',
arch: 'x86_64',
filetype: 'package',
url: 'https://url.test/cmake-3.20.2-windows-x86_64.msi',
},
{
name: 'cmake-3.20.2-windows-x86_64.zip',
platform: 'win32',
arch: 'x86_64',
filetype: 'archive',
url: 'https://url.test/cmake-3.20.2-windows-x86_64.zip',
},
],
url: '',
draft: false,
prerelease: false,
};

beforeEach(() => {
nock.disableNetConnect();
});

afterEach(() => {
nock.cleanAll();
nock.enableNetConnect();
});

it('downloads the 32 bit package when requested', async () => {
const orig_platform: string = process.platform;
Object.defineProperty(process, 'platform', {
value: 'win32',
});
expect(process.platform).toBe('win32');
const x86_nock = nock('https://url.test')
.get('/cmake-3.20.2-windows-i386.zip')
.replyWithFile(200, path.join(dataPath, 'empty.zip'));
await setup.addCMakeToToolCache(version, ['x86']);
expect(x86_nock.isDone()).toBe(true);
Object.defineProperty(process, 'platform', {
value: orig_platform,
});
});

it('downloads the 64 bit package when requested', async () => {
const orig_platform: string = process.platform;
Object.defineProperty(process, 'platform', {
value: 'win32',
});
expect(process.platform).toBe('win32');
const x86_nock = nock('https://url.test')
.get('/cmake-3.20.2-windows-x86_64.zip')
.replyWithFile(200, path.join(dataPath, 'empty.zip'));
await setup.addCMakeToToolCache(version, ['x86_64']);
expect(x86_nock.isDone()).toBe(true);
Object.defineProperty(process, 'platform', {
value: orig_platform,
});
});

it('falls back to 64 bit package when both requested', async () => {
const orig_platform: string = process.platform;
Object.defineProperty(process, 'platform', {
value: 'win32',
});
expect(process.platform).toBe('win32');
const x86_nock = nock('https://url.test')
.get('/cmake-3.20.2-windows-x86_64.zip')
.replyWithFile(200, path.join(dataPath, 'empty.zip'));
await setup.addCMakeToToolCache(version, ['x86_64', 'x86']);
expect(x86_nock.isDone()).toBe(true);
Object.defineProperty(process, 'platform', {
value: orig_platform,
});
});
});
72 changes: 72 additions & 0 deletions __tests__/version.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,3 +383,75 @@ describe('When using the 3.20 release', () => {
});
});
});

describe('When using the 3.19 windows release with both 32 and 64 bit archives', () => {
// The windows releases before 3.20 had different platform naming for 32 and 64 bit archives
// cmake-3.19.8-win32-x86.zip and cmake-3.19.8-win64-x64.zip
const releases = [
{
tag_name: 'v3.19.0',
assets: [
{
name: 'cmake-3.19.0-win32-x86.zip',
browser_download_url: 'https://url.test/cmake-3.19.0-win32-x86.zip',
},
{
name: 'cmake-3.19.0-win64-x64.zip',
browser_download_url: 'https://url.test/cmake-3.19.0-win64-x64.zip',
},
],
},
];

beforeEach(() => {
nock.disableNetConnect();
nock('https://api.github.com')
.get('/repos/Kitware/CMake/releases')
.reply(200, releases);
nock('https://api.github.com')
.get('/repos/Kitware/CMake/releases')
.query({ page: 2 })
.reply(200, []);
});

afterEach(() => {
nock.cleanAll();
nock.enableNetConnect();
});

it('correctly parses the 32 bit archive', async () => {
const version_info = await version.getAllVersionInfo();
const selected = version.getLatestMatching('3.x', version_info);
const assets = selected.assets.filter(
(a) =>
a.platform === 'win32' && a.filetype === 'archive' && a.arch === 'x86'
);
expect(assets.length).toBe(1);
expect(assets[0]).toEqual({
name: 'cmake-3.19.0-win32-x86.zip',
platform: 'win32',
arch: 'x86',
filetype: 'archive',
url: 'https://url.test/cmake-3.19.0-win32-x86.zip',
});
});

it('correctly parses the 64 bit archive', async () => {
const version_info = await version.getAllVersionInfo();
const selected = version.getLatestMatching('3.x', version_info);
const assets = selected.assets.filter(
(a) =>
a.platform === 'win32' &&
a.filetype === 'archive' &&
a.arch === 'x86_64'
);
expect(assets.length).toBe(1);
expect(assets[0]).toEqual({
name: 'cmake-3.19.0-win64-x64.zip',
platform: 'win32',
arch: 'x86_64',
filetype: 'archive',
url: 'https://url.test/cmake-3.19.0-win64-x64.zip',
});
});
});
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ inputs:
github-api-token:
description: 'GitHub token to use when retrieving version info'
default: '${{ github.token }}'
use-32bit:
description: 'Force using 32 bit version of cmake, instead of looking for 64 bit version'
default: 'false'
runs:
using: 'node12'
main: 'dist/index.js'
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

Loading

0 comments on commit 710e055

Please sign in to comment.