wiki/_next/data/Ie9t5zutrXP6Of75Cb5xF/cloud.github-actions.json
2022-07-29 15:41:17 +00:00

1 line
20 KiB
JSON

{"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 - '<YOUR_NUR_REPO>'\n cachixName:\n - '<YOUR_CACHIX_NAME>'\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 <nixpkgs> {}).lib.version'\n - name: Setup cachix\n uses: cachix/cachix-action@v10\n if: ${{ matrix.cachixName != '<YOUR_CACHIX_NAME>' }}\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 != <YOUR_NUR_REPO>' }}\n run: curl -XPOST \"https://nur-update.herokuapp.com/update?repo=${{ matrix.nurRepo }}\"\n"}]}]}]},"backlinks":[]},"__N_SSG":true}