Gitea Actions - Support for configuration variables in workflows #12817

Closed
opened 2025-11-02 10:21:56 -06:00 by GiteaMirror · 5 comments
Owner

Originally created by @kerem0comert on GitHub (Apr 10, 2024).

Feature Description

Hello,

In my Gitea Actions configuration - suppose that I would like to be able to configure the behavior of certain steps.
For example, consider the following step:

    - name: Run pytest
      run: |
        if [ -d tests/ ]; then
          if [ -f tests/gitea_actions.yaml ]; then
            echo "Found gitea_actions.yaml, checking if tests should be run..."
            
            run_tests=$(python -c "import yaml; print(yaml.safe_load(open('tests/gitea_actions.yaml'))['run_tests'])")
            echo "run_tests is set to $run_tests"
            if [ "$run_tests" = "True" ]; then
              echo "run_tests is set to true, running tests..."
              python -m pytest tests/
            else
              echo "run_tests is not set to true, skipping tests."
            fi
          else
            echo "gitea_actions.yaml does not exist, skipping tests."
          fi
        else
          echo "Test directory does not exist, skipping tests."
        fi

Currently I can configure this behavior by a yaml file that I keep in the repository. However, is it possible to have it as an external variable that is configurable per repository, in the Gitea frontend? And it can be accessed in a way like gitea.actor. I assume this is similar to what GitHub Actions already supports here.

Please let me know if such a thing already exists, or if not what is the best practice for this requirement (should I continue having this external yaml file for my configs?).

Thanks!

Screenshots

No response

Originally created by @kerem0comert on GitHub (Apr 10, 2024). ### Feature Description Hello, In my Gitea Actions configuration - suppose that I would like to be able to configure the behavior of certain steps. For example, consider the following step: ```yaml - name: Run pytest run: | if [ -d tests/ ]; then if [ -f tests/gitea_actions.yaml ]; then echo "Found gitea_actions.yaml, checking if tests should be run..." run_tests=$(python -c "import yaml; print(yaml.safe_load(open('tests/gitea_actions.yaml'))['run_tests'])") echo "run_tests is set to $run_tests" if [ "$run_tests" = "True" ]; then echo "run_tests is set to true, running tests..." python -m pytest tests/ else echo "run_tests is not set to true, skipping tests." fi else echo "gitea_actions.yaml does not exist, skipping tests." fi else echo "Test directory does not exist, skipping tests." fi ``` Currently I can configure this behavior by a yaml file that I keep in the repository. However, is it possible to have it as an external variable that is configurable per repository, in the Gitea frontend? And it can be accessed in a way like ```gitea.actor```. I assume this is similar to [what GitHub Actions already supports here](https://github.blog/changelog/2023-01-10-github-actions-support-for-configuration-variables-in-workflows/). Please let me know if such a thing already exists, or if not what is the best practice for this requirement (should I continue having this external yaml file for my configs?). Thanks! ### Screenshots _No response_
GiteaMirror added the type/proposalissue/needs-feedback labels 2025-11-02 10:21:56 -06:00
Author
Owner

@lunny commented on GitHub (Apr 10, 2024):

This has been supported. ref https://docs.gitea.com/usage/actions/act-runner?_highlight=variable#configuration-variable

@lunny commented on GitHub (Apr 10, 2024): This has been supported. ref https://docs.gitea.com/usage/actions/act-runner?_highlight=variable#configuration-variable
Author
Owner

@kerem0comert commented on GitHub (Apr 10, 2024):

Thanks!
The docs say:

Variable names can only contain alphanumeric characters ([a-z], [A-Z], [0-9]) or underscores (_). Spaces are not allowed.

however, when I set the name as run_tests I see that the UI converts it to uppercase. Do both work? Is this intended? Maybe a clarification of this in the docs would be nice.

run_tests_ss

@kerem0comert commented on GitHub (Apr 10, 2024): Thanks! The docs say: ``` Variable names can only contain alphanumeric characters ([a-z], [A-Z], [0-9]) or underscores (_). Spaces are not allowed. ``` however, when I set the name as ```run_tests``` I see that the UI converts it to uppercase. Do both work? Is this intended? Maybe a clarification of this in the docs would be nice. ![run_tests_ss](https://github.com/go-gitea/gitea/assets/42437138/ce5d65df-5834-4f04-ae54-26bd074bf026)
Author
Owner

@kerem0comert commented on GitHub (Apr 10, 2024):

I have the name set up in uppercase and set to true (as I assume lowercase may create confusion as the UI seems to convert it) and I have:

    - name: Run pytest
      run: |
        if [ -d tests/ ]; then
          echo "Test directory exists..."
          
          echo "RUN_TESTS variable is set to {{ vars.RUN_TESTS }}"
          
          if [ "{{ vars.RUN_TESTS }}" = "true" ]; then
            echo "RUN_TESTS is set to true, running tests..."
            python -m pytest tests/
          else
            echo "RUN_TESTS is not set to true, skipping tests."
          fi
        else
          echo "Test directory does not exist, skipping tests."
        fi

however, I get as output:

Test directory exists...
RUN_TESTS variable is set to {{ vars.RUN_TESTS }}
RUN_TESTS is not set to true, skipping tests.

So it seems the variable does not get read. What am I doing wrong?

@kerem0comert commented on GitHub (Apr 10, 2024): I have the name set up in uppercase and set to ```true``` (as I assume lowercase may create confusion as the UI seems to convert it) and I have: ```yaml - name: Run pytest run: | if [ -d tests/ ]; then echo "Test directory exists..." echo "RUN_TESTS variable is set to {{ vars.RUN_TESTS }}" if [ "{{ vars.RUN_TESTS }}" = "true" ]; then echo "RUN_TESTS is set to true, running tests..." python -m pytest tests/ else echo "RUN_TESTS is not set to true, skipping tests." fi else echo "Test directory does not exist, skipping tests." fi ``` however, I get as output: ``` Test directory exists... RUN_TESTS variable is set to {{ vars.RUN_TESTS }} RUN_TESTS is not set to true, skipping tests. ``` So it seems the variable does not get read. What am I doing wrong?
Author
Owner

@lunny commented on GitHub (Apr 10, 2024):

Sorry, the documentaion is wrong. It should be ${{ vars.RUN_TESTS }}. I will send a PR to correct it.

@lunny commented on GitHub (Apr 10, 2024): Sorry, the documentaion is wrong. It should be `${{ vars.RUN_TESTS }}`. I will send a PR to correct it.
Author
Owner

@lunny commented on GitHub (Apr 10, 2024):

This will be fixed by #30394

@lunny commented on GitHub (Apr 10, 2024): This will be fixed by #30394
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#12817