Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to version build artifacts using GitHub Actions?

My use case is I want to have a unique version number for artifacts per each build/run. With current tools like CircleCI, Travis, etc. there is a build number available which is basically a counter that always goes up. So, I can create version strings like 0.1.0-27. This counter is increased each time even for the same commit.

How can I do something similar with GitHub Actions? Github actions only offer GITHUB_SHA and GITHUB_REF.

like image 887
moorara Avatar asked Jan 22 '19 14:01

moorara


People also ask

How do I get artifacts from GitHub Actions?

Downloading artifacts during a workflow run The actions/download-artifact action can be used to download previously uploaded artifacts during a workflow run. Note: You can only download artifacts in a workflow that were uploaded during the same workflow run.

How do I find the build number of an action in GitHub?

run_number : A unique number for each run of a particular workflow in a repository. This number begins at 1 for the workflow's first run, and increments with each new run. This number does not change if you re-run the workflow run.

Where are GitHub artifacts uploaded?

Where does the upload go? At the bottom of the workflow summary page, there is a dedicated section for artifacts.

What is the GitHub actions artifacts API?

The GitHub Actions Artifacts API allows you to download, delete, and retrieve information about workflow artifacts. The GitHub Actions Artifacts API allows you to download, delete, and retrieve information about workflow artifacts. Artifacts enable you to share data between jobs in a workflow and store data once that workflow has completed.

How to automate release creation and artifact upload with GitHub actions?

Being able to automate release creation and artifact upload with GitHub Actions allows you to fully leverage continuous and automated delivery. To create a release in your repo, your GitHub Actions workflow should utilize the create-release Action. Here is my implementation of it:

What's new in GitHub actions?

GitHub Actions now has a unique number and ID for a run/build in the github context. github.run_id : A unique number for each run within a repository.

How long are artifacts stored in GitHub?

All actions and workflows called within a run have write access to that run's artifacts. By default, GitHub stores build logs and artifacts for 90 days, and this retention period can be customized.


1 Answers

GitHub Actions now has a unique number and ID for a run/build in the github context.

github.run_id : A unique number for each workflow run within a repository. This number does not change if you re-run the workflow run.

github.run_number : A unique number for each run of a particular workflow in a repository. This number begins at 1 for the workflow's first run, and increments with each new run. This number does not change if you re-run the workflow run.

github.run_attempt : A unique number for each attempt of a particular workflow run in a repository. This number begins at 1 for the workflow run's first attempt, and increments with each re-run.

ref: https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#github-context

You can reference them in workflows like this:

      - name: Output Run ID         run: echo ${{ github.run_id }}       - name: Output Run Number         run: echo ${{ github.run_number }}       - name: Output Run Attempt         run: echo ${{ github.run_attempt }} 
like image 129
peterevans Avatar answered Sep 20 '22 04:09

peterevans