Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gitea Actions - Support for configuration variables in workflows #30393

Closed
kerem0comert opened this issue Apr 10, 2024 · 5 comments · Fixed by #30394
Closed

Gitea Actions - Support for configuration variables in workflows #30393

kerem0comert opened this issue Apr 10, 2024 · 5 comments · Fixed by #30394
Labels
issue/needs-feedback For bugs, we need more details. For features, the feature must be described in more detail type/proposal The new feature has not been accepted yet but needs to be discussed first.

Comments

@kerem0comert
Copy link

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

@kerem0comert kerem0comert added the type/proposal The new feature has not been accepted yet but needs to be discussed first. label Apr 10, 2024
@lunny
Copy link
Member

lunny commented Apr 10, 2024

@lunny lunny added the issue/needs-feedback For bugs, we need more details. For features, the feature must be described in more detail label Apr 10, 2024
@kerem0comert
Copy link
Author

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
Copy link
Author

kerem0comert commented 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?

@lunny
Copy link
Member

lunny commented Apr 10, 2024

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

@lunny
Copy link
Member

lunny commented Apr 10, 2024

This will be fixed by #30394

wolfogre pushed a commit that referenced this issue Apr 11, 2024
Fix #30393

---------

Co-authored-by: silverwind <[email protected]>
Co-authored-by: Zettat123 <[email protected]>
GiteaBot pushed a commit to GiteaBot/gitea that referenced this issue Apr 11, 2024
Fix go-gitea#30393

---------

Co-authored-by: silverwind <[email protected]>
Co-authored-by: Zettat123 <[email protected]>
GiteaBot pushed a commit to GiteaBot/gitea that referenced this issue Apr 11, 2024
Fix go-gitea#30393

---------

Co-authored-by: silverwind <[email protected]>
Co-authored-by: Zettat123 <[email protected]>
lunny added a commit that referenced this issue Apr 11, 2024
Backport #30394 by @lunny

Fix #30393

Co-authored-by: Lunny Xiao <[email protected]>
Co-authored-by: silverwind <[email protected]>
Co-authored-by: Zettat123 <[email protected]>
lunny added a commit that referenced this issue Apr 11, 2024
Backport #30394 by @lunny

Fix #30393

Co-authored-by: Lunny Xiao <[email protected]>
Co-authored-by: silverwind <[email protected]>
Co-authored-by: Zettat123 <[email protected]>
@go-gitea go-gitea locked as resolved and limited conversation to collaborators Jul 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
issue/needs-feedback For bugs, we need more details. For features, the feature must be described in more detail type/proposal The new feature has not been accepted yet but needs to be discussed first.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants