Skip to content

Commit b1c82a3

Browse files
committed
Add tests for PATH suggestion output of installation script
The "template" installation script stored in this repository prints advice to the user about adding the installation to their PATH environment variable. This advice is adjusted according to whether a previous installation was found in the PATH and according to the path(s) of their installation(s) so it is fairly complex. For this reason, it will be good to have a check in the "Test install script" CI workflow to ensure the output is as expected.
1 parent bf25b5b commit b1c82a3

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

.github/workflows/test-install-script.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,78 @@ jobs:
191191
shell: bash
192192
run: |
193193
"${PWD}/bin/${{ env.TOOL_NAME }}" --version | grep "^nightly-"
194+
195+
path-suggestions:
196+
needs: configure
197+
strategy:
198+
fail-fast: false
199+
200+
matrix:
201+
os:
202+
- ubuntu-latest
203+
- windows-latest
204+
- macos-latest
205+
206+
runs-on: ${{ matrix.os }}
207+
208+
steps:
209+
- name: Set install path environment variables
210+
shell: bash
211+
run: |
212+
# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable
213+
FIRST_INSTALLATION_FOLDER="first-installation-folder"
214+
echo "FIRST_INSTALLATION_FOLDER=${FIRST_INSTALLATION_FOLDER}" >> "$GITHUB_ENV"
215+
echo "FIRST_BINDIR=${{ runner.temp }}/${FIRST_INSTALLATION_FOLDER}" >> "$GITHUB_ENV"
216+
SECOND_INSTALLATION_FOLDER="second-installation-folder"
217+
echo "SECOND_INSTALLATION_FOLDER=${SECOND_INSTALLATION_FOLDER}" >> "$GITHUB_ENV"
218+
echo "SECOND_BINDIR=${{ runner.temp }}/${SECOND_INSTALLATION_FOLDER}" >> "$GITHUB_ENV"
219+
220+
- name: Download script artifact
221+
uses: actions/download-artifact@v2
222+
with:
223+
name: ${{ env.SCRIPT_ARTIFACT_NAME }}
224+
225+
- name: Make script executable
226+
run: chmod u+x "${{ github.workspace }}/${{ env.SCRIPT_NAME }}"
227+
228+
- name: Check script output without previous installation in PATH
229+
shell: sh
230+
env:
231+
BINDIR: ${{ env.FIRST_BINDIR }}
232+
run: |
233+
mkdir -p "${{ env.BINDIR }}"
234+
"${{ github.workspace }}/${{ env.SCRIPT_NAME }}" | \
235+
grep \
236+
-F \
237+
'${{ env.TOOL_NAME }} not found. You might want to add "${{ env.FIRST_BINDIR }}" to your $PATH'
238+
239+
- name: Add first installation to PATH
240+
shell: bash
241+
run: |
242+
# See: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#adding-a-system-path
243+
echo "${{ env.FIRST_BINDIR }}" >> "$GITHUB_PATH"
244+
245+
- name: Check script output with previous installation in PATH (non-Windows)
246+
if: runner.os != 'Windows'
247+
shell: sh
248+
env:
249+
BINDIR: ${{ env.SECOND_BINDIR }}
250+
run: |
251+
mkdir -p "${{ env.BINDIR }}"
252+
"${{ github.workspace }}/${{ env.SCRIPT_NAME }}" | \
253+
grep \
254+
-F \
255+
'${{ env.TOOL_NAME }} was found at ${{ env.FIRST_BINDIR }}/${{ env.TOOL_NAME }}. Please prepend "${{ env.BINDIR }}" to your $PATH'
256+
257+
# ${{ runner.temp }} is a Windows style path on the windows runner, but the script output uses the equivalent POSIX style path.
258+
# So a regex is used for the output check on Windows.
259+
- name: Check script output with previous installation in PATH (Windows)
260+
if: runner.os == 'Windows'
261+
shell: sh
262+
env:
263+
BINDIR: ${{ env.SECOND_BINDIR }}
264+
run: |
265+
mkdir -p "${{ env.BINDIR }}"
266+
"${{ github.workspace }}/${{ env.SCRIPT_NAME }}" | \
267+
grep \
268+
'${{ env.TOOL_NAME }} was found at .*/${{ env.FIRST_INSTALLATION_FOLDER }}/${{ env.TOOL_NAME }}\. Please prepend ".*/${{ env.SECOND_INSTALLATION_FOLDER }}" to your \$PATH'

0 commit comments

Comments
 (0)