Run scripts as non-root user #20
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Test | |
on: | |
push: | |
workflow_dispatch: | |
jobs: | |
pre-run: | |
name: Pre-run step executes | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@v4 | |
- run: if [ -f pre-run ]; then echo "pre-run should not exist yet"; exit 1; fi | |
- uses: ./ | |
with: | |
pre-run: touch pre-run | |
- run: if [ ! -f pre-run ]; then echo "pre-run should exist"; exit 1; fi | |
- run: if [ "$(id -u)" = "0" ]; then echo "current user should not be root"; exit 1; fi | |
pre-run-non-root: | |
name: Pre-run step executes as a user other than root | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: ./ | |
with: | |
pre-run: if [ "$(id -u)" = "0" ]; then echo "current user should not be root"; exit 1; fi | |
run-in-vm: | |
name: Run-in-vm step executes | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@v4 | |
- run: if [ -f run-in-vm ]; then echo "run-in-vm should not exist yet"; exit 1; fi | |
- uses: ./ | |
with: | |
run-in-vm: uname -a > run-in-vm | |
- run: if [ ! -f run-in-vm ]; then echo "run-in-vm should exist (copied out of VM)"; exit 1; fi | |
- run: if ! grep -q "FreeBSD" run-in-vm; then echo "run-in-vm should contain FreeBSD"; exit 1; fi | |
post-run: | |
name: Post-run step executes | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@v4 | |
- run: if [ -f post-run ]; then echo "post-run should not exist yet"; exit 1; fi | |
- uses: ./ | |
with: | |
post-run: touch post-run | |
- run: if [ ! -f post-run ]; then echo "post-run should exist"; exit 1; fi | |
post-run-non-root: | |
name: Pre-run step executes as a user other than root | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: ./ | |
with: | |
post-run: if [ "$(id -u)" = "0" ]; then echo "current user should not be root"; exit 1; fi |