GitHub Actions部署至PythonAnywhere时遇permission denied错误求助
GitHub Actions部署PythonAnywhere时Permission Denied问题处理
错误信息
Run git update-index --chmod=+x deploy.sh; ./deploy.sh git update-index --chmod=+x deploy.sh; ./deploy.sh shell: /usr/bin/bash -e {0} env: PYTHONPATH: /home/runner/work/cosmic_cruiser/cosmic_cruiser/ pythonLocation: /opt/hostedtoolcache/Python/3.9.18/x64 PKG_CONFIG_PATH: /opt/hostedtoolcache/Python/3.9.18/x64/lib/pkgconfig Python_ROOT_DIR: /opt/hostedtoolcache/Python/3.9.18/x64 Python2_ROOT_DIR: /opt/hostedtoolcache/Python/3.9.18/x64 Python3_ROOT_DIR: /opt/hostedtoolcache/Python/3.9.18/x64 LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.9.18/x64/lib DEMO_PA_PWD: *** /home/runner/work/_temp/d8dbb980-ed66-4e73-bbae-b48afa95da3a.sh: line 1: ./deploy.sh: Permission denied Error: Process completed with exit code 126.
现有GitHub Actions配置(main.yml)
# This is a workflow to test and deploy our demo app. name: Demo CI/CD # Controls when the workflow will run on: # Triggers the workflow on push or pull request events but only for the main branch push: branches: [ master ] pull_request: branches: [ master ] # Allows you to run this workflow manually from the Actions tab workflow_dispatch: env: PYTHONPATH: /home/runner/work/cosmic_cruiser/cosmic_cruiser/ # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: # This workflow contains a single job called "build" build: # The type of runner that the job will run on runs-on: ubuntu-latest environment: pa_deploy # Steps represent a sequence of tasks that will be executed as part of the job steps: - name: Set up Python 3.9 uses: actions/setup-python@v4 with: # Semantic version range syntax or exact version of a Python version python-version: '3.9' # Optional - x64 or x86 architecture, defaults to x64 architecture: 'x64' # You can test your matrix by printing the current Python version - name: Display Python version run: python -c "import sys; print(sys.version)" # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v2 - name: Install MongoDB uses: supercharge/mongodb-github-action@1.8.0 - name: Install Python packages. run: make dev_env - name: Run Python tests. run: make all_tests - name: Deploy to PythonAnywhere run: git update-index --chmod=+x deploy.sh; ./deploy.sh env: DEMO_PA_PWD: ${{secrets.DEMO_PA_PWD}}
已尝试的方案
- 本地检查deploy.sh权限,确认执行位已开启:
0 -rwxrwxrwx 1 user user 757 Feb 1 17:29 deploy.sh - 本地执行
git update-index --chmod=+x deploy.sh并推送更改 - 在部署步骤中显式执行
git update-index --chmod=+x deploy.sh后再运行脚本 - 重新克隆仓库
备注:仓库中所有文件(如README)执行位均已开启,且无法关闭deploy.sh的执行位
可行解决方案
方案1:直接用chmod设置执行权限
替换部署步骤中的命令,跳过git索引操作,直接给脚本加执行权限:
- name: Deploy to PythonAnywhere run: chmod +x deploy.sh && ./deploy.sh env: DEMO_PA_PWD: ${{secrets.DEMO_PA_PWD}}
git update-index仅修改git仓库的权限记录,但Actions runner环境中checkout后的文件权限可能受仓库配置或runner设置影响,直接用chmod能确保脚本在当前环境获得执行权限。
方案2:用bash直接调用脚本(绕过执行位检查)
如果设置权限仍无效,可以直接通过bash解释器执行脚本,无需依赖文件自身的执行位:
- name: Deploy to PythonAnywhere run: bash deploy.sh env: DEMO_PA_PWD: ${{secrets.DEMO_PA_PWD}}
方案3:检查并修复目录权限
偶尔目录权限不足也会导致脚本无法执行,可以先添加步骤检查当前目录权限:
- name: Check workspace permissions run: ls -ld $GITHUB_WORKSPACE
如果目录权限过低,可先修复:
- name: Fix directory permissions run: chmod 755 $GITHUB_WORKSPACE
内容的提问来源于stack exchange,提问作者SeniorDesign
相关产品推荐
相关产品推荐

