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

Actions fail when writing to GITHUB_ENV in separate repository #33134

Open
noetzold opened this issue Jan 7, 2025 · 5 comments
Open

Actions fail when writing to GITHUB_ENV in separate repository #33134

noetzold opened this issue Jan 7, 2025 · 5 comments
Labels
topic/gitea-actions related to the actions of Gitea type/bug

Comments

@noetzold
Copy link

noetzold commented Jan 7, 2025

Description

Im using powershell on windows system and my action fails when write to GITHUB_ENV is performent in seperate repository.

Here is a test yml file to reproduce the issue:

name: build
on:
  push:
    branches:
      - '**'

defaults:
  run:
    shell: powershell

env:
  ACCESS_TOKEN: ${{secrets.ACCESS_TOKEN}}

jobs:
  Build:
    runs-on: windows
    steps:
      - name: Test1
        run: echo "TEST_VAR1=Hello" >> $env:GITHUB_ENV

      - name: Test2
        uses: https://${{ secrets.ACCESS_TOKEN }}@xyz/actions/gitea-issue@master

      - name: Print test 2
        if: ${{ always() }}
        run: echo "TestVar2 $env:TEST_VAR2"

gitea-issue repository action.yml:

name: 'Set up gitea issue'

defaults:
  run:
    shell: powershell

runs:
  using: "composite"
  steps:
    - name: Test1
      run: echo "TEST_VAR2=Hello2" >> $env:GITHUB_ENV

Step Test1 runs fine while Test2 fails.
There is no error message.
image

If I start the runner on a different PC with the same workflow, it works:
image
I do not know if it is the reason but the failing runner is on Windows 11 while the working one is on Windows 10.

Gitea Version

1.22.6

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

No response

Operating System

No response

How are you running Gitea?

Gitea runs from docker

Database

MySQL/MariaDB

@kemzeb kemzeb added the topic/gitea-actions related to the actions of Gitea label Jan 7, 2025
@lunny
Copy link
Member

lunny commented Jan 7, 2025

Are there any logs from the failed step?

@noetzold
Copy link
Author

noetzold commented Jan 7, 2025

Not in the action view or in the runner output. Is there another place?

@ChristopherHX
Copy link
Contributor

ChristopherHX commented Jan 7, 2025

Might be unrelated to your failure: The following syntax is not valid in action.yml and is discarded by the original nektos/act implementation and currently only allowed in act_runner while nektos/act switched to show errors if run steps have no shell in composite actions

defaults:
  run:
    shell: powershell

It is possible that your shell becomes pwsh (or even bash, sh in docker/linux/macos/freebsd) if installed in action.yml as result. Might be unrelated

@noetzold
Copy link
Author

noetzold commented Jan 8, 2025

Thank you @ChristopherHX for pointing me in the right direction.

The working system has "PowerShell Core" installed, the other one does not. If "PowerShell Core" is missing, the default is "PowerShell Desktop". https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsshell
This explains the difference.

But why writing to Write-Output "TEST_VAR=Hello" >> $env:GITHUB_ENV fails in PowerShell Desktop I do not know. I am fine with the workaround of using PowerShell Core instead.

Here is a slightly more sophisticated action to reproduce this:

name: build
on:
  push:
    branches:
      - '**'

env:
  ACCESS_TOKEN: ${{secrets.ACCESS_TOKEN}}

jobs:
  Build:
    runs-on: windows
    steps:
      - name: Test
        uses: https://${{ secrets.ACCESS_TOKEN }}@git.xyz.de/actions/gitea-issue@master

      - name: Print test
        if: ${{ always() }}
        run: echo "TestVar= $env:TEST_VAR"
name: 'Set up gitea issue'

runs:
  using: "composite"
  steps:
    - name: Test
      shell: powershell
      run: |
        $host.Version
        Write-Output "TEST_VAR=Hello" >> $env:GITHUB_ENV
        get-content $env:GITHUB_ENV

Here is the log of this run action-Build-533.log

image

@ChristopherHX
Copy link
Contributor

But why writing to Write-Output "TEST_VAR=Hello" >> $env:GITHUB_ENV fails in PowerShell Desktop I do not know. I am fine with the workaround of using PowerShell Core instead.

I think that I remember... this is an default encoding problem that has been fixed in pwsh core

PowerShell versions 5.1 and below (shell: powershell) do not use UTF-8 by default, so you must specify the UTF-8 encoding. For example:

See https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions?tool=powershell#environment-files

Selecting powershell in docs is needed to see this

Beyond the logging issue of act_runner not showing the error everything works like expected in my point of view

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic/gitea-actions related to the actions of Gitea type/bug
Projects
None yet
Development

No branches or pull requests

4 participants