Skip to content

Commit

Permalink
Add token, repo and sha input (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
n-elie committed Oct 27, 2023
1 parent 470b693 commit ea75e8f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ jobs:
asset_name: myapp_windows-nightly-$$.zip # name to upload the release as, use $$ to insert date (YYYYMMDD) and 6 letter commit hash
asset_content_type: application/zip # required by GitHub API
max_releases: 7 # optional, if there are more releases than this matching the asset_name, the oldest ones are going to be deleted
token: *** # optional, a github token. defaults to GITHUB_TOKEN
sha: 547fdf5 # optional, a commit SHA. Defaults to GITHUB_SHA
repo: Pure-D/serve-d # optional, the repository where the release is located
```
12 changes: 12 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ inputs:
description: 'Maximum number of historical releases with the given asset_name to keep'
required: false
default: 7
token:
description: 'The Github token.'
required: false
default: ${{ github.token }}
repo:
description: "Optionally specify the repo where the release is located. Defaults to current repo"
required: false
default: ${{ github.repository }}
sha:
description: "Optionally specify the commit SHA. Defaults to SHA that triggered the workflow"
required: false
default: ${{ github.sha }}

output:
uploaded:
Expand Down
18 changes: 8 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,21 @@ async function uploadAsset(octokit, name) {

async function run() {
try {
const token = core.getInput("token", { required: false });
const sha = core.getInput("sha", { required: false });
let repo = core.getInput("repo", { required: false });
const maxReleases = parseInt(core.getInput("max_releases", { required: false }));
const releaseId = core.getInput("release_id", { required: true });
let name = core.getInput("asset_name", { required: true });
const placeholderStart = name.indexOf("$$");
const nameStart = name.substring(0, placeholderStart);
const nameEnd = name.substring(placeholderStart + 2);

if (!process.env.GITHUB_TOKEN
|| !process.env.GITHUB_SHA
|| !process.env.GITHUB_REPOSITORY)
throw new Error("Missing required GitHub environment variables!");

const octokit = getOctokit(process.env.GITHUB_TOKEN);
const hash = process.env.GITHUB_SHA.substring(0, 6);
const repository = process.env.GITHUB_REPOSITORY.split('/');

const octokit = getOctokit(token);
const hash = sha.substring(0, 6);
const repository = repo.split('/');
const owner = repository[0];
const repo = repository[1];
repo = repository[1];

core.info("Checking previous assets");
let assets = await octokit.rest.repos.listReleaseAssets({
Expand Down

0 comments on commit ea75e8f

Please sign in to comment.