Zip Code Base with Github Actions for Releases

The original post can be found here.

In this tutorial, we will use Github Actions to zip the code base and create a new release with it.

Code Base Setup

touch README.md
touch main.py
touch .gitignore

Push the changes to the master branch.

git add --all
git commit -m "Added basic files"
git push

Workflow Setup

Create a workflow here:

mkdir -p ./.github/workflows/
touch ./.github/workflows/master.yml

The contents should be:

name: MasterDeployCI
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Zip Folder
run: zip -r release.zip .
- name: Release to Github
run: echo "Release"

Then push your changes to the remote repository:

git add --all
git commit -m "Added workflow for master"
git push

As you can see it worked, but we zipped too much. We don’t want to zip the .git folder, the .github folder or the .gitignore file.

We can use -x. We can also test this locally (if on Ubuntu or OSx):

name: MasterDeployCI
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Zip Folder
run: zip -r release.zip . -x ".git/*" ".github/*"
- name: Release to Github
run: echo "Release"

Release

Update the workflow to be:

name: MasterDeployCI
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Create Release Folder
run: rsync -arv --exclude='.git/' --exclude='.github/' --exclude='.gitignore' . ./release
- name: Switch to Release Folder
run: |
cd release
ls -la
- name: Bump version and push tag
uses: anothrNick/github-tag-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO_OWNER: keithweaver

You can download the source code.

Thanks for reading! Follow me for more.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store