在新的 GitHub Actions 中,我尝试安装一个包以便在后续步骤之一中使用它。
name: CI
on: [push, pull_request]
jobs:
translations:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
with:
fetch-depth: 1
- name: Install xmllint
run: apt-get install libxml2-utils
# ...
然而这失败了
Run apt-get install libxml2-utils
apt-get install libxml2-utils
shell: /bin/bash -e {0}
E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?
##[error]Process completed with exit code 100.
最好的方法是什么?我需要使用 Docker 吗?
文档说:
Linux 和 macOS 虚拟机均使用无密码运行
。当您需要执行命令或安装需要比当前用户更多权限的工具时,您可以使用sudo
而无需提供密码。sudo
因此,只需执行以下操作即可:
- name: Install xmllint
run: sudo apt-get install -y libxml2-utils
请在此处查看此答案:https://stackoverflow.com/a/73500415/2038264
cache-apt-pkgs-action 可以安装和缓存 apt 软件包,因此您后续的构建速度很快。配置也更容易,只需添加你想要的包即可:
- uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: dia doxygen doxygen-doc doxygen-gui doxygen-latex graphviz mscgen
version: 1.0
错误提示了问题
E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
这是一个权限问题。如此美好又简单,用 sudo 运行它。
下面的示例
jobs:
test:
name: Unit test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: ⚙️ Install lcov
run: |
sudo apt-get update
sudo apt-get -y install lcov
这里 github 操作正在安装
lcov
一个执行代码覆盖率的工具。