Skip to content

Create an actions/create-archive action

Current situation

We often need to make an archive and attach this archive. This is repetitive.

Desired outcome

A actions/create-archive action, with the following parameters:

  • path: (required) the archive name, relative to the current working directory.
  • patterns: (required) a list of directory or file name patterns, relative to the current directory, possibly with paths. They may contain placeholders (* or **). They follow the actions/get-files pattern parameter conventions.
  • The placeholder (*) in a subdirectory is not supported in Windows environment.
  • format: (optional) the archive format, either tar or tar.gz if specified, defaulting to tar.gz if not specified.
  • warn-if-not-found: (optional) a boolean, defaulting to false.

It creates the archive, but does not attach it.

Sample usage:

Basic

- uses: actions/create-archive@v1
  with:
    path: myarchive.tar.gz
    patterns:
    - 'screenshots/*.svg'
    - foo.html
    - bar/
    - '**/*.png'
- uses: actions/get-file@v1
  with:
    path: myarchive.tar.gz

By default, empty archives are not possible. create-archive will return a non-zero status code if the specified patterns match no files and may generate an error log entry ('The specified patterns do not match any files.' or some similar description).

Advanced

If the warn-if-not-found input is set to true, empty archives are allowed, and a warning is issued if the specified patterns match no files. The action will return a zero status code and the archive file will contain no files.

- uses: actions/create-archive@v1
  with:
    path: myarchive.tar.gz
    patterns:
    - 'screenshots/*.svg'
    - bar/foo.html
    - foo/bar/
    - '**/foo.bar'
    warn-if-not-found: true
- uses: actions/get-file@v1
  with:
    path: myarchive.tar.gz

There will be a myarchive.tar.gz file, which may contain no files. If it contains no files, a warning is generated ('The specified patterns do not match any files.' or some similar description).

Analysis

Solution

Edited by Jean-Marc BELORGANE