Skip to content

Commit

Permalink
first version
Browse files Browse the repository at this point in the history
  • Loading branch information
dsaltares committed Feb 25, 2020
1 parent 5537caf commit 3016dd5
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 2 deletions.
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM alpine:latest

RUN apk add --no-cache \
curl \
jq

COPY fetch_github_asset.sh /fetch_github_asset.sh

ENTRYPOINT ["/fetch_github_asset.sh"]
29 changes: 27 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,27 @@
# fetch-gh-release-asset
Github Action to download an asset from a Github release
# Fetch GH Release Asset

This action downloads an asset from a Github release. Private repos are supported.

## Inputs

### `repo`

**Required** The `org/repo`.

### `version`

The release version to fetch from. Default `"latest"`.

### `file`

**Required** The name of the file in the release.

## Example usage

```yaml
uses: dsaltares/fetch-gh-release-asset@master
with:
repo: "dsaltares/godot-wild-jam-18"
version: "latest"
file: "plague-linux.zip"
```
26 changes: 26 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: 'Fetch Github Release Asset'
description: 'Downloads an asset from a Github release'

inputs:
repo:
description: 'org/repo to download from'
required: true
version:
description: 'version of the release to download from'
required: false
default: 'latest'
file:
description: 'name of the file in the release to download'
required: true

runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.repo }}
- ${{ inputs.version }}
- ${{ inputs.file }}

branding:
icon: 'download-cloud'
color: 'orange'
31 changes: 31 additions & 0 deletions fetch_github_asset.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

if [[ -z "$GITHUB_TOKEN" ]]; then
echo "Missing GITHUB_TOKEN env variable"
exit 1
fi

if [[ -z "$INPUT_REPO" ]]; then
echo "Missing repo input in the action"
exit 1
fi

if [[ -z "$INPUT_FILE" ]]; then
echo "Missing file input in the action"
exit 1
fi

API_URL="https://$GITHUB_TOKEN:@api.github.com/repos/$INPUT_REPO"
ASSET_ID=$(curl $API_URL/releases/${INPUT_VERSION} | jq -r ".assets | map(select(.name == \"${INPUT_FILE}\"))[0].id")

if [[ -z "$ASSET_ID" ]]; then
echo "Could not find asset id"
exit 1
fi

curl \
-J \
-L \
-H "Accept: application/octet-stream" \
"$API_URL/releases/assets/$ASSET_ID" \
-o ${INPUT_FILE}

0 comments on commit 3016dd5

Please sign in to comment.