mirror of
https://github.com/foo-dogsquared/wiki.git
synced 2025-01-31 01:57:54 +00:00
149 lines
33 KiB
HTML
149 lines
33 KiB
HTML
<!DOCTYPE html><html><head><meta name="viewport" content="width=device-width"/><meta charSet="utf-8"/><title>GitHub Actions</title><script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script><script id="MathJax-script" async="" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script><script type="text/x-mathjax-config">
|
|
MathJax = {
|
|
tex: {
|
|
inlineMath: [ ['$','$'], ['\(','\)'] ],
|
|
displayMath: [ ['$$','$$'], ['[',']'] ]
|
|
},
|
|
options = {
|
|
processHtmlClass = "math"
|
|
}
|
|
}
|
|
</script><meta name="next-head-count" content="6"/><link rel="preload" href="/wiki/_next/static/css/52fc2ba29703df73922c.css" as="style"/><link rel="stylesheet" href="/wiki/_next/static/css/52fc2ba29703df73922c.css" data-n-g=""/><noscript data-n-css=""></noscript><link rel="preload" href="/wiki/_next/static/chunks/main-ae4733327bd95c4ac325.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/webpack-50bee04d1dc61f8adf5b.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/framework.9d524150d48315f49e80.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/commons.0e1c3f9aa780c2dfe9f0.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/pages/_app-8e3d0c58a60ec788aa69.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/940643274e605e7596ecea1f2ff8d83317a3fb76.4841a16762f602a59f00.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/pages/%5B%5B...slug%5D%5D-1aa198f87ede1cd0e1dc.js" as="script"/></head><body><div id="__next"><main><h1>GitHub Actions</h1><section class="post-metadata"><span>Date: <!-- -->2021-06-20 18:58:48 +08:00</span><span>Date modified: <!-- -->2022-06-19 11:46:41 +08:00</span></section><nav class="toc"><ol class="toc-level toc-level-1"><li class="toc-item toc-item-h1"><a href="/wiki/cloud.github-actions#ecosystem" class="toc-link toc-link-h1">Ecosystem</a></li><li class="toc-item toc-item-h1"><a href="/wiki/cloud.github-actions#actions" class="toc-link toc-link-h1">Actions</a></li><li class="toc-item toc-item-h1"><a href="/wiki/cloud.github-actions#examples" class="toc-link toc-link-h1">Examples</a><ol class="toc-level toc-level-2"><li class="toc-item toc-item-h2"><a href="/wiki/cloud.github-actions#python-version-of-an-installation" class="toc-link toc-link-h2">Python version of an installation</a></li><li class="toc-item toc-item-h2"><a href="/wiki/cloud.github-actions#docker-container-integration" class="toc-link toc-link-h2">Docker container integration</a></li><li class="toc-item toc-item-h2"><a href="/wiki/cloud.github-actions#building-a-nix-binary-cache" class="toc-link toc-link-h2">Building a Nix binary cache</a></li><li class="toc-item toc-item-h2"><a href="/wiki/cloud.github-actions#building-packages-in-multiple-architectures" class="toc-link toc-link-h2">Building packages in multiple architectures</a></li></ol></li></ol></nav><p><img src="/wiki/assets/fds-visual-github-actions-description.png" placeholder="blur"/></p><ul><li><p>a CI/CD tool integrated into GitHub
|
|
</p></li><li><p>it is free for public repos but limited time per month for private repos
|
|
</p></li><li><p><a href="https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions">documentation</a> for it
|
|
</p></li><li><p>focused into creating workflows which can be separate and applied in different contexts
|
|
</p><ul><li><p>a workflow is activated from an event
|
|
</p></li><li><p>stored in <code class="inline-code">.github/workflows</code> in the remote repo
|
|
</p></li></ul></li><li><p>each workflow can run a job which are composed of steps
|
|
</p></li><li><p>each step make uses an action which is basically a script;
|
|
it can interact with the repo or do something else entirely without ever touching it
|
|
</p></li><li><p>you can use already defined actions or with your own
|
|
</p></li><li><p>if you want to explore other options, the <a href="https://github.com/marketplace">GitHub marketplace</a> allows searching for various third-party actions
|
|
</p></li></ul><h1 id="ecosystem">Ecosystem</h1><ul><li><p>there is also a <a href="https://docs.github.com/en/actions/guides">detailed guide</a> in introducing the overall concept
|
|
</p></li><li><p>the workflow allows you to create build artifacts;
|
|
you have fine-grained control such as letting you <a href="https://github.com/marketplace/actions/upload-a-build-artifact">upload certain files to be artifacts</a> and <a href="https://github.com/marketplace/actions/download-a-build-artifact">downloading them</a> after a workflow run;
|
|
it also enables sharing of data between jobs
|
|
</p></li><li><p>it can make automated releases like what I have done with <a href="https://github.com/foo-dogsquared/pop-launcher-plugin-duckduckgo-bangs/blob/d878e991dbb3269b4ea520e8c41bfa3e6346e4ab/.github/workflows/release.yml">one of my projects</a></p></li><li><p>it can create automated Git commits with <a href="https://github.com/marketplace/actions/git-auto-commit">Git Auto Commit</a>;
|
|
combine with the ability to set schedules, you can create an automatic sync following a project
|
|
</p></li><li><p>otherwise, you can also create automated release but have to go through a merge request;
|
|
for example, this is how <a href="https://github.com/simple-icons/simple-icons/blob/9020eb4a8163817813f90f493c66e8d6b565d31c/.github/workflows/create-release.yml">Simple Icons maintain their releases</a></p></li></ul><h1 id="actions">Actions</h1><ul><li><p>each of the job is mostly built with the actions;
|
|
the job can be controlled further through the workflow file;
|
|
see the <a href="https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions">Workflow Syntax</a> for more information
|
|
</p></li><li><p>related information such as the current branch, runners specifics, and so forth are stored in <a href="https://docs.github.com/en/actions/learn-github-actions/contexts">Contexts</a></p></li><li><p>like previously mentioned, you can search these actions in GitHub's marketplace
|
|
</p></li><li><p>the actions are primarily defined with <code class="inline-verbatim">actions.yml</code> from the root which can serve as a documentation for the parameters
|
|
</p></li></ul><h1 id="examples">Examples</h1><p>With GitHub Actions being a massive ecosystem of integrations as of 2021-07-05, we have to find some examples in the worldwide community repos from there.
|
|
</p><h2 id="python-version-of-an-installation">Python version of an installation</h2><p>The following block is a minimal example checking the Python version in the installation.
|
|
</p><pre class="src-block"><code class="language-yaml">name: Python version
|
|
on: [push]
|
|
jobs:
|
|
check-python-version:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v2
|
|
- uses: actions/setup-python@v2
|
|
- run: python --version
|
|
</code></pre><h2 id="docker-container-integration">Docker container integration</h2><p>GitHub workflows can make use of containers for easier delivering of dependencies and reproducing the development environment (among other things).
|
|
This includes...
|
|
</p><ul><li><p><a href="https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry">GitHub's own container registry</a>,
|
|
</p></li><li><p><a href="https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idcontainer">using a container to be used in a workflow</a> which is nice for building for multiple operating systems (e.g., multiple Linux distros)
|
|
</p></li><li><p><a href="https://docs.github.com/en/actions/using-containerized-services/about-service-containers">service containers</a> to make use of tools to your workflow,
|
|
</p></li><li><p>and even <a href="https://docs.github.com/en/actions/publishing-packages/publishing-docker-images">publishing containers to a registry from a workflow</a>.
|
|
</p></li></ul><p>In this example, we'll push an image to docker.io registry.
|
|
Be sure to have the necessary credentials and set it to the workflow environment to successfully run this workflow.
|
|
</p><pre class="src-block"><code class="language-yaml">name: Docker build image
|
|
on: [push]
|
|
jobs:
|
|
docker:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v2
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v1
|
|
- name: Setup Docker Buildx
|
|
uses: docker/setup-buildx-action@v1
|
|
- name: Login to DockerHub
|
|
uses: docker/login-action@v1
|
|
with:
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
- name: Build and push
|
|
id: docker_build
|
|
uses: docker/build-push-action@v2
|
|
with:
|
|
push: true
|
|
tags: ${{ secrets.DOCKERHUB_USERNAME }}/python-helloworld:latest
|
|
platforms: linux/amd64,linux/arm64
|
|
- name: Image digest
|
|
run: echo ${{ steps.docker_build.outputs.digest }}
|
|
</code></pre><h2 id="building-a-nix-binary-cache">Building a Nix binary cache</h2><p>We'll use <a href="/wiki/cloud.cachix">Cachix</a> as our binary cache service which has a free 10GB space (as of 2022-06-19).
|
|
This makes it easier to setup and distribute your own project built with <a href="/wiki/tools.nix">Nix package manager</a>.
|
|
</p><pre class="src-block"><code class="language-yaml">name: "Push packages into Cachix cache"
|
|
on:
|
|
pull_request:
|
|
push:
|
|
jobs:
|
|
tests:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v2.3.4
|
|
- uses: cachix/install-nix-action@v13
|
|
with:
|
|
nix_path: nixpkgs=channel:nixos-unstable
|
|
- uses: cachix/cachix-action@v10
|
|
with:
|
|
name: mycache
|
|
signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}'
|
|
- run: nix-build
|
|
- run: nix-shell --run "echo OK"
|
|
</code></pre><h2 id="building-packages-in-multiple-architectures">Building packages in multiple architectures</h2><p>This makes use of job matrix allowing to easily create similar workflows with different configurations.
|
|
</p><p>We'll use the GitHub Actions workflow file from the NUR template.
|
|
It is somewhat complex and it is doing a fine job showcasing some of GitHub Actions features.
|
|
</p><pre class="src-block"><code class="language-yaml">name: "Build and populate cache"
|
|
on:
|
|
pull_request:
|
|
push:
|
|
schedule:
|
|
- cron: '27 4 * * *'
|
|
jobs:
|
|
tests:
|
|
strategy:
|
|
matrix:
|
|
nurRepo:
|
|
- '<YOUR_NUR_REPO>'
|
|
cachixName:
|
|
- '<YOUR_CACHIX_NAME>'
|
|
nixPath:
|
|
- nixpkgs=channel:nixos-unstable
|
|
- nixpkgs=channel:nixpkgs-unstable
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v2.3.4
|
|
- name: Install nix
|
|
uses: cachix/install-nix-action@v13
|
|
with:
|
|
nix_path: "${{ matrix.nixPath }}"
|
|
- name: Show nixpkgs version
|
|
run: nix-instantiate --eval -E '(import <nixpkgs> {}).lib.version'
|
|
- name: Setup cachix
|
|
uses: cachix/cachix-action@v10
|
|
if: ${{ matrix.cachixName != '<YOUR_CACHIX_NAME>' }}
|
|
with:
|
|
name: ${{ matrix.cachixName }}
|
|
signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}'
|
|
- name: Check evaluation
|
|
run: |
|
|
nix-env -f . -qa \* --meta --xml \
|
|
--allowed-uris https://static.rust-lang.org \
|
|
--option restrict-eval true \
|
|
--option allow-import-from-derivation true \
|
|
--drv-path --show-trace \
|
|
-I nixpkgs=$(nix-instantiate --find-file nixpkgs) \
|
|
-I $PWD
|
|
- name: Build nix packages
|
|
run: nix run -I 'nixpkgs=channel:nixos-unstable' nixpkgs.nix-build-uncached -c nix-build-uncached ci.nix -A cacheOutputs
|
|
- name: Trigger NUR update
|
|
if: ${{ matrix.nurRepo != <YOUR_NUR_REPO>' }}
|
|
run: curl -XPOST "https://nur-update.herokuapp.com/update?repo=${{ matrix.nurRepo }}"
|
|
</code></pre></main></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{"metadata":{"date":"\"2021-06-20 18:58:48 +08:00\"","date_modified":"\"2022-06-19 11:46:41 +08:00\"","language":"en","source":""},"title":"GitHub Actions","hast":{"type":"root","children":[{"type":"element","tagName":"nav","properties":{"className":"toc"},"children":[{"type":"element","tagName":"ol","properties":{"className":"toc-level toc-level-1"},"children":[{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h1","properties":{"id":"ecosystem"},"children":[{"type":"text","value":"Ecosystem"}]}]},"properties":{"className":"toc-item toc-item-h1"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h1","href":"/cloud.github-actions#ecosystem"},"children":[{"type":"text","value":"Ecosystem"}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h1","properties":{"id":"actions"},"children":[{"type":"text","value":"Actions"}]}]},"properties":{"className":"toc-item toc-item-h1"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h1","href":"/cloud.github-actions#actions"},"children":[{"type":"text","value":"Actions"}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h1","properties":{"id":"examples"},"children":[{"type":"text","value":"Examples"}]}]},"properties":{"className":"toc-item toc-item-h1"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h1","href":"/cloud.github-actions#examples"},"children":[{"type":"text","value":"Examples"}]},{"type":"element","tagName":"ol","properties":{"className":"toc-level toc-level-2"},"children":[{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h2","properties":{"id":"python-version-of-an-installation"},"children":[{"type":"text","value":"Python version of an installation"}]}]},"properties":{"className":"toc-item toc-item-h2"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h2","href":"/cloud.github-actions#python-version-of-an-installation"},"children":[{"type":"text","value":"Python version of an installation"}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h2","properties":{"id":"docker-container-integration"},"children":[{"type":"text","value":"Docker container integration"}]}]},"properties":{"className":"toc-item toc-item-h2"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h2","href":"/cloud.github-actions#docker-container-integration"},"children":[{"type":"text","value":"Docker container integration"}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h2","properties":{"id":"building-a-nix-binary-cache"},"children":[{"type":"text","value":"Building a Nix binary cache"}]}]},"properties":{"className":"toc-item toc-item-h2"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h2","href":"/cloud.github-actions#building-a-nix-binary-cache"},"children":[{"type":"text","value":"Building a Nix binary cache"}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h2","properties":{"id":"building-packages-in-multiple-architectures"},"children":[{"type":"text","value":"Building packages in multiple architectures"}]}]},"properties":{"className":"toc-item toc-item-h2"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h2","href":"/cloud.github-actions#building-packages-in-multiple-architectures"},"children":[{"type":"text","value":"Building packages in multiple architectures"}]}]}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"img","properties":{"src":"/assets/fds-visual-github-actions-description.png"},"children":[]}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"a CI/CD tool integrated into GitHub\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"it is free for public repos but limited time per month for private repos\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions"},"children":[{"type":"text","value":"documentation"}]},{"type":"text","value":" for it\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"focused into creating workflows which can be separate and applied in different contexts\n"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"a workflow is activated from an event\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"stored in "},{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":".github/workflows"}]},{"type":"text","value":" in the remote repo\n"}]}]}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"each workflow can run a job which are composed of steps\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"each step make uses an action which is basically a script;\n it can interact with the repo or do something else entirely without ever touching it\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"you can use already defined actions or with your own\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"if you want to explore other options, the "},{"type":"element","tagName":"a","properties":{"href":"https://github.com/marketplace"},"children":[{"type":"text","value":"GitHub marketplace"}]},{"type":"text","value":" allows searching for various third-party actions\n"}]}]}]},{"type":"element","tagName":"h1","properties":{"id":"ecosystem"},"children":[{"type":"text","value":"Ecosystem"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"there is also a "},{"type":"element","tagName":"a","properties":{"href":"https://docs.github.com/en/actions/guides"},"children":[{"type":"text","value":"detailed guide"}]},{"type":"text","value":" in introducing the overall concept\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"the workflow allows you to create build artifacts;\n you have fine-grained control such as letting you "},{"type":"element","tagName":"a","properties":{"href":"https://github.com/marketplace/actions/upload-a-build-artifact"},"children":[{"type":"text","value":"upload certain files to be artifacts"}]},{"type":"text","value":" and "},{"type":"element","tagName":"a","properties":{"href":"https://github.com/marketplace/actions/download-a-build-artifact"},"children":[{"type":"text","value":"downloading them"}]},{"type":"text","value":" after a workflow run;\n it also enables sharing of data between jobs\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"it can make automated releases like what I have done with "},{"type":"element","tagName":"a","properties":{"href":"https://github.com/foo-dogsquared/pop-launcher-plugin-duckduckgo-bangs/blob/d878e991dbb3269b4ea520e8c41bfa3e6346e4ab/.github/workflows/release.yml"},"children":[{"type":"text","value":"one of my projects"}]}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"it can create automated Git commits with "},{"type":"element","tagName":"a","properties":{"href":"https://github.com/marketplace/actions/git-auto-commit"},"children":[{"type":"text","value":"Git Auto Commit"}]},{"type":"text","value":";\n combine with the ability to set schedules, you can create an automatic sync following a project\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"otherwise, you can also create automated release but have to go through a merge request;\n for example, this is how "},{"type":"element","tagName":"a","properties":{"href":"https://github.com/simple-icons/simple-icons/blob/9020eb4a8163817813f90f493c66e8d6b565d31c/.github/workflows/create-release.yml"},"children":[{"type":"text","value":"Simple Icons maintain their releases"}]}]}]}]},{"type":"element","tagName":"h1","properties":{"id":"actions"},"children":[{"type":"text","value":"Actions"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"each of the job is mostly built with the actions;\n the job can be controlled further through the workflow file;\n see the "},{"type":"element","tagName":"a","properties":{"href":"https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions"},"children":[{"type":"text","value":"Workflow Syntax"}]},{"type":"text","value":" for more information\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"related information such as the current branch, runners specifics, and so forth are stored in "},{"type":"element","tagName":"a","properties":{"href":"https://docs.github.com/en/actions/learn-github-actions/contexts"},"children":[{"type":"text","value":"Contexts"}]}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"like previously mentioned, you can search these actions in GitHub's marketplace\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"the actions are primarily defined with "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"actions.yml"}]},{"type":"text","value":" from the root which can serve as a documentation for the parameters\n"}]}]}]},{"type":"element","tagName":"h1","properties":{"id":"examples"},"children":[{"type":"text","value":"Examples"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"With GitHub Actions being a massive ecosystem of integrations as of 2021-07-05, we have to find some examples in the worldwide community repos from there.\n"}]},{"type":"element","tagName":"h2","properties":{"id":"python-version-of-an-installation"},"children":[{"type":"text","value":"Python version of an installation"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"The following block is a minimal example checking the Python version in the installation.\n"}]},{"type":"element","tagName":"pre","properties":{"className":["src-block"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-yaml"]},"children":[{"type":"text","value":"name: Python version\non: [push]\njobs:\n check-python-version:\n runs-on: ubuntu-latest\n steps:\n - uses: actions/checkout@v2\n - uses: actions/setup-python@v2\n - run: python --version\n"}]}]},{"type":"element","tagName":"h2","properties":{"id":"docker-container-integration"},"children":[{"type":"text","value":"Docker container integration"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"GitHub workflows can make use of containers for easier delivering of dependencies and reproducing the development environment (among other things).\nThis includes...\n"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry"},"children":[{"type":"text","value":"GitHub's own container registry"}]},{"type":"text","value":",\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idcontainer"},"children":[{"type":"text","value":"using a container to be used in a workflow"}]},{"type":"text","value":" which is nice for building for multiple operating systems (e.g., multiple Linux distros)\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://docs.github.com/en/actions/using-containerized-services/about-service-containers"},"children":[{"type":"text","value":"service containers"}]},{"type":"text","value":" to make use of tools to your workflow,\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"and even "},{"type":"element","tagName":"a","properties":{"href":"https://docs.github.com/en/actions/publishing-packages/publishing-docker-images"},"children":[{"type":"text","value":"publishing containers to a registry from a workflow"}]},{"type":"text","value":".\n"}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"In this example, we'll push an image to docker.io registry.\nBe sure to have the necessary credentials and set it to the workflow environment to successfully run this workflow.\n"}]},{"type":"element","tagName":"pre","properties":{"className":["src-block"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-yaml"]},"children":[{"type":"text","value":"name: Docker build image\non: [push]\njobs:\n docker:\n runs-on: ubuntu-latest\n steps:\n - name: Checkout\n uses: actions/checkout@v2\n - name: Set up QEMU\n uses: docker/setup-qemu-action@v1\n - name: Setup Docker Buildx\n uses: docker/setup-buildx-action@v1\n - name: Login to DockerHub\n uses: docker/login-action@v1\n with:\n username: ${{ secrets.DOCKERHUB_USERNAME }}\n password: ${{ secrets.DOCKERHUB_TOKEN }}\n - name: Build and push\n id: docker_build\n uses: docker/build-push-action@v2\n with:\n push: true\n tags: ${{ secrets.DOCKERHUB_USERNAME }}/python-helloworld:latest\n platforms: linux/amd64,linux/arm64\n - name: Image digest\n run: echo ${{ steps.docker_build.outputs.digest }}\n"}]}]},{"type":"element","tagName":"h2","properties":{"id":"building-a-nix-binary-cache"},"children":[{"type":"text","value":"Building a Nix binary cache"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"We'll use "},{"type":"element","tagName":"a","properties":{"href":"/cloud.cachix"},"children":[{"type":"text","value":"Cachix"}]},{"type":"text","value":" as our binary cache service which has a free 10GB space (as of 2022-06-19).\nThis makes it easier to setup and distribute your own project built with "},{"type":"element","tagName":"a","properties":{"href":"/tools.nix"},"children":[{"type":"text","value":"Nix package manager"}]},{"type":"text","value":".\n"}]},{"type":"element","tagName":"pre","properties":{"className":["src-block"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-yaml"]},"children":[{"type":"text","value":"name: \"Push packages into Cachix cache\"\non:\n pull_request:\n push:\njobs:\n tests:\n runs-on: ubuntu-latest\n steps:\n - uses: actions/checkout@v2.3.4\n - uses: cachix/install-nix-action@v13\n with:\n nix_path: nixpkgs=channel:nixos-unstable\n - uses: cachix/cachix-action@v10\n with:\n name: mycache\n signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}'\n - run: nix-build\n - run: nix-shell --run \"echo OK\"\n"}]}]},{"type":"element","tagName":"h2","properties":{"id":"building-packages-in-multiple-architectures"},"children":[{"type":"text","value":"Building packages in multiple architectures"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"This makes use of job matrix allowing to easily create similar workflows with different configurations.\n"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"We'll use the GitHub Actions workflow file from the NUR template.\nIt is somewhat complex and it is doing a fine job showcasing some of GitHub Actions features.\n"}]},{"type":"element","tagName":"pre","properties":{"className":["src-block"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-yaml"]},"children":[{"type":"text","value":"name: \"Build and populate cache\"\non:\n pull_request:\n push:\n schedule:\n - cron: '27 4 * * *'\njobs:\n tests:\n strategy:\n matrix:\n nurRepo:\n - '\u003cYOUR_NUR_REPO\u003e'\n cachixName:\n - '\u003cYOUR_CACHIX_NAME\u003e'\n nixPath:\n - nixpkgs=channel:nixos-unstable\n - nixpkgs=channel:nixpkgs-unstable\n runs-on: ubuntu-latest\n steps:\n - name: Checkout repository\n uses: actions/checkout@v2.3.4\n - name: Install nix\n uses: cachix/install-nix-action@v13\n with:\n nix_path: \"${{ matrix.nixPath }}\"\n - name: Show nixpkgs version\n run: nix-instantiate --eval -E '(import \u003cnixpkgs\u003e {}).lib.version'\n - name: Setup cachix\n uses: cachix/cachix-action@v10\n if: ${{ matrix.cachixName != '\u003cYOUR_CACHIX_NAME\u003e' }}\n with:\n name: ${{ matrix.cachixName }}\n signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}'\n - name: Check evaluation\n run: |\n nix-env -f . -qa \\* --meta --xml \\\n --allowed-uris https://static.rust-lang.org \\\n --option restrict-eval true \\\n --option allow-import-from-derivation true \\\n --drv-path --show-trace \\\n -I nixpkgs=$(nix-instantiate --find-file nixpkgs) \\\n -I $PWD\n - name: Build nix packages\n run: nix run -I 'nixpkgs=channel:nixos-unstable' nixpkgs.nix-build-uncached -c nix-build-uncached ci.nix -A cacheOutputs\n - name: Trigger NUR update\n if: ${{ matrix.nurRepo != \u003cYOUR_NUR_REPO\u003e' }}\n run: curl -XPOST \"https://nur-update.herokuapp.com/update?repo=${{ matrix.nurRepo }}\"\n"}]}]}]},"backlinks":[]},"__N_SSG":true},"page":"/[[...slug]]","query":{"slug":["cloud.github-actions"]},"buildId":"Ie9t5zutrXP6Of75Cb5xF","assetPrefix":"/wiki","nextExport":false,"isFallback":false,"gsp":true}</script><script nomodule="" src="/wiki/_next/static/chunks/polyfills-99d808df29361cf7ffb1.js"></script><script src="/wiki/_next/static/chunks/main-ae4733327bd95c4ac325.js" async=""></script><script src="/wiki/_next/static/chunks/webpack-50bee04d1dc61f8adf5b.js" async=""></script><script src="/wiki/_next/static/chunks/framework.9d524150d48315f49e80.js" async=""></script><script src="/wiki/_next/static/chunks/commons.0e1c3f9aa780c2dfe9f0.js" async=""></script><script src="/wiki/_next/static/chunks/pages/_app-8e3d0c58a60ec788aa69.js" async=""></script><script src="/wiki/_next/static/chunks/940643274e605e7596ecea1f2ff8d83317a3fb76.4841a16762f602a59f00.js" async=""></script><script src="/wiki/_next/static/chunks/pages/%5B%5B...slug%5D%5D-1aa198f87ede1cd0e1dc.js" async=""></script><script src="/wiki/_next/static/Ie9t5zutrXP6Of75Cb5xF/_buildManifest.js" async=""></script><script src="/wiki/_next/static/Ie9t5zutrXP6Of75Cb5xF/_ssgManifest.js" async=""></script></body></html> |