Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Steelskin committed Nov 5, 2024
0 parents commit c62b957
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 0 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Test

on:
push:
branches:
- main
pull_request:

jobs:
upload-file:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Create executable file
run: |
echo "#!/bin/bash" > hello.sh
echo "echo 'Hello world!'" >> hello.sh
chmod +x hello.sh
- name: Upload artifact
uses: ./
with:
name: hello
path: hello.sh

- name: Delete file
run: rm hello.sh

- name: Download artifact
uses: thebrowsercompany/gha-download-tar-artifact@main
with:
name: hello
path: .

- name: Run executable
run: |
./hello.sh
upload-directory:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Create directory
run: |
mkdir -p hello
echo "Hello world!" > hello/world.txt
echo "#!/bin/bash" > hello/hello.sh
echo "echo 'Hello world!'" >> hello/hello.sh
chmod +x hello/hello.sh
- name: Upload artifact
uses: ./
with:
name: hello
path: hello/

- name: Delete directory
run: rm -rf hello

- name: Download artifact
uses: thebrowsercompany/gha-download-tar-artifact@main
with:
name: hello
path: .

- name: Check permissions
run: |
./hello/hello.sh && ! test -x hello/world.txt
29 changes: 29 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BSD 3-Clause License

Copyright (c) 2024, The Browser Company of New York
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# `@thebrowsercompany/gha-upload-tar-artifact`

Tar and upload [Action Artifacts](https://docs.github.com/en/actions/using-workflows/storing-workflow-data-as-artifacts) from your Workflow Runs. Internally powered by GitHub's [@actions/upload-artifact](https://github.com/actions/upload-artifact) action. This action tars the provided path before using [@actions/upload-artifact](https://github.com/actions/upload-artifact) to upload the tar file, preserving permissions on non-Windows platforms.

See also [gha-uncompress-download](https://github.com/thebrowsercompany/gha-uncompress-download). For further documenation, refer to the [@actions/upload-artifact](https://github.com/actions/upload-artifact) documentation.

- [`@thebrowsercompany/gha-upload-tar-artifact`](#thebrowsercompanygha-upload-tar-artifact)
- [Usage](#usage)
- [Inputs](#inputs)
- [Outputs](#outputs)

## Usage

### Inputs

```yaml
- uses: thebrowsercompany/gha-upload-tar-artifact@main
with:
# Name of the artifact to upload.
name:

# A file or directory that describes what to upload.
# Required.
path:

# Duration after which artifact will expire in days. 0 means using default retention.
# Minimum 1 day.
# Maximum 90 days unless changed from the repository settings page.
# Optional. Defaults to repository settings.
retention-days:
```
### Outputs
| Name | Description | Example |
| - | - | - |
| `artifact-id` | GitHub ID of an Artifact, can be used by the REST API | `1234` |
| `artifact-url` | URL to download an Artifact. Can be used in many scenarios such as linking to artifacts in issues or pull requests. Users must be logged-in in order for this URL to work. This URL is valid as long as the artifact has not expired or the artifact, run or repository have not been deleted | `https://github.com/example-org/example-repo/actions/runs/1/artifacts/1234` |
68 changes: 68 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: 'Tar and upload a path, preserving permissions'
description: 'Upload a build artifact that can be used by subsequent workflow steps, with permissions preserved.'
author: 'The Browser Company of New York'

inputs:
name:
description: 'The name of the artifact to create.'
default: 'artifact'
path:
description: 'The path to compress and upload.'
required: true
retention-days:
description: >
Duration after which artifact will expire in days. 0 means using default retention.
Minimum 1 day.
Maximum 90 days unless changed from the repository settings page.
default: 0

outputs:
artifact-id:
description: >
A unique identifier for the artifact that was just uploaded. Empty if the artifact upload failed.
This ID can be used as input to other APIs to download, delete or get more information about an artifact: https://docs.github.com/en/rest/actions/artifacts
artifact-url:
description: >
A download URL for the artifact that was just uploaded. Empty if the artifact upload failed.
This download URL only works for requests Authenticated with GitHub. Anonymous downloads will be prompted to first login.
If an anonymous download URL is needed than a short time restricted URL can be generated using the download artifact API: https://docs.github.com/en/rest/actions/artifacts#download-an-artifact
This URL will be valid for as long as the artifact exists and the workflow run and repository exists. Once an artifact has expired this URL will no longer work.
Common uses cases for such a download URL can be adding download links to artifacts in descriptions or comments on pull requests or issues.
runs:
using: composite

defaults:
run:
shell: pwsh

steps:
- name: Create Tar Archive
id: create-tar
run: |
$TempDir = New-TemporaryFile | % { Remove-Item $_; New-Item -ItemType Directory -Path $_ }
$TarFile = Join-Path $TempDir "${{ inputs.name }}.tar"
Write-Host "tar-file=$TarFile" >> $env:GITHUB_OUTPUT
tar cf $TarFile -C "${{ inputs.path }}" .
- uses: actions/upload-artifact@v4
id: upload-artifact
with:
name: ${{ inputs.name }}
path: ${{ steps.create-tar.outputs.tar-file }}
retention-days: ${{ inputs.retention-days }}

- name: Delete Temporary Directory
run: |
$TempDir = Split-Path -Parent ${{ steps.create-tar.outputs.tar-file }}
Remove-Item -Recurse $TempDir
- name: Export Outputs
run: |
Write-Host "artifact-id=${{ steps.upload-artifact.outputs.artifact-id }}" >> $env:GITHUB_OUTPUT
Write-Host "artifact-url=${{ steps.upload-artifact.outputs.artifact-url }}" >> $env:GITHUB_OUTPUT

0 comments on commit c62b957

Please sign in to comment.