Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to persist a WORKDIR between Actions in GitHub Actions?

I woke up to my GitHub Actions BETA invite this morning (wooo) and have started playing with it, with the aim of migrating some simple build, test and deploy pipelines I currently have running on CircleCI.

I'm still trying to get my head around Actions, but the flow I have in mind is that after a push, the first Action in the workflow will launch a Docker container. Inside that container I'll run some simple build processes such as minimising assets and removing artefacts. The next Action will then run some tests on the build. And the next Action(s) in the pipeline will deploy to one of a number of environments, depending on the branch I pushed to.

I've followed the docs at https://developer.github.com/actions/creating-github-actions/creating-a-docker-container/ and have a rudimentary workflow that launches a Docker container and runs some build commands inside the WORKDIR. I'm also able to run a deployment (via rsync) from inside this WORKDIR too.

However, I'd like to split this into separate steps/Actions, but I can't figure out a way to to this.

Essentially, this would be similar to the CircleCI jobs/workflow model I'm using. However, with CircleCI, the first job runs a build then persists the resulting directory structure throughout the rest of the workflow, like this:

# Persist dist directory
  - persist_to_workspace:
      root: ~/project
      paths:
        - .

So, I'm kinda equating CircleCI's Jobs to GitHub's Actions here, which is possibly the wrong thing to do? Essentially, what I'm trying to find out is whether I can persist a WORKDIR inside the first Action's Docker container and make that WORKDIR available to subsequent Actions.

Is this possible, or am I way off with what I'm imagining GitHub Actions can do?

Thanks!

like image 668
Contention Avatar asked Feb 01 '19 16:02

Contention


People also ask

How do I share data between jobs in GitHub Actions?

Passing data between jobs in a workflow. You can use the upload-artifact and download-artifact actions to share data between jobs in a workflow. This example workflow illustrates how to pass data between jobs in the same workflow. For more information, see the actions/upload-artifact and download-artifact actions.

Do GitHub Actions run concurrently?

GitHub Actions combines Continuous Integration (CI) and Continuous Delivery (CD) to constantly and consistently test and build your code and ship it to any target. Actions also provide a job matrix which assists in executing multiple jobs without configuring it. It can generate a maximum of 256 jobs per workflow run.

What is concurrency in GitHub Actions?

concurrency to ensure that only a single job or workflow using the same concurrency group will run at a time. A concurrency group can be any string or expression. The expression can use any context except for the secrets context.

What is one way that GitHub Actions workflows can not be used?

"GitHub Actions workflows can't be executed on this repository. Actions is not available for legacy per-repository billing plans.


1 Answers

Answering this myself in case someone else runs into this issue (and, like me, didn't fully read the docs!). :o)

The docs here explain, but essentially the working directory of any container you start as part of an action exists as /github/workspace. Actions can modify the contents of this working directory, and when containers are started in subsequent actions during the workflow, the working directory for these actions/containers will contain the modifications made earlier in the workflow.

So, the answer is yes, the Docker WORKDIR at /github/workspace is persisted throughout a GitHub Actions workflow in a similar way to how it can persist in a CircleCI workflow.

like image 123
Contention Avatar answered Oct 24 '22 01:10

Contention