From 4b48cb9aedb9eb317d4ea7ea13bf17a2fcc3455a Mon Sep 17 00:00:00 2001 From: Jan Jurzitza Date: Fri, 27 Oct 2023 07:43:49 +0000 Subject: [PATCH] readd token/repo/sha inputs again Co-authored-by: Nicolas Elie <40382614+n-elie@users.noreply.github.com> --- README.md | 20 ++++++++++++++------ action.yml | 12 ++++++++++++ index.js | 21 ++++++++++++--------- 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index f70bd72..194e069 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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///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) @@ -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 ``` diff --git a/action.yml b/action.yml index 1b665c5..61e2d0d 100644 --- a/action.yml +++ b/action.yml @@ -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: diff --git a/index.js b/index.js index dd0ec63..6583b1d 100644 --- a/index.js +++ b/index.js @@ -35,6 +35,14 @@ 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 }); @@ -42,16 +50,11 @@ async function run() { 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({