The code below will automatically create a new asset for each new release that you publish on Github. Add it to your repository in a .github/workflow/
folder and experience the magic yourself!
Update: I’ve also setup a sample repository with working code here:
https://github.com/mklasen/zip-creation-github-action
Direct link to the workflow file: https://github.com/mklasen/zip-creation-github-action/blob/master/.github/workflows/release-action.yml
After a new release is created, a ZIP file will be added to the new release after the action ran, see an example release here: https://github.com/mklasen/zip-creation-github-action/releases/tag/v4
Original example code
Note: this snippet is created for PHP based repositories that user composer. If your repository does not use composer then you should remove the steps on line 15, 19 and 26 and customize the script to your needs.
SimDala says
Hi!
Nice effort, directly what I’m looking for, but I got no magic directly from trying:
##[debug]Evaluating condition for step: ‘Install dependencies’
##[debug]Evaluating: success()
##[debug]Evaluating success:
##[debug]=> true
##[debug]Result: true
##[debug]Starting: Install dependencies
##[debug]Loading inputs
##[debug]Loading env
Run composer install -o -q
##[debug]/usr/bin/bash -e /home/runner/work/_temp/8ac2e495-fed6-4b5e-b75f-0aa9e3a36a0c.sh
Error: Process completed with exit code 1.
##[debug]Finishing: Install dependencies
Marinus Klasen says
Did you customize the action according to your repo? Ex: if your repository does not use composer, you can remove that part of the script.
- name: Install dependencies
run: |
composer install -o -q
SimDala says
I didn’t look so deep into the action more than I saw that there was an issue connected to installing dependencies.
It may probably be so that my repo don’t use composer. At least I haven’t added that dependency so my repo is quite standard repo on github.
SimDala says
Hi again,
Is the composer in the script the Composer for manage PHP or is there another composer too?
My purpose is to create customizable zip-files automatically on new release and I haven’t yet added any addons to my github repo. Just want the solution to be as clean and smooth as possible.
My instant thought is that it shouldn’t be needed so much extra since github is creating a zip and tar file of the whole project as default on release.
Marinus Klasen says
I have not tested this, but you could probably slim it down to this and then extend the ZIP command with files that you’d like to exclude from the ZIP. `(-x file1.txt file2.txt)`
name: Create release
on:
release:
types:
- created
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Zip Folder
run: zip -r ${{ github.event.repository.name }}.zip .
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: ${{ github.event.repository.name }}.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SimDala says
Hi again. Is there some documentation about how the zip line should look like?
It reports some error before the -name:Release and the error differs if I change the first line from name: to -name:
Marinus Klasen says
Hi! I’ve setup a public Github Repo with working code here: https://github.com/mklasen/zip-creation-github-action
SimDala says
Ah, great, thanks a lot for that help. It worked great.
Now when the action works fine, I have some problem with the format of the zip-file.
What I’m trying to achieve is a zip-file created from the content in a subfolder named the same as the project name.
The zip-file shall not contain the folder itself, just the content of the subfolder and include all subfolders and files.
I tried a few different ways but not succeeded yet.
Is it possible to change folder before the zip command like:
cd ${{ github.event.repository.name }}; zip ..\${{ github.event.repository.name }}.zip .; cd ..
I know that the above line isn’t working but I think you get the idea.
If i’m using zip ${{ github.event.repository.name }}.zip . ${{ github.event.repository.name }}/*
I get the name of the subfolder stored at the root in the zip-file.
Marinus Klasen says
If you haven’t done already, I recommend experimenting with this from the command line first, until you found a working solution, and then adding it to Github actions.
I think you can change the working directory for each step as well, that might help? Also check out https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
SimDala says
I thought about that too, but it’s not the same on command line and within the action, so it’s quite hard to compare them. Did I mention that this is on a Windows machine?
I didn’t have a Unix system available when trying.
Did you see that I wrote to you directly on github btw?
Marinus Klasen says
True, consider using WSL2 to run an Ubuntu installation within Windows, works great!!
Thanks for mentioning the Github issue, I did not see it before.