Maintaining a Python Package with GitHub Actions
Tags: githubhack23, python, github, opensource
Published: 2023-05-20 16:43:04

## What I built

A hangman game created using Python and distributed as a Python package through [PyPI](https://pypi.org/). It utilizes GitHub actions to test and lint the code whenever there is a push or pull request to the main branch. Additionally, whenever a new release is created, the new version of the package is automatically deployed to PyPI.

### Category Submission: 

Wacky Wildcards

### App Link

Package on PyPI: https://pypi.org/project/hangman-package/

### Screenshots

Demonstration of the game in GitHub Codespaces:
![Demonstration](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hl3mlq6va7jurugoip92.gif)

### Description

The game can be installed using pip.
```
pip install hangman-package
```
To play, you just need to import the package, create an instance of the Hangman class and call the `play` method.
```python
from hangman import Hangman

hangman = Hangman()
hangman.play()
```
You can pass a list of words to the Hangman class to utilize custom words. By default, the words are a list of programming language names.
```python
hangman = Hangman(words=['apple', 'banana', 'orange', 'melon'])
```

### Link to Source Code

Github repository: https://github.com/viniciusenari/hangman-package

### Permissive License 

MIT License

## Background (What made you decide to build this particular app? What inspired you?) 

I wanted to build something with GitHub Actions to learn the basics of how it works. Since I am most comfortable working with Python, I looked for workflow templates available for Python and found two that could be helpful in maintaining a Python package.

![Workflow templates](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ng385ksaf8fs82h1tu1f.png)

I wasn't sure what to build for a package, so I ended up going with the first idea that came to mind—a hangman game. While it's not an original idea, it served its purpose of allowing me to utilize and learn more about GitHub Actions.

### How I built it (How did you utilize GitHub Actions or GitHub Codespaces? Did you learn something new along the way? Pick up a new skill?)

I utilized two GitHub actions workflows, one for [testing and linting](https://github.com/viniciusenari/hangman-package/blob/main/.github/workflows/python-package.yml) and another one for [publishing my package](https://github.com/viniciusenari/hangman-package/blob/main/.github/workflows/python-publish.yml). The workflow for testing and linting is triggered whenever there is a push or a pull request to the main branch. It utilizes the pytest library to run tests and flake8 to lint, ensuring that the code follows conventions and works correctly. It runs against multiple Python versions.

The workflow for publishing is triggered when a new release is created. It utilizes the build command to create a distributable version of the package and publishes it to PyPI.

Overall, I learned how to utilize these workflows to automate important tasks in my development process, making it easier to maintain code quality and distribute my package.

In addition to GitHub Actions, I also utilized GitHub Codespaces to experiment with my package. Without needing to rely on my local development environment, I was able to test the package.

### Additional Resources/Info
https://en.wikipedia.org/wiki/Hangman_(game)