forked from microsoftgraph/msgraph-sdk-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBumpCoreLibraryVersion.php
More file actions
52 lines (40 loc) · 1.88 KB
/
Copy pathBumpCoreLibraryVersion.php
File metadata and controls
52 lines (40 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/**
* Copyright (c) Microsoft Corporation. All Rights Reserved.
* Licensed under the MIT License. See License in the project root
* for license information.
*
* Updates this package's dependency to always use the latest version of https://packagist.org/packages/microsoft/microsoft-graph-core
*/
require_once 'PackagistUtils.php';
const COMPOSER_JSON_PATH = "./composer.json";
const PACKAGE_NAME = "microsoft-graph-core";
const COMPOSER_JSON_CORE_REGEX = '#"microsoft/'. PACKAGE_NAME . '"\s*:\s*"(.+)"#';
$composerJsonContents = file_get_contents(COMPOSER_JSON_PATH);
if (!$composerJsonContents) {
throw new \Exception("Could not read composer.json at: ".COMPOSER_JSON_PATH);
}
$matches = [];
if (!preg_match(COMPOSER_JSON_CORE_REGEX, $composerJsonContents, $matches)) {
throw new \Exception("Could not find Core Library dependency in composer.json using regex: ".COMPOSER_JSON_CORE_REGEX);
}
$currentCoreVersion = $matches[1];
$currentCoreVersion = ($currentCoreVersion[0] === "^") ? substr($currentCoreVersion, 1) : $currentCoreVersion;
echo "CurrentCoreVersion: {$currentCoreVersion}.";
// $latestCoreVersion = getLatestPackagistVersion(PACKAGE_NAME);
$latestCoreVersion = "2.2.1-preview";
echo "Latest core version: {$latestCoreVersion}.";
if (!$latestCoreVersion) {
exit("No non-branch version of the Core Library is available on Packagist");
}
$replacement = sprintf("\"microsoft/%s\": \"^{$latestCoreVersion}\"", PACKAGE_NAME);
if (!file_put_contents(
COMPOSER_JSON_PATH,
preg_replace(COMPOSER_JSON_CORE_REGEX, $replacement, $composerJsonContents))) {
throw new \Exception("Unable to overwrite Core library version in composer.json");
}
// output informs GitHub Action whether to bump minor SDK version or bump major SDK version
if (intval($latestCoreVersion[0]) > intval($currentCoreVersion[0])) {
exit("MAJOR_REV_SDK_VERSION");
}
exit("MINOR_REV_SDK_VERSION");