Can I use Inline Powershell in Build Script? - build

I need to build an Electron app installer with some "dynamic" values in the package.json. I'd like to replace a placeholder with powershell as part of the build process.
Can I use powershell inside this yml definition to set string to value1, build/publish artifact and then repeat using value2?
I can only find one example and it's calling an external script.

Of course, I found it as soon as I posted!
steps:
- powershell: |
Write-Host "This works!"

Related

Can I run a Windows Powershell command matching all files in the current directory and all subdirectories?

My file structure looks like this:
maindir/
- subdir/
- file1.ts
- file2.ts
- file3.ts
- file4.ts
I'm trying to build typescript interfaces using ts-interface-builder, and I want to match and build all 4 file*.ts files. (ts-interface-builder just builds the types, this question is mainly about the matching pattern / wildcards in Windows Powershell since I'm used to Unix).
I'm currently using this command:
npx ts-interface-builder ./maindir/*.ts
But this only builds file3.ts and file4.ts.
I could use a slightly different command:
npx ts-interface-builder ./maindir/*/*.ts
But it only builds file1.ts and file2.ts.
I tried researching Windows Powershell wildcards but wasn't able to figure it out.
Is there a single command I could use to build all 4 files?
Assuming that your npx command is executed by / from PowerShell:
npx ts-interface-builder (Get-ChildItem ./maindir -Recurse -Filter *.ts).FullName
See also: The Get-ChildItem cmdlet.

Github Actions path does not update

Right now, I'm trying to build a tool from source and use it to build a C++ project. I'm able to extract the tar file (gcc-arm-none-eabi). But, when I try to add it to path (using $GITHUB_PATH, not add-path), the path doesn't apply on my next action and I can't build the file. The error states that it can't find the gcc-arm-none-eabi toolset, which means that it didn't go to path.
Here's the script for the entrypoint of the first function (make is ran in the next action to allow for path to apply)
echo "Downloading ARM Toolchain"
# The one from apt isn't updated so I have to build from source
curl -L https://developer.arm.com/-/media/Files/downloads/gnu-rm/10-2020q4/gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2 -o gcc-arm-none-eabi.tar.bz2
tar -xjf gcc-arm-none-eabi.tar.bz2
echo "/github/workspace/gcc-arm-none-eabi-10-2020-q4-major/bin" >> $GITHUB_PATH
I can't even debug by seeing what's in the path because running echo $(PATH) just says that PATH cannot be found. What should I do?
I can't even debug by seeing what's in the path because running echo $(PATH) just says that PATH cannot be found. What should I do?
First, PATH is not a command so if you want to print its value, it would be something like echo "${PATH}" or echo "$PATH"
Then, if you want to add a value to an existing environment variable, it would be something like
export PATH="${PATH}:/github/workspace/gcc-arm-none-eabi-10-2020-q4-major/bin"
EDIT: seems not a valid way to add something to the path using Github Actions, meanwhile it seems correct in the question. To get more details: https://docs.github.com/en/free-pro-team#latest/actions/reference/workflow-commands-for-github-actions#adding-a-system-path . Thanks to Benjamin W. for pointing this out in the comments.
Finally I think it would be a better fit if you use a docker image that already contains that kind of dependancies (you could easily write your own Dockerfile if this image doesn't already exists). Github action is designed to use docker (or OCI containers) image that contains the dependancies you need to perform your build actions. You should take a look here: https://docs.github.com/en/free-pro-team#latest/actions/creating-actions/dockerfile-support-for-github-actions

Get %AppData% path (or other environment variable) for Git hook on Windows (10)

Is it possible to get the %AppData% path within a git hook on my Windows 10 machine?
I am attempting to use it to call gulp.... so maybe even the environment variable %NODE_PATH% which I also have....but essentially I want to get the path of the environment variable.
I currently have:-
gulp="/c/Users/MYUSERNAME/AppData/Roaming/npm/gulp.cmd"
echo $gulp
and then I can call gulp successfully..... but I'd like not to hardcode my username in the path....and rather have something like:-
gulp="%AppData%/gulp.cmd"
echo $gulp
Any suggestions?
This works on my Git Bash:
$ export gulp=`echo $APPDATA | sed -e 's/^C:/\/c/;s/\\\\/\//g;s/$/\\/npm\\/gulp\\.cmd/' `
$ gulp
No gulpfile found
The sed transforms the Windows path into something in Bash format, with each regular expression separated by a semicolon:
Change "C:\" to "/c":
s/^C:/\/c/
Change the remaining backslashes:
s/\\\\/\//g
Append the gulp command:
s/$/\\/npm\\/gulp\\.cmd/
The backticks evaluate the expression, and they requiring doubling up the backslashes used for escaping the regex special characters.

Use VS Online "Command Line" task with relative paths

I'm trying to use the new VS Online Build process and, specifically, package my app as a NuGet package.
To do so I have to execute something like "nuget pack". My source code is in GitHub and there, under the root folder, I have a folder called .nuget with all necessary to do the packaging.
I've added to my build template a "Command Line" step with this parameters:
tool: C:\a\9ea8689c\myusername\myproject.nuget\nuget.exe
arguments: pack
Everything else is defaults, included working folder. This works. However when I've tried to replace the absolute path for something like ".nuget/nuget.exe" or .nuget/nuget.exe or even changing the working folder to .nuget and from there just type "nuget.exe" it repeatedly fails because it can't find the tool.
Am I missing something? Should the task work with relative paths?
You should use absolute paths leveraging TFS Environment Variables like TF_BUILD_BUILDDIRECTORY.
In a batch file it is something like
echo Launching my own NuGet copy
%TF_BUILD_BUILDDIRECTORY%\myproject.nuget\nuget.exe
This worked for me: $(BUILD.SOURCESDIRECTORY)\NuGet.exe.
Notice the dot instead of underscore. I have put my NuGet.exe in the main repository folder, in my case NuGet 3.5 Beta.

How to get last build label in text file

I have one project which is under Cruise control.
I want to write one console application which will write the last build label of that project in one text file.
CruiseControl passes CCNetLabel argument to script that it invokes. You can just print this out to a file from the script without writing a console application.
If you need to retrieve project version from outside of the CruiseControl, then you can either access this file (i.e.: by exposing it via IIS) or poll and parse XML report of CruiseControl dashboard (which is located at http://BuildServer/XmlServerReport.aspx)
Depends on what flavour of cruisecontrol you use ? For default, java version, i have something like this
<schedule showProgress="true">
<composite showProgress="true">
<exec timeout="2400" command="${homedir}/bin/updatebuildid" args="${sbhomedir}/projects/${project.name} ${label}"/>
..... etc ..
And updatebuild script is basicly a shellscript for invoking sed to add a postfix to a version number in the packaging files. for you it could be just simple "echo $1 > $yourfile"