canovasjm / covid-19-san-juan

MIT License
11 stars 11 forks source link

Python file creation in the repo path #2

Open jairamjidgekar opened 2 years ago

jairamjidgekar commented 2 years ago

Hi San, Thank you for your blog regarding file creation using PYTHON script.
I have a similar requirement.

For testing purpose, I am having sample .py code, which creates a file ( simple dummy file). But , when I run the job via actions, it's not creating the file ... It runs successfully, but the file is not generating. Kindly help.

In your py code, I can see that you have directly used the "data/" (relative path). How is it picking the file? I don't see any code in your py code that it creates the file in the current path (data/).

Even I have placed the python code in the same repo path and the file which I want to create also is present in the same path.

Please have a look at my below code.

Python code:

import os print("Start of File") cwd = os.getcwd() # Get the current working directory (cwd) files = os.listdir(cwd) # Get all the files in that directory print("Files in %r: %s" % (cwd, files)) f = open("/home/runner/work/country_profile/country_profile/QWC.txt", "w") f.write("Now the file has more content!") f.close() print("End of File")

.yml code: ( I am not using any secrets).

name: Python Test run file

on: push: branches: [ "main" ] pull_request: branches: [ "main" ]

workflow_dispatch:

jobs: build: runs-on: ubuntu-latest

steps:
  - uses: actions/checkout@v3

  - name: Run python script test file
    run: python python_test.py

  - name: commit files
    run: |
      git config --local user.email "action@github.com"
      git config --local user.name "GitHub Action"
      git add -A
      git commit -m "update data" -a
jairamjidgekar commented 2 years ago

image

jairamjidgekar commented 2 years ago

image