1

I'm trying to write a GitHub Actions workflow which can zip up my entire repository. I have written it as such:

name: Zip repository and put on S3
on: [workflow_dispatch]

jobs:
  zip-n-push:
    name: Zip and Push
    runs-on: ubuntu-latest
    steps:
      - name: Zip Folder
        run: |
          rm -rf <repository_name>.zip
          zip -r <repository_name>.zip <repository_name> -x ".git/*" ".github/*"

Upon running it, I get an error saying:

zip error: Nothing to do! (<repository_name>.zip).

Am I doing something wrong? What should I change here? Thanks in advance.

I expect this action to create a .zip file of my repository. I intend to send that zip file to an AWS S3 bucket, but I need to clear this roadblock first.

Azeem
  • 11,148
  • 4
  • 27
  • 40
Shiv
  • 23
  • 2

3 Answers3

1

GitHub Actions won't automatically fetch the code from the repository. You need to add something like checkout to retrieve the code. (This is done on purpose, in case you need to set up an environment before getting code.)

Jim Redmond
  • 4,139
  • 1
  • 14
  • 18
1

TLDR: Use git to create the zip archive, Github builds on top of it and has support for that. Therefore get the files you want to archive out of the git repository first (archive or fetch+checkout+zip).


You can control creating the (zip) archive of your repository with the git-archive(1) command and optional .gitattributes file(s) (specifically Creating an archive), that you can commit to the repository as well.

# git-archive: ignore .gitignore, .gitattributes, .github/ etc. 
.git* export-ignore

Not only could you then use the git archive command then to create the zip (compare: How do I export my project as a .zip of git repository?, Github is already offering a download for it.

Using that link then would spare you to run the checkout action (compare: How to download .zip from GitHub for a particular commit sha?), however you can also do the checkout and use the git archive or zip command-line to create a more tailored zip. It then requires the checkout action (compare: GitHub - jobs : what is : use actions/checkout).

hakre
  • 193,403
  • 52
  • 435
  • 836
1

You are getting zip error: Nothing to do! (<repository_name>.zip). because there does not exist a folder by the name you provided, you can go a directory back using cd ../ before your other scripts

name: Zip repository and put on S3
on: [workflow_dispatch]

jobs:
  zip-n-push:
    name: Zip and Push
    runs-on: ubuntu-latest
    steps:
      - name: Zip Folder
        run: |
          cd ../ # I added this
          rm -rf <repository_name>.zip
          zip -r <repository_name>.zip <repository_name> -x ".git/*" ".github/*"

I hope this helps!

Umair Jibran
  • 423
  • 4
  • 9