Marinus Klasen

Marinus Klasen

  • Development
  • Consultancy
  • Developer Resources
  • Blog
  • Contact

August 27, 2021

Github action: Automatically add a ZIP asset for each new release

Marinus Klasen

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.

About Marinus Klasen

Marinus has been working in software/web development for more than a decade. Since 2020 his attention shifted on sharing knowledge and developing products and tools for sharing knowledge.

Marinus Klasen on Twitter

Looking for a WordPress expert?
Hire top notch developers on Codeable!

Consult an expert

Comments

  1. SimDala says

    October 13, 2022 at 8:16 am

    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

    Reply
    • Marinus Klasen says

      October 13, 2022 at 8:34 am

      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

      Reply
      • SimDala says

        October 17, 2022 at 8:51 am

        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.

        Reply
      • SimDala says

        October 31, 2022 at 8:50 am

        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.

        Reply
        • Marinus Klasen says

          October 31, 2022 at 9:19 am

          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 }}

          Reply
          • SimDala says

            November 21, 2022 at 3:43 pm

            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

            November 21, 2022 at 3:59 pm

            Hi! I’ve setup a public Github Repo with working code here: https://github.com/mklasen/zip-creation-github-action

  2. SimDala says

    November 23, 2022 at 10:22 am

    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.

    Reply
    • Marinus Klasen says

      November 30, 2022 at 11:15 am

      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

      Reply
      • SimDala says

        December 11, 2022 at 11:33 pm

        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?

        Reply
        • Marinus Klasen says

          December 12, 2022 at 9:34 am

          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.

          Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Get in touch

Contact me using the details below

Marinus Klasen

Wilhelmina van Pruisenweg 35, 2595 AN Den Haag

marinus@mklasen.com
twitter.com/marinusklasen
linkedin.com/in/marinusklasen

  • GitHub
  • LinkedIn
  • Twitter

Have you read?

  • Elementor Widget UsageMarch 27, 2025
  • Programmatically showing popups with ElementorMarch 25, 2025
  • The Elementor sanitize_settings errorSeptember 12, 2024
  • Announcing.. Wooping Shop Health!June 13, 2024
  • Swiper setup when using wp-scriptsMarch 14, 2024

Copyright © 2025 ยท Marinus Klasen | Webdesign by Team Rood