Skip to content

Commit 9d4a34a

Browse files
authored
Merge pull request #189 from per1234/fix-install-script-path-suggestion
Fix install script's check for previous installation
2 parents 4d5c4e9 + 1f641f6 commit 9d4a34a

File tree

2 files changed

+81
-6
lines changed

2 files changed

+81
-6
lines changed

Diff for: .github/workflows/test-install-script.yml

+75
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'

Diff for: other/installation-script/install.sh

+6-6
Original file line numberDiff line numberDiff line change
@@ -186,19 +186,19 @@ bye() {
186186

187187
testVersion() {
188188
set +e
189-
EXECUTABLE_PATH="$(command -v $PROJECT_NAME)"
190-
if [ "$?" = "1" ]; then
191-
# $PATH is intentionally a literal in this message.
192-
# shellcheck disable=SC2016
193-
echo "$PROJECT_NAME not found. You might want to add \"$EFFECTIVE_BINDIR\" to your "'$PATH'
194-
else
189+
if EXECUTABLE_PATH="$(command -v $PROJECT_NAME)"; then
195190
# Convert to resolved, absolute paths before comparison
196191
EXECUTABLE_REALPATH="$(cd -- "$(dirname -- "$EXECUTABLE_PATH")" && pwd -P)"
197192
EFFECTIVE_BINDIR_REALPATH="$(cd -- "$EFFECTIVE_BINDIR" && pwd -P)"
198193
if [ "$EXECUTABLE_REALPATH" != "$EFFECTIVE_BINDIR_REALPATH" ]; then
194+
# $PATH is intentionally a literal in this message.
199195
# shellcheck disable=SC2016
200196
echo "An existing $PROJECT_NAME was found at $EXECUTABLE_PATH. Please prepend \"$EFFECTIVE_BINDIR\" to your "'$PATH'" or remove the existing one."
201197
fi
198+
else
199+
# $PATH is intentionally a literal in this message.
200+
# shellcheck disable=SC2016
201+
echo "$PROJECT_NAME not found. You might want to add \"$EFFECTIVE_BINDIR\" to your "'$PATH'
202202
fi
203203

204204
set -e

0 commit comments

Comments
 (0)