Skip to content

Commit

Permalink
Pass the shell arguments directly to bash
Browse files Browse the repository at this point in the history
This allows us to run the "run" script using "set -eo pipefail" by default.

The previous wrapper executed the arguments as a bash command string, which
allowed the user to run any command, but didn't give us a chance to special case
if the argument was a script passed from the GHA "run" command.

This is a breaking change.

Porting guide:

* Instead of `msys2 mybinary` you now have to run `msys2 -c 'mybinary'`
* To revert the bash error settings you can use `set +e` and `set +o pipefail`
  in your run script
  • Loading branch information
lazka committed Jul 14, 2020
1 parent 5c975f7 commit 13553f6
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 17 deletions.
42 changes: 40 additions & 2 deletions .github/workflows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ jobs:
rm -rf node_modules
- name: run action
uses: ./
- run: msys2 go env
- run: msys2 -c "go env"
env:
MSYS2_PATH_TYPE: inherit

Expand All @@ -219,7 +219,7 @@ jobs:
uses: ./
with:
path-type: inherit
- run: msys2 go env
- run: msys2 -c "go env"

install:
needs: [path-type]
Expand Down Expand Up @@ -292,3 +292,41 @@ jobs:
update: true
install: base-devel git
- run: git describe --dirty --tags

errorhandling:
needs: [defaultdirty]
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: build action
shell: bash
run: |
npm ci
npm run pkg
rm -rf node_modules
- name: run action
uses: ./
- shell: msys2 {0}
run: |
(! false | true) || exit 1; # make sure "-o pipefail" is active by default
[[ "$-" =~ 'e' ]] || exit 1; # make sure "set -e" is active by default
workingdir:
needs: [errorhandling]
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: build action
shell: bash
run: |
npm ci
npm run pkg
rm -rf node_modules
- name: run action
uses: ./
- shell: msys2 {0}
run: |
# make sure we are in checkout directory
dir="$(pwd)"
cd "$GITHUB_WORKSPACE"
[[ "$dir" == "$(pwd)" ]]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Then, for multi-line scripts:
Or, for single line commands:
```yaml
- run: msys2 uname -a
- run: msys2 -c 'uname -a'
```
### Default shell
Expand Down Expand Up @@ -90,7 +90,7 @@ Furthermore, the environment variable can be overridden. This is useful when mul
pacman --noconfirm -U mingw-w64-*-any.pkg.tar.xz
- run: |
set MSYSTEM=MINGW64
msys2 <command to test the package>
msys2 -c '<command to test the package>'
```

#### path-type
Expand Down
19 changes: 6 additions & 13 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ async function run() {
const p_install = core.getInput('install');
const p_cache = core.getInput('cache');

let drive = 'C:';
let base = 'C:';

if (p_release) {
// Use upstream package instead of the default installation in the virtual environment.
core.startGroup('Downloading MSYS2...');
drive = '%~dp0';
base = '%~dp0';
let inst_dest = path.join(tmp_dir, 'base.exe');
await tc.downloadTool(inst_url, inst_dest);

Expand All @@ -60,18 +60,11 @@ async function run() {
}

let wrap = [
`setlocal`,
`@echo off`,
`setlocal`,
`IF NOT DEFINED MSYS2_PATH_TYPE set MSYS2_PATH_TYPE=` + p_pathtype,
`set "args=%*"`,
`set "args=%args:\\=/%"`,
/* TODO:
See https://www.msys2.org/wiki/Launchers/#the-idea
Ideally, there would be some better solution than 'cd $OLDPWD', such as using 'CHERE_INVOKING=1'.
However, since an intermediate file is used, it would probably make CHERE_INVOKING use the location of
'msys2.cmd' or the temporal file created by GitHub's runner.
*/
drive + `\\msys64\\usr\\bin\\env.exe /usr/bin/bash --norc -ilceo pipefail "cd $OLDPWD && %args%"`
`set CHERE_INVOKING=1`,
base + `\\msys64\\usr\\bin\\bash.exe -leo pipefail %*`
].join('\r\n');

let cmd = path.join(dest, 'msys2.cmd');
Expand All @@ -89,7 +82,7 @@ async function run() {
}

async function run(args, opts) {
await exec.exec('cmd', ['/D', '/S', '/C', cmd].concat(args), opts);
await exec.exec('cmd', ['/D', '/S', '/C', cmd].concat(['-c', args.join(' ')]), opts);
}

async function pacman(args, opts) {
Expand Down

0 comments on commit 13553f6

Please sign in to comment.