Skip to content

Commit 5e6896d

Browse files
author
Paweł Galerczyk
committed
Init
0 parents  commit 5e6896d

File tree

4 files changed

+201
-0
lines changed

4 files changed

+201
-0
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 David Saltares
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Fetch GH Release Asset
2+
3+
This action downloads an asset from a GitHub release and provides some release details as output. Private repos are supported.
4+
I modify orginally [@dsaltares/fetch-gh-release-asset](https://github.com/dsaltares/fetch-gh-release-asset) to work on composite action insteed docker.
5+
6+
When you use self-hosted github runner in docker, shared directory with workspace doesn't work. So this is why i decade to use composite action.
7+
8+
thx [dsaltares](https://github.com/dsaltares) for orginal bash script!
9+
10+
## Inputs
11+
12+
### `token`
13+
14+
**Required** The GitHub token. Typically this will be `${{ secrets.GITHUB_TOKEN }}`
15+
16+
### `file`
17+
18+
**Required** The name of the file to be downloaded.
19+
20+
### `repo`
21+
22+
The `org/repo` containing the release.
23+
24+
### `version`
25+
26+
The release version to fetch from in the form `tags/<tag_name>` or `<release_id>`. Defaults to `latest`.
27+
28+
### `target`
29+
30+
Target file path. Only supports paths to subdirectories of the GitHub Actions workspace directory
31+
32+
## Outputs
33+
34+
### `version`
35+
36+
The version number of the release tag. Can be used to deploy for example to itch.io
37+
38+
### `name`
39+
40+
[Also called a title of a release](https://docs.github.com/en/github/administering-a-repository/managing-releases-in-a-repository). Defaults to the same value as `version` if not specified when creating a release.
41+
42+
### `body`
43+
44+
The body (description) of a release.
45+
46+
## Example usage
47+
48+
```yaml
49+
uses: dsaltares/fetch-gh-release-asset@master
50+
with:
51+
repo: "paweb88/fetch-gh-release-asset"
52+
version: "tags/v0.1.18"
53+
file: "plague-linux.zip"
54+
target: "subdir/plague-linux.zip"
55+
token: ${{ secrets.GITHUB_TOKEN }}
56+
```
57+
58+
## Support
59+
60+
This action only supports Linux runners as this is a [docker container](https://docs.github.com/en/actions/creating-actions/about-actions#types-of-actions) action. If you encounter `Error: Container action is only supported on Linux` then you are using non-linux runner.

action.yaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: 'Fetch Github Release Asset as Composite Actions'
2+
description: 'Downloads an asset from a Github release'
3+
4+
inputs:
5+
repo:
6+
description: 'The `org/repo` containing the release.'
7+
required: false
8+
default: ''
9+
version:
10+
description: 'The release version to fetch from in the form `tags/<tag_name>` or `<release_id>`.'
11+
required: false
12+
default: 'latest'
13+
file:
14+
description: 'The name of the file to be downloaded.'
15+
required: true
16+
target:
17+
description: 'Target file path.'
18+
required: false
19+
token:
20+
description: 'The GitHub token. Typically this will be secrets.GITHUB_TOKEN'
21+
required: true
22+
23+
runs:
24+
using: 'composite'
25+
steps:
26+
- run: ${{ github.action_path }}/fetch_github_asset.sh
27+
shell: bash
28+
id: fetch
29+
env:
30+
INPUT_REPO: ${{ inputs.repo }}
31+
INPUT_VERSION: ${{ inputs.version }}
32+
INPUT_FILE: ${{ inputs.file }}
33+
INPUT_TARGET: ${{ inputs.target }}
34+
INPUT_TOKEN: ${{ inputs.token }}
35+
36+
outputs:
37+
version:
38+
description: 'The version of the release or tag'
39+
value: ${{ steps.fetch.outputs.version }}
40+
name:
41+
description: 'The name of the release'
42+
value: ${{ steps.fetch.outputs.name }}
43+
body:
44+
description: 'The body of the release'
45+
value: ${{ steps.fetch.outputs.body }}
46+
47+
branding:
48+
icon: 'download-cloud'
49+
color: 'orange'

fetch_github_asset.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/bash
2+
3+
if [[ -z "$INPUT_FILE" ]]; then
4+
echo "Missing file input in the action"
5+
exit 1
6+
fi
7+
8+
if [[ -z "$GITHUB_REPOSITORY" ]]; then
9+
echo "Missing GITHUB_REPOSITORY env variable"
10+
exit 1
11+
fi
12+
13+
REPO=$GITHUB_REPOSITORY
14+
if [[ -n ${INPUT_REPO} ]]; then
15+
REPO=$INPUT_REPO
16+
fi
17+
18+
# Optional target file path
19+
TARGET=$INPUT_FILE
20+
if [[ -n ${INPUT_TARGET} ]]; then
21+
TARGET=$INPUT_TARGET
22+
fi
23+
24+
# Optional personal access token for external repository
25+
TOKEN=$GITHUB_TOKEN
26+
if [[ -n ${INPUT_TOKEN} ]]; then
27+
TOKEN=$INPUT_TOKEN
28+
fi
29+
30+
API_URL="https://api.github.com/repos/$REPO"
31+
RELEASE_DATA=$(curl ${TOKEN:+"-H"} ${TOKEN:+"Authorization: token ${TOKEN}"} \
32+
"$API_URL/releases/${INPUT_VERSION}")
33+
MESSAGE=$(echo "$RELEASE_DATA" | jq -r ".message")
34+
35+
if [[ "$MESSAGE" == "Not Found" ]]; then
36+
echo "[!] Release asset not found"
37+
echo "Release data: $RELEASE_DATA"
38+
echo "-----"
39+
echo "repo: $REPO"
40+
echo "asset: $INPUT_FILE"
41+
echo "target: $TARGET"
42+
echo "version: $INPUT_VERSION"
43+
exit 1
44+
fi
45+
46+
echo "MESSAGE: '$RELEASE_DATA'"
47+
48+
ASSET_ID=$(echo "$RELEASE_DATA" | jq -r ".assets | map(select(.name == \"${INPUT_FILE}\"))[0].id")
49+
TAG_VERSION=$(echo "$RELEASE_DATA" | jq -r ".tag_name" | sed -e "s/^v//" | sed -e "s/^v.//")
50+
RELEASE_NAME=$(echo "$RELEASE_DATA" | jq -r ".name")
51+
RELEASE_BODY=$(echo "$RELEASE_DATA" | jq -r ".body")
52+
53+
if [[ -z "$ASSET_ID" ]]; then
54+
echo "Could not find asset id"
55+
exit 1
56+
fi
57+
58+
curl \
59+
-J \
60+
-L \
61+
-H "Accept: application/octet-stream" \
62+
${TOKEN:+"-H"} ${TOKEN:+"Authorization: token ${TOKEN}"} \
63+
"$API_URL/releases/assets/$ASSET_ID" \
64+
--create-dirs \
65+
-o "${TARGET}"
66+
67+
echo "$TAG_VERSION"
68+
69+
echo "::set-output name=version::$TAG_VERSION"
70+
echo "::set-output name=name::$RELEASE_NAME"
71+
echo "::set-output name=body::$RELEASE_BODY"

0 commit comments

Comments
 (0)