Skip to content

Commit

Permalink
Merge pull request #6 from 1138-4EB/feat-shelltype
Browse files Browse the repository at this point in the history
Add GHA workflow, allow to select shell variant, add checks, etc.
  • Loading branch information
Ecco authored Oct 9, 2019
2 parents 11c006e + c9dfb87 commit fc9c30b
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 30 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: 'action'
on: [ push, pull_request ]
jobs:
set:
runs-on: windows-latest
steps:
- uses: actions/checkout@v1
- name: install deps
run: npm ci
- name: run action
uses: ./
- name: test MSYS
run: |
set MSYSTEM=MSYS
msys2do ./test.sh
- name: test MINGW64
run: |
set MSYSTEM=MINGW64
msys2do ./test.sh
- name: test MINGW32
run: |
set MSYSTEM=MINGW32
msys2do ./test.sh
undef:
strategy:
matrix:
task: [ MSYS, MINGW64, MINGW32 ]
runs-on: windows-latest
steps:
- uses: actions/checkout@v1
- name: install deps
run: npm ci
- name: run action
uses: ./
with:
msystem: ${{ matrix.task }}
- run: msys2do ./test.sh
66 changes: 66 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# comment this out distribution branches
node_modules/

# Editors
.vscode

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Other Dependency directories
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next
32 changes: 27 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
# Setup msys2
# Setup MSYS2

This is a GitHub action to setup an msys2 environment
**setup-msys2** is a JavaScript GitHub Action (GHA) to setup a full-featured [MSYS2](https://www.msys2.org/) environment, using the GHA [toolkit](https://github.com/actions/toolkit).

In actions.yml:
The latest tarball available at [repo.msys2.org/distrib/x86_64](http://repo.msys2.org/distrib/x86_64/) is cached. Using the action extracts it and provides an entrypoint named `msys2do`.

```
steps:
## Usage

```yaml
- uses: numworks/setup-msys2@v1
- run: msys2do uname -a
```
By default, `MSYSTEM` is set to `MINGW64`. However, an optional parameter named `msystem` is supported, which expects `MSYS`, `MINGW64` or `MING32`. For example:

```yaml
- uses: numworks/setup-msys2@v1
with:
msystem: MSYS
```

Furthermore, the environment variable can be overriden. This is useful when multiple commands need to be executed in different contexts. For example, in order to build a PKGBUILD file and then test the installed artifact:

```yaml
- uses: numworks/setup-msys2@v1
with:
msystem: MSYS
- run: msys2do makepkg-mingw -sCLfc --noconfirm --noprogressbar
- run: msys2do pacman --noconfirm -U mingw-w64-*-any.pkg.tar.xz
- run: |
set MSYSTEM=MINGW64
msys2do <command to test the package>
```
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
name: 'Setup Msys2 environment'
description: 'Setup an Msys2 environment and provide an msys2do helper'
author: 'NumWorks'
inputs:
msystem:
description: 'Variant of the environment to set by default: MSYS, MINGW32 or MINGW64'
required: false
default: 'MINGW64'
runs:
using: 'node12'
main: 'index.js'
42 changes: 32 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,46 @@ const fs = require('fs');

async function run() {
try {
const msys2base = await tc.downloadTool('http://repo.msys2.org/distrib/x86_64/msys2-base-x86_64-20190524.tar.xz');
if (process.platform !== 'win32') {
core.setFailed("MSYS2 does not work on non-windows platforms; please check the 'runs-on' field of the job");
return;
}

const tar = await io.which('tar', true);

const dest = path.join(process.env['RUNNER_TEMP'], 'msys')
const tmp_dir = process.env['RUNNER_TEMP'];
if (!tmp_dir) {
core.setFailed('environment variable RUNNER_TEMP is undefined');
return;
}
const dest = path.join(tmp_dir, 'msys');

// For some reason, GNU Tar on Windows expects paths to be slash-separated
const normalizedDest = dest.replace(/\\/g, '/')
await io.mkdirP(dest);

await io.mkdirP(dest)
const distrib = await tc.downloadTool('http://repo.msys2.org/distrib/x86_64/msys2-base-x86_64-20190524.tar.xz');

await exec.exec(`"${tar}"`, ['-x', '-J', '--force-local', '-C', normalizedDest, '-f', msys2base])
await exec.exec(`"${tar}"`, [
'-x', '-J', '--force-local',
// For some reason, GNU Tar on Windows expects paths to be slash-separated
'-C', dest.replace(/\\/g, '/'),
'-f', distrib
]);

fs.writeFileSync(
path.join(dest, 'msys2do.cmd'),
fs.readFileSync(path.join(__dirname, 'msys2do.cmd'))
)
let cmd = path.join(dest, 'msys2do.cmd');
fs.writeFileSync(cmd, [
'setlocal',
'set MSYS2_PATH_TYPE=strict',
`%~dp0\\msys64\\usr\\bin\\bash.exe -ilc "cd $OLDPWD && %*"`
].join('\n\r'));

core.addPath(dest);

core.exportVariable('MSYSTEM', core.getInput('msystem'));

core.startGroup('Starting MSYS2 for the first time...');
// For some reason, `msys2do` does not work
await exec.exec(`"${cmd}"`, ['uname', '-a']);
core.endGroup();
}
catch (error) {
core.setFailed(error.message);
Expand Down
5 changes: 0 additions & 5 deletions msys2do.cmd

This file was deleted.

6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 1 addition & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
"version": "1.0.0",
"description": "Msys2 GitHub action",
"main": "index.js",
"scripts": {
"lint": "eslint index.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/numworks/setup-msys2.git"
Expand All @@ -22,11 +19,8 @@
},
"homepage": "https://github.com/numworks/setup-msys2",
"dependencies": {
"@actions/core": "^1.1.1",
"@actions/core": "^1.1.3",
"@actions/exec": "^1.0.1",
"@actions/tool-cache": "1.1.2"
},
"devDependencies": {
"eslint": "^6.3.0"
}
}
5 changes: 5 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env sh

uname -a

env | grep MSYS

0 comments on commit fc9c30b

Please sign in to comment.