Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Using Python in a Workflow

00:00 Let’s start the section of this video course with a task. Add a new workflow to your repository that displays the current Python version of the Ubuntu latest virtual machine when you push the code to the remote repository.

00:13 At this point, you should have an idea how to tackle the task yourself, so if you want, you can pause this video course and build the workflow yourself, and then join me again and I’ll show you how I would build it.

00:27 Inside .github/workflows/ create a new file named hello_python.yaml.

00:36 First, give it a nice name, for example, Hello Python! Then define the trigger. So in this case, it’s again on: push, and then start a jobs section with the job run_python.

00:54 Continue by using a descriptive name. So for example, Run Ubuntu's Python, and it should run on ubuntu-latest. So the property is runs-on: with a colon again.

01:10 Then on the same indentation line, continue with steps: and as the one step, again, start it with a - run:. Let’s just output the Python version, so python -- version. Save the file and commit it, and then check the workflow in the browser.

01:42 Alright, so the workflow ran on push, and when you go into the logs, then you can see the current Python version that Ubuntu uses. As of this recording, it’s 3.12.3, but depending on when you watch this course, the Python version could be a different one.

02:02 That means just using the Ubuntu Python is not so ideal because usually when you run Python code, you want to specifically know which Python version to use.

02:14 So that workflow could definitely use some improvements. To improve this workflow, you will leverage existing GitHub Actions. So let’s explore them for a moment in the next lesson.

Become a Member to join the conversation.