Skip to content

Commit

Permalink
readd token/repo/sha inputs again
Browse files Browse the repository at this point in the history
Co-authored-by: Nicolas Elie <40382614+n-elie@users.noreply.github.com>
  • Loading branch information
WebFreak001 and n-elie committed Oct 27, 2023
1 parent 8721b99 commit 4b48cb9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 15 deletions.
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ Deploy a nightly release to a GitHub release. Supports deleting old nightlys and

name: Deploy Nightly
on:
# This can be used to automatically publish nightlies at UTC nighttime
schedule:
- cron: '0 2 * * *' # run at 2 AM UTC
# This can be used to allow manually triggering nightlies from the web interface
workflow_dispatch:

jobs:
nightly:
Expand All @@ -25,8 +28,6 @@ jobs:
- name: Deploy Windows release
if: matrix.os == 'windows-latest'
uses: WebFreak001/deploy-nightly@v2.0.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # automatically provided by github actions
with:
upload_url: https://uploads.github.com/repos/Pure-D/serve-d/releases/20717582/assets{?name,label} # find out this value by opening https://github.com/gitapi/repos/<owner>/<repo>/releases in your browser and copy the full "upload_url" value including the {?name,label} part
release_id: 20717582 # same as above (id can just be taken out the upload_url, it's used to find old releases)
Expand All @@ -38,10 +39,17 @@ jobs:

### Advanced Use

if you want to publish a release to another repository, or just from outside a release-event, manually provide the environment variables
if you want to publish a release to another repository or from a different commit, you can configure the API token, API repository endpoint and commit sha for the generated filename like this:

```yml
env:
GITHUB_SHA: 547fdf5 # used for checking for existing files / the filename (only the first 6 characters are used)
GITHUB_REPOSITORY: Pure-D/serve-d # this is where the API calls go to list asset files, must match the upload_url
with:
# can be used to specify a custom token, otherwise defaults to the auto
# generated token for the current GitHub Action context `${secrets.GITHUB_TOKEN}`
token: ${secrets.MyCustomToken}
# used for checking for existing files by inserting into the filename (only
# the first 6 characters are used)
sha: 547fdf5
# this is where the API calls go to list asset files, must match the repo from
# the upload_url
repo: Pure-D/serve-d
```
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 repository ("OwnerName/RepoName") where the release is located. Defaults to current repository'
required: false
default: ${{ github.repository }}
sha:
description: 'Optionally specify the commit SHA for release filename. Defaults to SHA that triggered the workflow. Only the first 6 characters are used'
required: false
default: ${{ github.sha }}

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

async function run() {
try {
// was the previous way before this was an action 'with' input
const token_env = process.env.GITHUB_TOKEN || "";
if (token_env != "")
core.warning("This action no longer uses the GITHUB_TOKEN environment variable. You can simply remove the environment variable if it's `${secrets.GITHUB_TOKEN}` or migrate to setting `with: token: ...` instead. Setting this environment variable will be ignored in the future.");

const token = token_env != "" ? token_env : 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 4b48cb9

Please sign in to comment.