-2

I want to write a text to file using GitHub Actions but I don't know how to do it.

I've tried:

def write(path, text):
    file = open(path, 'w')
    file.write(text)
    file.close()

but nothing has changed.

But if I run it on local machine it is still works.

Cat_125
  • 1
  • 2
  • What do you mean by nothing has changed? Do you mean that the file is not present, the file contents are empty, or the file contents are the same? – Oluwafemi Sule Mar 13 '23 at 10:32
  • Where are you expecting to see that file? It's (presumably) being written to the runner, which is an ephemeral environment. – jonrsharpe Mar 13 '23 at 10:32
  • @OluwafemiSule, file contents are the same – Cat_125 Mar 13 '23 at 11:09
  • Are you writing to the correct location? What if you open the file again via code? – Peter Mar 13 '23 at 11:32
  • If you still need help, please [edit] to provide more details about what you expected and how you determined that the expected output was not found in the file. A very common beginner mistake is looking in the wrong directory; perhaps see also [What exactly is current working directory?](https://stackoverflow.com/questions/45591428/what-exactly-is-current-working-directory) – tripleee Mar 13 '23 at 11:54
  • You actually need to `push` the file after the update, for the changes to appear on the repository after the Github Action workflow run. – GuiFalourd Mar 13 '23 at 13:59

1 Answers1

-2
def write(filename, text):

    with open(filename, 'w') as file:
        file.write(text)

filename = 'example.txt'

text = '12works!'

write(filename, text)

The text is what you going to write into the file

Adriaan
  • 17,741
  • 7
  • 42
  • 75
Fantom_n
  • 1
  • 2
  • 1
    This is unlikely to solve the issue they're having, as it's the same code other than `open` being changed to a context manager. – Peter Mar 13 '23 at 11:31