Lessons

Zip Code Base with Github Actions for Releases

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

Code Base Setup

You will need a Github repository and access to Github Actions. First step, clone your repository and switch into it. We will begin to create empty files in the folder. These files represent a simple app.

1 2 3 touch README.md touch main.py touch .gitignore

Push the changes to the master branch.

1 2 3 git add --all git commit -m "Added basic files" git push

Workflow Setup

We will use the zip command: zip -r release.zip .. This is zip into a file called release.zip and zip up the current directory (.).

Create a workflow here:

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

The contents should be:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 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:

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

Screenshot of Github Workflow Running

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):

Screenshot of Github Workflow Running

Update the workflow to be:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 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

We are going to use this release/tagging. You can look at this awesome list of actions for a range of actions.

Update the workflow to be:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 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

Screenshot of Github Workflow Running

Screenshot of Github Workflow Running

Screenshot of Github Workflow Running

You can download the source code.