Skip to content
This repository was archived by the owner on Jul 19, 2024. It is now read-only.

Commit 8cd2c2c

Browse files
Add scripts to handle PR flow
Logic to point to the last commit of branch being reviewed in PR
1 parent 1234382 commit 8cd2c2c

File tree

7 files changed

+75
-124
lines changed

7 files changed

+75
-124
lines changed

.travis.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
sudo: required
2+
3+
language: csharp
4+
dotnet: 2.1
5+
mono: none
6+
7+
services:
8+
- docker
9+
10+
dist: trusty
11+
addons:
12+
apt:
13+
sources:
14+
- sourceline: "deb [arch=amd64] https://packages.microsoft.com/ubuntu/14.04/prod trusty main"
15+
key_url: "https://packages.microsoft.com/keys/microsoft.asc"
16+
packages:
17+
- powershell
18+
19+
# The git clone command is needed because travis always performs git clone on a branch.
20+
# This makes it impossible to get all the branch and tag information needed without fully cloning.
21+
before_install:
22+
- chmod ugo+x ./scripts/setup_repo.sh && ./scripts/setup_repo.sh
23+
- sudo apt-get install -y powershell
24+
25+
install:
26+
- pwsh -f "./Install-Prerequisites.ps1"
27+
- docker pull gittools/gitversion:5.0.0-linux-debian-9-netcoreapp2.2
28+
- export GitVersion_Version=$(docker run --rm -v "$(pwd):/repo" gittools/gitversion:5.0.0-linux-debian-9-netcoreapp2.2 /repo -output json -showvariable majorminorpatch)
29+
30+
script:
31+
- pwsh -c "Invoke-Psake -buildFile Build.ps1 -taskList build,test"
32+
33+
stages:
34+
- name: deploy
35+
# require the branch name to be master (note for PRs this is the base branch name)
36+
if: branch = master and tag IS present
37+
- pwsh -c "Invoke-Psake -buildFile Build.ps1 -taskList build,test,publish"

Build.ps1

Lines changed: 5 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,3 @@
1-
# This is a PSake script that supports the following tasks:
2-
# clean, build, test and publish. The default task is build.
3-
#
4-
# The publish task uses the Publish-Module command to publish
5-
# to either the PowerShell Gallery (the default) or you can change
6-
# the $Repository property to the name of an alternate repository.
7-
#
8-
# The test task invokes Pester to run any Pester tests in your
9-
# workspace folder. Name your test scripts <TestName>.Tests.ps1
10-
# and Pester will find and run the tests contained in the files.
11-
#
12-
# You can run this build script directly using the invoke-psake
13-
# command which will execute the build task. This task "builds"
14-
# a temporary folder from which the module can be published.
15-
#
16-
# PS C:\> invoke-psake build.ps1
17-
#
18-
# You can run your Pester tests (if any) by running the following command.
19-
#
20-
# PS C:\> invoke-psake build.ps1 -taskList test
21-
#
22-
# You can execute the publish task with the following command. Note that
23-
# the publish task will run the test task first. The Pester tests must pass
24-
# before the publish task will run. The first time you run the publish
25-
# command, you will be prompted to enter your PowerShell Gallery NuGetApiKey.
26-
# After entering the key, it is encrypted and stored so you will not have to
27-
# enter it again.
28-
#
29-
# PS C:\> invoke-psake build.ps1 -taskList publish
30-
#
31-
# You can verify the stored and encrypted NuGetApiKey by running the following
32-
# command. This will display your NuGetApiKey in plain text!
33-
#
34-
# PS C:\> invoke-psake build.ps1 -taskList showKey
35-
#
36-
# You can store a new NuGetApiKey with this command. You can leave off
37-
# the -properties parameter and you'll be prompted for the key.
38-
#
39-
# PS C:\> invoke-psake build.ps1 -taskList storeKey -properties @{NuGetApiKey='test123'}
40-
#
411

422
###############################################################################
433
# Customize these properties for your module.
@@ -63,31 +23,21 @@ Properties {
6323
(Split-Path $PSCommandPath -Leaf)
6424
)
6525

66-
# Name of the repository you wish to publish to. Default repo is the PSGallery.
67-
$PublishRepository = $null
68-
69-
# Your NuGet API key for the PSGallery. Leave it as $null and the first time
70-
# you publish you will be prompted to enter your API key. The build will
71-
# store the key encrypted in a file, so that on subsequent publishes you
72-
# will no longer be prompted for the API key.
73-
$NuGetApiKey = $null
74-
$EncryptedApiKeyPath = "$env:LOCALAPPDATA\vscode-powershell\NuGetApiKey.clixml"
7526
}
7627

7728
###############################################################################
7829
# Customize these tasks for performing operations before and/or after publish.
7930
###############################################################################
8031
Task PrePublish {
8132
$functionDeclarations = @( Get-ChildItem -Path $PublishDir\Public\*.ps1 -ErrorAction SilentlyContinue )
82-
$functionNames = @()
33+
[string[]]$functionNames = @()
8334
foreach ($function in $functionDeclarations) {
8435
$functionNames += $function.BaseName
8536
}
86-
$functionsToExport = $functionNames -join ","
8737

8838
Update-ModuleManifest -Path $PublishDir\${ModuleName}.psd1 `
89-
-ModuleVersion "0.0.14" `
90-
-FunctionsToExport $functionsToExport
39+
-ModuleVersion "$env:GitVersion_Version" `
40+
-FunctionsToExport $functionNames
9141
}
9242

9343
Task PostPublish {
@@ -102,8 +52,8 @@ Task default -depends Build
10252
Task Publish -depends Test, PrePublish, PublishImpl, PostPublish {
10353
}
10454

105-
Task PublishImpl -depends Test -requiredVariables PublishDir, EncryptedApiKeyPath {
106-
$NuGetApiKey = Get-NuGetApiKey $NuGetApiKey $EncryptedApiKeyPath
55+
Task PublishImpl -depends Test -requiredVariables PublishDir {
56+
$NuGetApiKey = $env:PSGalleryAPIToken
10757

10858
$publishParams = @{
10959
Path = $PublishDir
@@ -148,58 +98,7 @@ Task Init -requiredVariables PublishDir {
14898
}
14999
}
150100

151-
Task StoreKey -requiredVariables EncryptedApiKeyPath {
152-
if (Test-Path $EncryptedApiKeyPath) {
153-
Remove-Item $EncryptedApiKeyPath
154-
}
155-
156-
$null = Get-NuGetApiKey $NuGetApiKey $EncryptedApiKeyPath
157-
"The NuGetApiKey has been stored in $EncryptedApiKeyPath"
158-
}
159-
160-
Task ShowKey -requiredVariables EncryptedApiKeyPath {
161-
$NuGetApiKey = Get-NuGetApiKey $NuGetApiKey $EncryptedApiKeyPath
162-
"The stored NuGetApiKey is: $NuGetApiKey"
163-
}
164-
165101
Task ? -description 'Lists the available tasks' {
166102
"Available tasks:"
167103
$psake.context.Peek().tasks.Keys | Sort
168104
}
169-
170-
###############################################################################
171-
# Helper functions
172-
###############################################################################
173-
function Get-NuGetApiKey($NuGetApiKey, $EncryptedApiKeyPath) {
174-
$storedKey = $null
175-
if (!$NuGetApiKey) {
176-
if (Test-Path $EncryptedApiKeyPath) {
177-
$storedKey = Import-Clixml $EncryptedApiKeyPath | ConvertTo-SecureString
178-
$cred = New-Object -TypeName PSCredential -ArgumentList 'kh',$storedKey
179-
$NuGetApiKey = $cred.GetNetworkCredential().Password
180-
Write-Verbose "Retrieved encrypted NuGetApiKey from $EncryptedApiKeyPath"
181-
}
182-
else {
183-
$apiKeySS = Read-Host -Prompt "Enter your NuGet API Key" -AsSecureString
184-
$cred = New-Object -TypeName PSCredential -ArgumentList 'dw',$apiKeySS
185-
$NuGetApiKey = $cred.GetNetworkCredential().Password
186-
}
187-
}
188-
189-
if (!$storedKey) {
190-
# Store encrypted NuGet API key to use for future invocations
191-
if (!$apiKeySS) {
192-
$apiKeySS = ConvertTo-SecureString -String $NuGetApiKey -AsPlainText -Force
193-
}
194-
195-
$parentDir = Split-Path $EncryptedApiKeyPath -Parent
196-
if (!(Test-Path -Path $parentDir)) {
197-
$null = New-Item -Path $parentDir -ItemType Directory
198-
}
199-
200-
$apiKeySS | ConvertFrom-SecureString | Export-Clixml $EncryptedApiKeyPath
201-
Write-Verbose "Stored encrypted NuGetApiKey to $EncryptedApiKeyPath"
202-
}
203-
204-
$NuGetApiKey
205-
}

GitVersion.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
mode: ContinuousDelivery
2+
branches: {}
3+
ignore:
4+
sha: []

Install-Prerequisites.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# The psake module is needed to run tests and publish the module to powershell gallery.
2+
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted
3+
Install-Module -Name psake -MinimumVersion 4.8.0 -Repository "PSGallery"
4+
Install-Module -Name pester -MinimumVersion 4.8.0 -Repository "PSGallery"
5+
6+

ReleaseNotes.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
Release Notes for v0.0.14
2-
====================================
1+
# Release Notes
2+
3+
## v0.1.0
4+
Initial version that supports making basic requests to Jenkins via the Remote API.
5+
Includes convenience functions to make and delete jobs.
36

4-
Really nothing special to note yet.

ThreeShape.Jenkins.psd1

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
22
# Module manifest for module 'ThreeShape.Jenkins'
33
#
4-
# Generated by: BAT
4+
# Generated by: 3Shape A/S
55
#
66
# Generated on: 03/05/2019
77
#
@@ -12,7 +12,7 @@
1212
RootModule = 'ThreeShape.Jenkins.psm1'
1313

1414
# Version number of this module.
15-
ModuleVersion = '0.0.14'
15+
ModuleVersion = '0.1.0'
1616

1717
# Supported PSEditions
1818
CompatiblePSEditions = 'Core'
@@ -27,10 +27,10 @@
2727
CompanyName = '3Shape'
2828

2929
# Copyright statement for this module
30-
Copyright = '(c) 2019 3Shape. All rights reserved.'
30+
Copyright = '(c) 2019 3Shape, licensed under the Apache 2.0 license.'
3131

3232
# Description of the functionality provided by this module
33-
Description = 'PowerShell module to work with Jenkins'
33+
Description = 'PowerShell module to interact with the Jenkins Remote Access API. The module aims to wrap the API endpoints and expose them in a way that should look and feel familiar to Powershell developers.'
3434

3535
# Minimum version of the Windows PowerShell engine required by this module
3636
PowerShellVersion = '6.0'
@@ -80,25 +80,16 @@
8080
# Aliases to export from this module
8181
AliasesToExport = '*'
8282

83-
# DSC resources to export from this module
84-
# DscResourcesToExport = @()
85-
86-
# List of all modules packaged with this module
87-
# ModuleList = @()
88-
89-
# List of all files packaged with this module
90-
# FileList = @()
91-
9283
# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
9384
PrivateData = @{
9485

9586
PSData = @{
9687

9788
# Tags applied to this module. These help with module discovery in online galleries.
98-
# Tags = @()
89+
Tags = @('powershell', 'powershell core', 'jenkins', 'hudson', 'api', 'PSEdition_Core', 'Windows', 'Linux')
9990

10091
# A URL to the license for this module.
101-
# LicenseUri = ''
92+
LicenseUri = 'https://www.apache.org/licenses/LICENSE-2.0.txt'
10293

10394
# A URL to the main website for this project.
10495
# ProjectUri = ''

scripts/setup_repo.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
set -ev
3+
4+
if [ "${TRAVIS_PULL_REQUEST}" = "false" ]; then
5+
COMMIT_SHA=${TRAVIS_COMMIT}
6+
else
7+
COMMIT_SHA=${TRAVIS_PULL_REQUEST_SHA}
8+
fi
9+
10+
git clone https://github.com/$TRAVIS_REPO_SLUG.git $TRAVIS_REPO_SLUG
11+
cd $TRAVIS_REPO_SLUG
12+
git checkout -qf $COMMIT_SHA

0 commit comments

Comments
 (0)