diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..e1980f4 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,95 @@ +name: Test + +on: [push, pull_request] + +jobs: + test: + runs-on: windows-latest + strategy: + matrix: + include: + - platform: 'x86_64' + - platform: 'x86' + packages: >- + coreutils + moreutils + - platform: 'amd64' + packages: | + coreutils, + moreutils + fail-fast: false + + name: 'Test ${{ matrix.platform }}' + + steps: + - run: git config --global core.autocrlf input + + - uses: actions/checkout@v2 + + - name: Install Cygwin + uses: ./ + with: + platform: ${{ matrix.platform }} + packages: ${{ matrix.packages }} + + - name: Explicitly running shell + run: C:\cygwin\bin\bash -lc "echo 'Explicitly run shell'" + + - name: Single-line inline shell + run: echo "Running in $(pwd)" + shell: C:\cygwin\bin\bash.exe '{0}' + + - name: Multiline inline shell + run: >- + echo "Running in $(pwd)" && + true + shell: C:\cygwin\bin\bash.exe '{0}' + + - name: Shell script + run: C:\cygwin\bin\bash.exe tests/script.sh + + - name: Check requested packages got installed + run: C:\cygwin\bin\sponge.exe tmp + if: contains(matrix.packages, 'moreutils') + + complex-test: + runs-on: windows-latest + name: 'Complex Test' + + strategy: + matrix: + include: + - combination: 1 + + defaults: + run: + shell: C:\cygwin\bin\bash.exe --noprofile --norc -o igncr -eo pipefail '{0}' + + steps: + - run: git config --global core.autocrlf input + shell: pwsh -command ". '{0}'". + + - uses: actions/checkout@v2 + + - name: Install Cygwin + uses: ./ + + - name: Run one + run: | + echo + echo "One" + echo + + - name: Run two + run: | + if [[ '${{ matrix.combination }}' == "${COMBINATION}" ]]; then + echo "It's true: ${COMBINATION} satisfied" + else + exit 1 + fi + + echo + echo "Two" + echo + env: + COMBINATION: 1 diff --git a/README.md b/README.md new file mode 100644 index 0000000..2bddc47 --- /dev/null +++ b/README.md @@ -0,0 +1,79 @@ +Cygwin Install GitHub Action +============================ + +This GitHub Action can be used in a workflow to install Cygwin. + +e.g. + + - run: git config --global core.autocrlf input + + - uses: actions/checkout@v2 + + - uses: cygwin/cygwin-install-action@master + + - run: C:\cygwin\bin\bash.exe tests/script.sh + +Please fix my terrible cargo-cult PowerShell. + +Parameters +---------- + +| Input | Default | Description +| ----------- | ------- | ----------- +| platform | x86_64 | Install the x86 or x86\_64 version of Cygwin. +| packages | *none* | List of additional packages to install. + +Line endings +------------ + +If you're going to use `actions/checkout` in your workflow, you should +precede that with + + - run: git config --global core.autocrlf input + +to ensure that any shell scripts etc. in your repository don't get checked out +with `\r\n` line endings (leading to `'\r': command not found` errors). + +Likewise, if you have multiple lines of shell script in a YAML block for `run:` +in your workflow file, the file this is written into on the runner ends up with +`\r\n` line endings. + +You can use `>-` (rather than `|`) to ensure that it doesn't contain any +newlines. + +Alternatively, you can also use: + +- `igncr` in the `SHELLOPTS` environment variable +- invoke `bash` with `-o igncr` + +PATH +---- + +If you want to ensure that PATH only contains Cygwin executables, and other +stuff installed in the VM image isn't going to get picked up: + +- Set PATH to something like `/usr/bin:$(cygpath ${SYSTEMROOT})/system32` in + your shell script + +or, + +- Put `CYGWIN_NOWINPATH=1` into the environment +- start a login shell with `bash --login` +- because the profile script from does `cd ${HOME}`, either: + * `cd ${GITHUB_WORKSPACE}` in your shell script, or + * prevent the profile script from changing directory by putting + `CHERE_INVOKING` into the environment + +Symlinks +-------- + +Unfortunately, Cygwin's `setup` doesn't (currently) honour +`CYGWIN=winsymlinks:native` or offer an option to control the kind of symlinks +created, so some executables (e.g. `python`) are created as Cygwin-style +symlinks. Since CMD and PowerShell don't understand those symlinks, you cannot +run those executables directly in a `run:` in your workflow. Execute them via +`bash` or `env` instead. + +[1] The +[Workflow documentation](https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#exit-codes-and-error-action-preference) +suggests you should also use bash options `-eo pipefail`, omitted here for clarity diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..df71e01 --- /dev/null +++ b/action.yml @@ -0,0 +1,61 @@ +name: Install Cygwin Action +description: GitHub Action to install Cygwin + +inputs: + platform: + description: Platform [x86, x86_64] + required: false + default: x86_64 + packages: + description: Packages to install + required: false + +runs: + using: "composite" + steps: + - run: | + $platform = '${{ inputs.platform }}' + $platform = $platform -replace '^(x64|amd64)$', 'x86_64' + $platform = $platform -replace '^i686$', 'x86' + # validate that platform is one of the expected values + if (($platform -ne 'x86') -and ($platform -ne 'x86_64')) { + echo "unknown platform $platform" + exit 1 + } + Invoke-WebRequest https://cygwin.com/setup-$platform.exe -OutFile C:\setup.exe + shell: powershell + + - run: | + $packages = '${{ inputs.packages }}' + $pkg_list = $packages.Split('', [System.StringSplitOptions]::RemoveEmptyEntries) + $pkg_list = $pkg_list | % { $_.Trim() } + $pkg_list = $pkg_list | % { $_.Trim(',') } + + $args = @( + '-qgnO', + '-s', 'http://mirrors.kernel.org/sourceware/cygwin/', + '-l', 'C:\cygwin-packages', + # always install to C:\cygwin rather than the platform dependent + # default to make everything simpler + '-R', 'C:\cygwin' + ) + + if ($pkg_list.Count -gt 0) { + $args += '-P' + $args += $pkg_list -Join(',') + } + + # because setup is a Windows GUI app, make it part of a pipeline to make + # PowerShell wait for it to exit + & C:\setup.exe $args | Out-Default + shell: powershell + + - run: | + echo "C:\cygwin\bin" >> $env:GITHUB_PATH + # run login shell to copy skeleton profile files + C:\cygwin\bin\bash.exe --login + shell: powershell + +branding: + color: green + icon: terminal diff --git a/tests/script.sh b/tests/script.sh new file mode 100644 index 0000000..6a272cb --- /dev/null +++ b/tests/script.sh @@ -0,0 +1,4 @@ +#!/usr/bin/sh +echo "" +echo "Running a script" +echo ""