From e3f6ffe2878180f57318bf13febd3933ee81f664 Mon Sep 17 00:00:00 2001 From: Bryan Paxton <39971740+starbelly@users.noreply.github.com> Date: Fri, 6 Jan 2023 10:14:27 -0600 Subject: [PATCH] Provide an input for github tokens (#172) * Provide an input for github tokens - By providing an input for github tokens with a default users no longer have to pass the github token via their environment across workflows. - Remove GITHUB_TOKEN from our environment in all workflows * Don't run workflows on main on pull requests Co-authored-by: Paulo F. Oliveira --- .github/workflows/action.yml | 6 +----- .github/workflows/ubuntu.yml | 6 +----- .github/workflows/update_3rd_party_licenses.yml | 2 -- .github/workflows/windows.yml | 6 +----- action.yml | 9 +++++++++ dist/index.js | 7 +++++-- src/setup-beam.js | 7 +++++-- 7 files changed, 22 insertions(+), 21 deletions(-) diff --git a/.github/workflows/action.yml b/.github/workflows/action.yml index 39add08..43a7dbe 100644 --- a/.github/workflows/action.yml +++ b/.github/workflows/action.yml @@ -6,11 +6,7 @@ on: branches: - main pull_request: - branches: - - main - -env: - GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} + types: [opened, synchronize] jobs: check_integrity: diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index bc2aaa4..f3ffd83 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -6,11 +6,7 @@ on: branches: - main pull_request: - branches: - - main - -env: - GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} + types: [opened, synchronize] jobs: integration_test: diff --git a/.github/workflows/update_3rd_party_licenses.yml b/.github/workflows/update_3rd_party_licenses.yml index a5b45c8..42ac4d4 100644 --- a/.github/workflows/update_3rd_party_licenses.yml +++ b/.github/workflows/update_3rd_party_licenses.yml @@ -17,5 +17,3 @@ jobs: node-version: '14' - run: ./.github/workflows/update_3rd_party_licenses.sh - env: - GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index fbfb10b..6f51869 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -6,11 +6,7 @@ on: branches: - main pull_request: - branches: - - main - -env: - GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} + types: [opened, synchronize] jobs: integration_test: diff --git a/action.yml b/action.yml index d9d7ca5..ceb813a 100644 --- a/action.yml +++ b/action.yml @@ -8,6 +8,15 @@ branding: color: blue icon: code inputs: + github-token: + description: > + A GitHub token used to access the GitHub REST API for retrieving release and version information. + While this action will never perform anything more than read operations against the GitHub REST API, + we do not recommend providing a self-generated personal access token which may provide more access than is + required of this action. This input instead is merely a convenience so that users of this action do not + have to manually pass an automatically generated token via their environment settings within a workflow. + [Learn more about automatically generated tokens](https://docs.github.com/en/actions/security-guides/automatic-token-authentication) + default: ${{ github.token }} otp-version: description: Version range or exact version of Erlang/OTP to use, or false when installing only Gleam without OTP diff --git a/dist/index.js b/dist/index.js index de05728..dc9158a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -7612,9 +7612,12 @@ async function get(url0, pageIdxs) { const headers = { 'user-agent': 'setup-beam', } - if (process.env.GITHUB_TOKEN) { - headers.authorization = `Bearer ${process.env.GITHUB_TOKEN}` + const GithubToken = getInput('github-token', false) + + if (GithubToken) { + headers.authorization = `Bearer ${GithubToken}` } + if (pageIdx !== null) { url.searchParams.append('page', pageIdx) } diff --git a/src/setup-beam.js b/src/setup-beam.js index 8bf8c8e..8db3618 100644 --- a/src/setup-beam.js +++ b/src/setup-beam.js @@ -419,9 +419,12 @@ async function get(url0, pageIdxs) { const headers = { 'user-agent': 'setup-beam', } - if (process.env.GITHUB_TOKEN) { - headers.authorization = `Bearer ${process.env.GITHUB_TOKEN}` + const GithubToken = getInput('github-token', false) + + if (GithubToken) { + headers.authorization = `Bearer ${GithubToken}` } + if (pageIdx !== null) { url.searchParams.append('page', pageIdx) }