This repository has been archived by the owner on Jun 29, 2018. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More comprehensive update script - Push to npm and GitHub Releases. R…
…eferences #69
- Loading branch information
Showing
2 changed files
with
73 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
$global:config = @{ | ||
github_user = 'Daniel15' | ||
github_repo = 'yarn-release-test' | ||
github_token = 'CHANGEME' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,17 @@ | ||
# Checks for updates to Babel. If a new version is available, upgrades the Babel references in | ||
# Checks for updates to Babel. If a new version is available, upgrades the Babel references in | ||
# package.json to the new version, commits the new package.json, and pushes it to Github. | ||
|
||
Set-StrictMode -Version Latest | ||
param( | ||
[switch] $Clean = $false | ||
) | ||
|
||
$ErrorActionPreference = "Stop"; | ||
Set-StrictMode -Version Latest | ||
|
||
. ./scripts/config.ps1 | ||
|
||
############################ | ||
|
||
|
||
# Formats JSON in a nicer format than the built-in ConvertTo-Json does. | ||
function Format-Json([Parameter(Mandatory, ValueFromPipeline)][String] $json) { | ||
|
@@ -23,10 +33,10 @@ function Format-Json([Parameter(Mandatory, ValueFromPipeline)][String] $json) { | |
|
||
# Gets the latest version of a dependency from package.json | ||
function Get-LatestDependencyVersion( | ||
[Parameter(Mandatory)] [PSCustomObject] $package, | ||
[Parameter(Mandatory)] [PSCustomObject] $package, | ||
[Parameter(Mandatory)] [String] $filter | ||
) { | ||
$relevant_packages = $package.devDependencies.PSObject.Members | | ||
$relevant_packages = $package.devDependencies.PSObject.Members | | ||
Where-Object { $_.MemberType -eq 'NoteProperty' -and $_.Name -match $filter} | ||
$latest_version = ([Version] $relevant_packages[0].Value) | ||
|
||
|
@@ -42,7 +52,7 @@ function Get-LatestDependencyVersion( | |
|
||
# Sets the version number in package.json | ||
function Set-PackageVersion( | ||
[Parameter(Mandatory)] [PSCustomObject] $Package, | ||
[Parameter(Mandatory)] [PSCustomObject] $Package, | ||
[Parameter(Mandatory)] [String] $Version | ||
) { | ||
Write-Output 'Updating version in package.json' | ||
|
@@ -56,7 +66,45 @@ function Assert-LastExitCode { | |
throw 'Non-zero exit code encountered' | ||
} | ||
} | ||
|
||
|
||
function New-GitHubRelease( | ||
[Parameter(Mandatory)] [String] $Version | ||
) { | ||
Invoke-RestMethod ` | ||
-Uri ('https://api.github.com/repos/{0}/{1}/releases?access_token={2}' -f $global:config.github_user, $global:config.github_repo, $global:config.github_token) ` | ||
-Method Post ` | ||
-Body (@{ | ||
body = 'Automated upgrade to Babel ' + $version | ||
draft = $false | ||
name = $version | ||
tag_name = 'v' + $version | ||
} | ConvertTo-Json) | ||
} | ||
|
||
function Add-GitHubReleaseAsset( | ||
[Parameter(Mandatory)] [PSCustomObject] $Release, | ||
[Parameter(Mandatory)] [String] $Path | ||
) { | ||
$filename = Split-Path -Path $Path -Leaf | ||
$upload_url = $release.upload_url -replace '{.+', '' | ||
Invoke-WebRequest ` | ||
-Uri ('{0}?name={1}&access_token={2}' -f $upload_url, $filename, $global:config.github_token) ` | ||
-Method Post ` | ||
-ContentType 'text/javascript' ` | ||
-Body (Get-Content -Path $Path -Raw) | Out-Null | ||
|
||
Write-Output ('Uploaded ' + $filename) | ||
} | ||
|
||
############################ | ||
|
||
if ($Clean) { | ||
Write-Output "Cleaning working directory" | ||
git reset --hard HEAD | ||
git clean -fd | ||
git pull | ||
} | ||
|
||
.\node_modules\.bin\npm-check-updates -a; Assert-LastExitCode | ||
|
||
$package_json = Get-Content -Path package.json | ConvertFrom-Json | ||
|
@@ -69,7 +117,7 @@ if (([Version]$package_json.version) -ge $babel_version) { | |
Write-Output ('Current version is {0}, latest Babel version is {1}' -f $package_json.version, $babel_version) | ||
|
||
npm install; Assert-LastExitCode | ||
|
||
Write-Output 'Building and running tests' | ||
npm run build; Assert-LastExitCode | ||
npm run test; Assert-LastExitCode | ||
|
@@ -78,6 +126,19 @@ Write-Output 'Build looks okay, committing and pushing changes' | |
Set-PackageVersion -Package $package_json -Version $babel_version | ||
git commit -m ('Upgrade to Babel {0}' -f $babel_version) --author='DanBuild <[email protected]>' package.json; Assert-LastExitCode | ||
git tag -a ('release-' + $babel_version) -m ('Automated upgrade to Babel {0}' -f $babel_version); Assert-LastExitCode | ||
|
||
# Push to Github | ||
git push origin master --follow-tags; Assert-LastExitCode | ||
|
||
# Push to npm | ||
npm publish | ||
|
||
# Push to GitHub releases | ||
Write-Output "Creating GitHub release..." | ||
$release = New-GitHubRelease -Version $babel_version | ||
Add-GitHubReleaseAsset -Release $release -Path ./babel.js | ||
Add-GitHubReleaseAsset -Release $release -Path ./babel.min.js | ||
Add-GitHubReleaseAsset -Release $release -Path ./packages/babili-standalone/babili.js | ||
Add-GitHubReleaseAsset -Release $release -Path ./packages/babili-standalone/babili.min.js | ||
|
||
Write-Output 'DONE!' |