Skip to content

Add wrapper script for Linux and macOS#267

Merged
devblackops merged 3 commits intopsake:masterfrom
Saritasa:fix/add-support-of-linux-and-macos-2
Oct 18, 2018
Merged

Add wrapper script for Linux and macOS#267
devblackops merged 3 commits intopsake:masterfrom
Saritasa:fix/add-support-of-linux-and-macos-2

Conversation

@dermeister0
Copy link
Copy Markdown
Contributor

@dermeister0 dermeister0 commented Oct 11, 2018

Description

There is psake.cmd wrapper script to run psake tasks on Windows. I added a similar wrapper for Linux and macOS.

  • Set correct exit code in psake.ps1.
  • Introduce psake wrapper script.
  • Make src/psake executable, set correct autocrlf settings.

Related Issue

#262

Motivation and Context

It allows to use psake command to run psake tasks on Linux and macOS. Also psake.ps1 returns correct exit code now.

How Has This Been Tested?

I created tasks that may produce errors:

Task test `
{
    Hi-There
}
echo 'Task test { Hi-There }' > Test1.ps1
Task test `
    -requiredVariables @('SomeValue') `
{
    "Test $SomeValue"
}
echo "Task test -requiredVariables @('SomeValue') { \"Test \$SomeValue\" }" > Test2.ps1
Task test `
{
    $PSVersionTable
}
echo 'Task test { $PSVersionTable }' > Test3.ps1

Tested them on Ubuntu 18.04 (PowerShell Core 6.1).

git clone https://github.com/Saritasa/psake psake-fix-test
cd psake-fix-test/
git checkout fix/add-support-of-linux-and-macos-2
sudo ln -s `pwd`/src/psake /usr/bin/psake
psake Test1.ps1 test ; echo $?
psake Test2.ps1 test ; echo $?
psake Test2.ps1 test -parameters '@{SomeValue=123}' ; echo $?
psake Test3.ps1 test ; echo $?

Made sure correct exit code is returned.

Also I tested psake.cmd wrapper on Windows 10 (PowerShell 5.1).

&"psake-fix-test\src\psake.cmd" Test1.ps1 test ; echo $LASTEXITCODE
&"psake-fix-test\src\psake.cmd" Test2.ps1 test ; echo $LASTEXITCODE
&"psake-fix-test\src\psake.cmd" Test2.ps1 test -parameters '@{SomeValue=123}' ; echo $LASTEXITCODE
&"psake-fix-test\src\psake.cmd" Test3.ps1 test ; echo $LASTEXITCODE

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Set correct exit code in psake.ps1. Introduce psake wrapper script. Make src/psake executable, set correct autocrlf settings.
@dermeister0
Copy link
Copy Markdown
Contributor Author

der@build:~$ psake Test1.ps1 test ; echo $?
psake version 4.7.4
Copyright (c) 2010-2017 James Kovacs & Contributors

Executing test
Error: 10/11/18 1:38:50 PM:
At /home/der/Test1.ps1:1 char:13 + Task test { Hi-There } +             ~~~~~~~~ [<<==>>] Exception: The term 'Hi-There' is not recognized as the name of a cmdlet, function, script file, or operable program.Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
1
der@build:~$ psake Test2.ps1 test ; echo $?
psake version 4.7.4
Copyright (c) 2010-2017 James Kovacs & Contributors

Executing test
Error: 10/11/18 1:39:03 PM:
At /home/der/psake-fix-test/src/public/Assert.ps1:69 char:9 +         throw ('Assert: {0}' -f $failureMessage) +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [<<==>>] Exception: Assert: Variable SomeValue must be set to run task test.
1
der@build:~$ psake Test2.ps1 test -parameters '@{SomeValue=123}' ; echo $?
psake version 4.7.4
Copyright (c) 2010-2017 James Kovacs & Contributors

Executing test
Test 123

psake succeeded executing Test2.ps1

----------------------------------------------------------------------
Build Time Report
----------------------------------------------------------------------
Name   Duration
----   --------
test   00:00:00.050
Total: 00:00:00.136
0
der@build:~$ psake Test3.ps1 test ; echo $?
psake version 4.7.4
Copyright (c) 2010-2017 James Kovacs & Contributors

Executing test

Name                           Value
----                           -----
PSVersion                      6.1.0
PSEdition                      Core
GitCommitId                    6.1.0
OS                             Linux 4.15.0-36-generic #39-Ubuntu SMP Mon Sep 24 16:19:09 UTC 2018
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

psake succeeded executing Test3.ps1

----------------------------------------------------------------------
Build Time Report
----------------------------------------------------------------------
Name   Duration
----   --------
test   00:00:00.052
Total: 00:00:00.119


0

@dermeister0 dermeister0 mentioned this pull request Oct 11, 2018
9 tasks
@devblackops
Copy link
Copy Markdown
Member

Thanks @dermeister0!

Any chance you know why I receive this error?

readlink: illegal option -- f
usage: readlink [-n] [file ...]
mcp:4.7.4 brandon$ ./psake ../specs/docs_should_pass.ps1; echo $?
readlink: illegal option -- f
usage: readlink [-n] [file ...]
psake version 4.7.4
Copyright (c) 2010-2017 James Kovacs & Contributors

Executing CheckDocs

psake succeeded executing ../specs/docs_should_pass.ps1

----------------------------------------------------------------------
Build Time Report
----------------------------------------------------------------------
Name      Duration
----      --------
CheckDocs 00:00:00.113
Total:    00:00:00.155
0
mcp:4.7.4 brandon$

Other than this, it appears to work fine.

@dermeister0
Copy link
Copy Markdown
Contributor Author

dermeister0 commented Oct 17, 2018

@devblackops

I can't reproduce it, but found similar report: https://unix.stackexchange.com/questions/30446/strange-behavior-in-dirname-readlink-f-0

I added -- option for safety. Please pull the recent change.

@devblackops
Copy link
Copy Markdown
Member

Same error for me.

readlink: illegal option -- f
usage: readlink [-n] [file ...]

I should add this is on macOS. I haven't tried linux.

@dermeister0
Copy link
Copy Markdown
Contributor Author

@devblackops
I fixed it for macOS, but it requires greadlink utility from coreutils package.

brew install coreutils

@devblackops
Copy link
Copy Markdown
Member

@dermeister0 Great. That works for me.

@devblackops devblackops merged commit ac51dbb into psake:master Oct 18, 2018
@devblackops devblackops mentioned this pull request Oct 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants