diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..34c8871 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,73 @@ +name: Test + +on: + push: + branches: + - main + pull_request: + workflow_dispatch: + +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: thebrowsercompany/gha-upload-tar-artifact@main + with: + name: hello-file + path: hello.sh + + - name: Delete file + run: rm hello.sh + + - name: Download artifact + uses: ./ + with: + name: hello-file + 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: thebrowsercompany/gha-upload-tar-artifact@main + with: + name: hello-dir + path: hello/ + + - name: Delete directory + run: rm -rf hello + + - name: Download artifact + uses: ./ + with: + name: hello-dir + path: hello/ + + - name: Check permissions + run: | + ./hello/hello.sh && ! test -x hello/world.txt \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..919ada1 --- /dev/null +++ b/LICENSE @@ -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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..2b96728 --- /dev/null +++ b/README.md @@ -0,0 +1,33 @@ +# `@thebrowsercompany/gha-download-tar-artifact` + +Download and untar [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/download-artifact](https://github.com/actions/download-artifact) action. This action uses [@actions/download-artifact](https://github.com/actions/download-artifact) to download the tar file and untar it, preserving permissions on non-Windows platforms. + +See also [gha-upload-tar-artifact](https://github.com/thebrowsercompany/gha-upload-tar-artifact). For further documentation, refer to the [@actions/download-artifact](https://github.com/actions/download-artifact) documentation. + +- [`@thebrowsercompany/gha-download-tar-artifact`](#thebrowsercompanygha-download-tar-artifact) + - [Usage](#usage) + - [Inputs](#inputs) + - [Outputs](#outputs) + +## Usage + +### Inputs + +```yaml +- uses: thebrowsercompany/gha-upload-tar-artifact@main + with: + # Name of the artifact to download. If unspecified, defaults to `artifact`. + name: + + # Destination path. + # Required. + path: +``` + +### Outputs + +| Name | Description | Example | +| - | - | - | +| Name | Description | Example | +| - | - | - | +| `download-path` | Absolute path where the artifact(s) were downloaded | `/tmp/my/download/path` | diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..d0e1bf3 --- /dev/null +++ b/action.yml @@ -0,0 +1,50 @@ +name: 'Download and untar an artifact, preserving permissions' +description: 'Download a build artifact that was previously uploaded in the workflow by the gha-upload-tar-artifact action, with permissions preserved.' +author: 'The Browser Company of New York' + +inputs: + name: + description: 'The name of the artifact to download.' + default: 'artifact' + required: true + path: + description: 'Destination path. Defaults to $GITHUB_WORKSPACE.' + default: ${{ github.workspace }} + + outputs: + download-path: + description: 'Path of artifact download' + +runs: + using: composite + + steps: + - name: Create Temporary Directory + shell: pwsh + id: create-temp-dir + run: | + $TempDir = New-TemporaryFile | % { Remove-Item $_; New-Item -ItemType Directory -Path $_ } + echo "temp-dir=$TempDir" >> $env:GITHUB_OUTPUT + + - name: Download Artifact + uses: actions/download-artifact@v4 + with: + name: ${{ inputs.name }} + path: ${{ steps.create-temp-dir.outputs.temp-dir }} + + - name: Extract Tar Archive + shell: pwsh + id: extract-tar + run: | + New-Item -ItemType Directory -Path "${{ inputs.path }}" -Force | Out-Null + $TarFile = Join-Path "${{ steps.create-temp-dir.outputs.temp-dir }}" "${{ inputs.name }}.tar" + tar xf $TarFile -C ${{ inputs.path }} + + - name: Delete Temporary Directory + shell: pwsh + run: Remove-Item -Recurse ${{ steps.create-temp-dir.outputs.temp-dir }} + + - name: Export Output + shell: pwsh + run: | + Write-Output "download-path=${{ inputs.path }}" >> $env:GITHUB_OUTPUT