<p><ahref="https://about.gitea.com/">Gitea</a> actions is the new Github-compatible CI/automation pipeline feature that ships with Gitea and <ahref="https://forgejo.org/">Forgejo</a>. In theory it is interoperable with <ahref="https://docs.github.com/en/actions">Github actions </a>but there are still a few rough edges and for that reason, the feature is still disabled by default.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>I have been trying to get <ahref="https://brainsteam.co.uk/2023/11/13/gastronaut-fediverse-recipe-app/"data-type="post"data-id="380">a django project</a> that uses <ahref="https://brainsteam.co.uk/2021/04/01/opinionated-guide-to-virtualenvs/"data-type="post"data-id="193">PDM</a> for Python dependency management to to install itself and run some tests in a Gitea CI environment.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>In theory, my workflow is simple:</p>
<!-- /wp:paragraph -->
<!-- wp:list -->
<ul><!-- wp:list-item -->
<li>Check out the code with actions/checkout@v4</li>
<!-- /wp:list-item -->
<!-- wp:list-item -->
<li>Install pdm with with<code> pdm-project/setup-pdm@v3</code></li>
<!-- /wp:list-item -->
<!-- wp:list-item -->
<li>Use a run: block to get pdm to install dependencies with <code>pdm install</code></li>
<!-- /wp:list-item -->
<!-- wp:list-item -->
<li>Use another run block to have PDM run my tests: <code>pdm run manage.py test</code></li>
<!-- /wp:list-item --></ul>
<!-- /wp:list -->
<!-- wp:paragraph -->
<p>Unfortunately there were a couple of odd quirks that I had to resolve first before I could get it working.</p>
<!-- /wp:paragraph -->
<!-- wp:heading {"level":3} -->
<h3class="wp-block-heading">Add a Github Key</h3>
<!-- /wp:heading -->
<!-- wp:paragraph -->
<p>I was initially getting an error about being Unauthorized from the <code>pdm-project/setup-pdm@v3</code> step. This is because the action attempts to download a list of pre-built python distributions from github and since we're running outside of github it is initially unable to get this list without an additional API key. All we need to do is <ahref="https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-personal-access-token-classic">create a Github token</a> and then set up a new project secret and paste in the token that we just created. I use the name <code>GH_TOKEN</code> because Gitea does not allow you to use any secret prefixed <code>GITHUB</code>.</p>
<figureclass="wp-block-image size-large"><imgsrc="/media/image-10-1024x404_47995791.png"alt="A screenshot of the project settings in gitea. Navigate to Actions, Secrets, Add Secret and reate a new secret called GH_TOKEN."class="wp-image-410"/><figcaptionclass="wp-element-caption">Create a secret called GH_TOKEN which we can pass to the action.</figcaption></figure>
<h3class="wp-block-heading">Change the Container Image</h3>
<!-- /wp:heading -->
<!-- wp:paragraph -->
<p>Once I resolved the authorization error above, I started getting error messages about how no Python releases were available for the given OS and architecture. I thought that was weird because in theory we're running Ubuntu on x64. <ahref="https://forum.gitea.com/t/gitea-actions-with-python/7605/4">This forum post</a> suggested that changing the docker image that the runner uses to execute the pipeline might work. I'm not 100% sure what the default Gitea action runner uses as its base image but Gitea Actions are based on <ahref="https://github.com/nektos/act">Act</a>, a local runner for Github actions and the official Act project recommends images by <ahref="https://github.com/catthehacker/docker_images">catthehacker</a> for use as runners. By specifying one of these images, we seem to be able to 'fix' whatever metadata is missing from the default image.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>We can pass a container in via the job <code>container</code> directive like so:</p>
<preclass="EnlighterJSRAW"data-enlighter-language="yaml"data-enlighter-theme=""data-enlighter-highlight=""data-enlighter-linenumbers=""data-enlighter-lineoffset=""data-enlighter-title=""data-enlighter-group="">name: Run Tests
run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀
on: [push]
jobs:
run_tests:
runs-on: ubuntu-latest
container: catthehacker/ubuntu:act-latest
steps:
- name: Checkout Codebase
uses: actions/checkout@v3
- name: Set up python
run: |
apt-get update && apt-get install -y python3-venv
pip install --upgrade pdm
- uses: pdm-project/setup-pdm@v3
with:
python-version: 3.10
token: ${{ secrets.GH_TOKEN }}
- name: Install dependencies
run: cd ${{ gitea.workspace }} && pdm install
- name: Run tests
run: |
cd ${{ gitea.workspace }} && pdm run manage.py test