Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apt-get install in a GitHub Actions workflow?

In the new GitHub Actions, I am trying to install a package in order to use it in one of the next steps.

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
    # ...

However this fails with

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.

What's the best way to do this? Do I need to reach for Docker?

like image 577
Niklas Avatar asked Sep 26 '22 18:09

Niklas


People also ask

Can you CD in GitHub Actions?

With GitHub Actions, you can trigger CI/CD workflows and pipelines of webhooks from these apps (even something simple, like a chat app message, if you've integrated your chat app into your GitHub repository, of course).

What is the difference between sudo apt and sudo apt-get?

The apt-get command is a full-featured but simplified interface to dpkg , and apt is a more user-friendly but slightly stripped-back version of apt-get .

How does apt-get update work?

The sudo apt-get upgrade command downloads and installs the updates for each outdated package and dependency on your system. But just running sudo apt-get upgrade will not automatically upgrade the outdated packages – you'll still have a chance to review the changes and confirm that you want to perform the upgrades.

How do I install packages using GitHub actions?

You can install packages as part of your CI flow using GitHub Actions. For example, you could configure a workflow so that anytime a developer pushes code to a pull request, the workflow resolves dependencies by downloading and installing packages hosted by GitHub Packages. Then, the workflow can run CI tests that require the dependencies.

How do I run a workflow in GitHub repository?

Running a workflow 1 On GitHub, navigate to the main page of the repository. 2 Under your repository name, click Actions . 3 In the left sidebar, click the workflow you want to run. 4 Above the list of workflow runs, select Run workflow . 5 Use the Branch dropdown to select the workflow's branch, and type the input parameters. Click Run workflow .

How do I use GitHub actions?

For more information, see " GitHub's products ." GitHub Actions help you automate your software development workflows in the same place you store code and collaborate on pull requests and issues. You can write individual tasks, called actions, and combine them to create a custom workflow.

Is GitHub actions a good choice for automated workflows?

They also support many third-party integrations to automate your CD operations. But as long as your automated workflows don’t contain jobs that need third party plugins and services, GitHub Actions is the ideal choice for you. What we have discussed in this tutorial is just the tip of the iceberg.


Video Answer


1 Answers

The docs say:

The Linux and macOS virtual machines both run using passwordless sudo. When you need to execute commands or install tools that require more privileges than the current user, you can use sudo without needing to provide a password.

So simply doing the following should work:

- name: Install xmllint
  run: sudo apt-get install -y libxml2-utils
like image 319
rmunn Avatar answered Oct 19 '22 00:10

rmunn