From d696d7d1720713e36ca5983973acce735724f619 Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Mon, 23 Sep 2024 09:01:14 +0100 Subject: [PATCH 01/15] use github token when getting latest release --- install-cmdstan/action.yml | 6 ++++-- install-cmdstan/scripts/get-latest-release.ps1 | 5 ++++- install-cmdstan/scripts/get-latest-release.sh | 7 ++++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/install-cmdstan/action.yml b/install-cmdstan/action.yml index c70124a..aa6b468 100644 --- a/install-cmdstan/action.yml +++ b/install-cmdstan/action.yml @@ -13,16 +13,18 @@ inputs: runs: using: 'composite' steps: + - env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Determine CmdStan Version (Unix) if: runner.os != 'Windows' && inputs.cmdstan-version == 'latest' run: | chmod +x ${{ github.action_path }}/scripts/get-latest-release.sh - ${{ github.action_path }}/scripts/get-latest-release.sh + ${{ github.action_path }}/scripts/get-latest-release.sh $GH_TOKEN shell: bash - name: Determine CmdStan Version (Windows) if: runner.os == 'Windows' && inputs.cmdstan-version == 'latest' - run: ${{ github.action_path }}\scripts\get-latest-release.ps1 + run: ${{ github.action_path }}\scripts\get-latest-release.ps1 $GH_TOKEN shell: pwsh - name: Set CmdStan Version (Specified) diff --git a/install-cmdstan/scripts/get-latest-release.ps1 b/install-cmdstan/scripts/get-latest-release.ps1 index dcc780e..dc32054 100644 --- a/install-cmdstan/scripts/get-latest-release.ps1 +++ b/install-cmdstan/scripts/get-latest-release.ps1 @@ -1,5 +1,8 @@ # PowerShell script to fetch the latest CmdStan release version with enhanced retry logic +# Get command line argument (token) +$token=$args[0] + # Initialize retry parameters $max_attempts = 10 $wait_time = 5 # seconds @@ -8,7 +11,7 @@ $version = $null for ($attempt = 1; $attempt -le $max_attempts; $attempt++) { try { # Using Invoke-RestMethod to fetch the latest release data - $response = Invoke-RestMethod -Uri "https://api.github.com/repos/stan-dev/cmdstan/releases/latest" -Method Get -ErrorAction Stop + $response = Invoke-RestMethod -Uri "https://api.github.com/repos/stan-dev/cmdstan/releases/latest" -Method Get -ErrorAction Stop -Authentication Bearer -Token $token $version = $response.tag_name -replace '^v', '' # Remove 'v' from version if present # Check if the version is successfully retrieved diff --git a/install-cmdstan/scripts/get-latest-release.sh b/install-cmdstan/scripts/get-latest-release.sh index 0db8889..8aa3f9e 100644 --- a/install-cmdstan/scripts/get-latest-release.sh +++ b/install-cmdstan/scripts/get-latest-release.sh @@ -11,6 +11,7 @@ else exit 1 fi +token=$1 retries=10 wait_time=5 status=0 @@ -19,7 +20,11 @@ version="" for ((i=0; i Date: Mon, 23 Sep 2024 09:11:22 +0100 Subject: [PATCH 02/15] pass gh token directly --- install-cmdstan/action.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/install-cmdstan/action.yml b/install-cmdstan/action.yml index aa6b468..213337a 100644 --- a/install-cmdstan/action.yml +++ b/install-cmdstan/action.yml @@ -13,18 +13,16 @@ inputs: runs: using: 'composite' steps: - - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Determine CmdStan Version (Unix) if: runner.os != 'Windows' && inputs.cmdstan-version == 'latest' run: | chmod +x ${{ github.action_path }}/scripts/get-latest-release.sh - ${{ github.action_path }}/scripts/get-latest-release.sh $GH_TOKEN + ${{ github.action_path }}/scripts/get-latest-release.sh ${{ secrets.GITHUB_TOKEN }} shell: bash - name: Determine CmdStan Version (Windows) if: runner.os == 'Windows' && inputs.cmdstan-version == 'latest' - run: ${{ github.action_path }}\scripts\get-latest-release.ps1 $GH_TOKEN + run: ${{ github.action_path }}\scripts\get-latest-release.ps1 ${{ secrets.GITHUB_TOKEN }} shell: pwsh - name: Set CmdStan Version (Specified) From 5c0fe06397fdcd117c1ef1b239937d588504483f Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Mon, 23 Sep 2024 09:21:49 +0100 Subject: [PATCH 03/15] use environemnt vars --- install-cmdstan/action.yml | 7 +++++-- install-cmdstan/scripts/get-latest-release.ps1 | 5 +---- install-cmdstan/scripts/get-latest-release.sh | 3 +-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/install-cmdstan/action.yml b/install-cmdstan/action.yml index 213337a..f1c5d30 100644 --- a/install-cmdstan/action.yml +++ b/install-cmdstan/action.yml @@ -13,16 +13,19 @@ inputs: runs: using: 'composite' steps: + - env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Determine CmdStan Version (Unix) if: runner.os != 'Windows' && inputs.cmdstan-version == 'latest' run: | chmod +x ${{ github.action_path }}/scripts/get-latest-release.sh - ${{ github.action_path }}/scripts/get-latest-release.sh ${{ secrets.GITHUB_TOKEN }} + ${{ github.action_path }}/scripts/get-latest-release.sh shell: bash - name: Determine CmdStan Version (Windows) if: runner.os == 'Windows' && inputs.cmdstan-version == 'latest' - run: ${{ github.action_path }}\scripts\get-latest-release.ps1 ${{ secrets.GITHUB_TOKEN }} + run: ${{ github.action_path }}\scripts\get-latest-release.ps1 ${{ env.GH_TOKEN }} shell: pwsh - name: Set CmdStan Version (Specified) diff --git a/install-cmdstan/scripts/get-latest-release.ps1 b/install-cmdstan/scripts/get-latest-release.ps1 index dc32054..ae3c52b 100644 --- a/install-cmdstan/scripts/get-latest-release.ps1 +++ b/install-cmdstan/scripts/get-latest-release.ps1 @@ -1,8 +1,5 @@ # PowerShell script to fetch the latest CmdStan release version with enhanced retry logic -# Get command line argument (token) -$token=$args[0] - # Initialize retry parameters $max_attempts = 10 $wait_time = 5 # seconds @@ -11,7 +8,7 @@ $version = $null for ($attempt = 1; $attempt -le $max_attempts; $attempt++) { try { # Using Invoke-RestMethod to fetch the latest release data - $response = Invoke-RestMethod -Uri "https://api.github.com/repos/stan-dev/cmdstan/releases/latest" -Method Get -ErrorAction Stop -Authentication Bearer -Token $token + $response = Invoke-RestMethod -Uri "https://api.github.com/repos/stan-dev/cmdstan/releases/latest" -Method Get -ErrorAction Stop -Authentication Bearer -Token $env:GH_TOKEN $version = $response.tag_name -replace '^v', '' # Remove 'v' from version if present # Check if the version is successfully retrieved diff --git a/install-cmdstan/scripts/get-latest-release.sh b/install-cmdstan/scripts/get-latest-release.sh index 8aa3f9e..9038d18 100644 --- a/install-cmdstan/scripts/get-latest-release.sh +++ b/install-cmdstan/scripts/get-latest-release.sh @@ -11,7 +11,6 @@ else exit 1 fi -token=$1 retries=10 wait_time=5 status=0 @@ -22,7 +21,7 @@ for ((i=0; i Date: Mon, 23 Sep 2024 09:58:16 +0100 Subject: [PATCH 04/15] move env to correct place --- install-cmdstan/action.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/install-cmdstan/action.yml b/install-cmdstan/action.yml index f1c5d30..c93d8be 100644 --- a/install-cmdstan/action.yml +++ b/install-cmdstan/action.yml @@ -12,10 +12,10 @@ inputs: runs: using: 'composite' - steps: - - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: - name: Determine CmdStan Version (Unix) if: runner.os != 'Windows' && inputs.cmdstan-version == 'latest' run: | From e6757b44d73f71b6057e7de562a11215a54e6ec7 Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Mon, 23 Sep 2024 11:30:12 +0100 Subject: [PATCH 05/15] use optional token from environment --- install-cmdstan/action.yml | 2 +- install-cmdstan/scripts/get-latest-release.ps1 | 8 +++++++- install-cmdstan/scripts/get-latest-release.sh | 14 ++++++++++---- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/install-cmdstan/action.yml b/install-cmdstan/action.yml index c93d8be..7fa58d6 100644 --- a/install-cmdstan/action.yml +++ b/install-cmdstan/action.yml @@ -25,7 +25,7 @@ runs: - name: Determine CmdStan Version (Windows) if: runner.os == 'Windows' && inputs.cmdstan-version == 'latest' - run: ${{ github.action_path }}\scripts\get-latest-release.ps1 ${{ env.GH_TOKEN }} + run: ${{ github.action_path }}\scripts\get-latest-release.ps1 shell: pwsh - name: Set CmdStan Version (Specified) diff --git a/install-cmdstan/scripts/get-latest-release.ps1 b/install-cmdstan/scripts/get-latest-release.ps1 index ae3c52b..b1a08bb 100644 --- a/install-cmdstan/scripts/get-latest-release.ps1 +++ b/install-cmdstan/scripts/get-latest-release.ps1 @@ -4,11 +4,17 @@ $max_attempts = 10 $wait_time = 5 # seconds $version = $null +$token = $env:GH_TOKEN +$auth_str = "" + +if (-not [string]::IsNullOrWhiteSpace($toke)) { + auth_str = "-Authentication Bearer -Token $token" +} for ($attempt = 1; $attempt -le $max_attempts; $attempt++) { try { # Using Invoke-RestMethod to fetch the latest release data - $response = Invoke-RestMethod -Uri "https://api.github.com/repos/stan-dev/cmdstan/releases/latest" -Method Get -ErrorAction Stop -Authentication Bearer -Token $env:GH_TOKEN + $response = Invoke-RestMethod -Uri "https://api.github.com/repos/stan-dev/cmdstan/releases/latest" -Method Get -ErrorAction Stop $auth_str $version = $response.tag_name -replace '^v', '' # Remove 'v' from version if present # Check if the version is successfully retrieved diff --git a/install-cmdstan/scripts/get-latest-release.sh b/install-cmdstan/scripts/get-latest-release.sh index 9038d18..3f96e35 100644 --- a/install-cmdstan/scripts/get-latest-release.sh +++ b/install-cmdstan/scripts/get-latest-release.sh @@ -18,11 +18,17 @@ version="" for ((i=0; i Date: Mon, 23 Sep 2024 11:30:27 +0100 Subject: [PATCH 06/15] use token from input --- install-cmdstan/action.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/install-cmdstan/action.yml b/install-cmdstan/action.yml index 7fa58d6..9929e53 100644 --- a/install-cmdstan/action.yml +++ b/install-cmdstan/action.yml @@ -9,11 +9,15 @@ inputs: description: 'Number of cores to use for building CmdStan' required: false default: '1' + github-token: + description: The GitHub token used to create an authenticated client + default: ${{ github.token }} + required: false runs: using: 'composite' env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_TOKEN: ${{ inputs.github-token }} steps: - name: Determine CmdStan Version (Unix) From 53dfa703dc54288efcb12597362a2c758605312c Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Mon, 23 Sep 2024 11:41:45 +0100 Subject: [PATCH 07/15] move env to steps --- install-cmdstan/action.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/install-cmdstan/action.yml b/install-cmdstan/action.yml index 9929e53..3761e5b 100644 --- a/install-cmdstan/action.yml +++ b/install-cmdstan/action.yml @@ -16,12 +16,11 @@ inputs: runs: using: 'composite' - env: - GH_TOKEN: ${{ inputs.github-token }} - steps: - name: Determine CmdStan Version (Unix) if: runner.os != 'Windows' && inputs.cmdstan-version == 'latest' + env: + GH_TOKEN: ${{ inputs.github-token }} run: | chmod +x ${{ github.action_path }}/scripts/get-latest-release.sh ${{ github.action_path }}/scripts/get-latest-release.sh @@ -29,6 +28,8 @@ runs: - name: Determine CmdStan Version (Windows) if: runner.os == 'Windows' && inputs.cmdstan-version == 'latest' + env: + GH_TOKEN: ${{ inputs.github-token }} run: ${{ github.action_path }}\scripts\get-latest-release.ps1 shell: pwsh From f891839a1d1c8ca94ca2c1d68c94885afdf103d5 Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Mon, 23 Sep 2024 14:03:19 +0100 Subject: [PATCH 08/15] use eval --- install-cmdstan/scripts/get-latest-release.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install-cmdstan/scripts/get-latest-release.sh b/install-cmdstan/scripts/get-latest-release.sh index 3f96e35..ad27828 100644 --- a/install-cmdstan/scripts/get-latest-release.sh +++ b/install-cmdstan/scripts/get-latest-release.sh @@ -28,7 +28,7 @@ for ((i=0; i Date: Mon, 23 Sep 2024 14:29:00 +0100 Subject: [PATCH 09/15] update README --- install-cmdstan/README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/install-cmdstan/README.md b/install-cmdstan/README.md index 6795919..b112c34 100644 --- a/install-cmdstan/README.md +++ b/install-cmdstan/README.md @@ -12,6 +12,11 @@ This action installs and caches [CmdStan](https://mc-stan.org/users/interfaces/c **Optional** Number of cores to use for building. Default `1`. +### `github-token` + +**Optional** The GitHub token used to create an authenticated client. By default +will use one automatically created by the github action. + ## Example usage ```yaml From 7a9101caad70f622f6850251bfde875fe3625dc6 Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Mon, 23 Sep 2024 14:30:36 +0100 Subject: [PATCH 10/15] fix typo --- install-cmdstan/scripts/get-latest-release.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install-cmdstan/scripts/get-latest-release.ps1 b/install-cmdstan/scripts/get-latest-release.ps1 index b1a08bb..89498ab 100644 --- a/install-cmdstan/scripts/get-latest-release.ps1 +++ b/install-cmdstan/scripts/get-latest-release.ps1 @@ -7,7 +7,7 @@ $version = $null $token = $env:GH_TOKEN $auth_str = "" -if (-not [string]::IsNullOrWhiteSpace($toke)) { +if (-not [string]::IsNullOrWhiteSpace($token)) { auth_str = "-Authentication Bearer -Token $token" } From 18e9206c310300379d7edbcbba645abb61bbe05f Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Mon, 23 Sep 2024 14:35:49 +0100 Subject: [PATCH 11/15] fix another typo --- install-cmdstan/scripts/get-latest-release.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install-cmdstan/scripts/get-latest-release.ps1 b/install-cmdstan/scripts/get-latest-release.ps1 index 89498ab..e4e8210 100644 --- a/install-cmdstan/scripts/get-latest-release.ps1 +++ b/install-cmdstan/scripts/get-latest-release.ps1 @@ -8,7 +8,7 @@ $token = $env:GH_TOKEN $auth_str = "" if (-not [string]::IsNullOrWhiteSpace($token)) { - auth_str = "-Authentication Bearer -Token $token" + $auth_str = "-Authentication Bearer -Token $token" } for ($attempt = 1; $attempt -le $max_attempts; $attempt++) { From 73d870771ea14950a266187ddf2a76b2d7eba42c Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Mon, 23 Sep 2024 15:20:01 +0100 Subject: [PATCH 12/15] windows: actually send header --- install-cmdstan/scripts/get-latest-release.ps1 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/install-cmdstan/scripts/get-latest-release.ps1 b/install-cmdstan/scripts/get-latest-release.ps1 index e4e8210..0443ee2 100644 --- a/install-cmdstan/scripts/get-latest-release.ps1 +++ b/install-cmdstan/scripts/get-latest-release.ps1 @@ -5,16 +5,17 @@ $max_attempts = 10 $wait_time = 5 # seconds $version = $null $token = $env:GH_TOKEN -$auth_str = "" - +$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]" if (-not [string]::IsNullOrWhiteSpace($token)) { - $auth_str = "-Authentication Bearer -Token $token" + $headers.Add('Accept','application/vnd.github+json') + $headers.Add('Authorization', -join('Bearer: ', $GH_TOKEN)) + $headers.Add('X-GitHub-Api-Version','2022-11-28') } for ($attempt = 1; $attempt -le $max_attempts; $attempt++) { try { # Using Invoke-RestMethod to fetch the latest release data - $response = Invoke-RestMethod -Uri "https://api.github.com/repos/stan-dev/cmdstan/releases/latest" -Method Get -ErrorAction Stop $auth_str + $response = Invoke-RestMethod -Uri "https://api.github.com/repos/stan-dev/cmdstan/releases/latest" -Method Get -ErrorAction Stop -Header $headers $version = $response.tag_name -replace '^v', '' # Remove 'v' from version if present # Check if the version is successfully retrieved From eb734b097c153a439995ba032068a5a5ac3c3663 Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Mon, 23 Sep 2024 15:29:22 +0100 Subject: [PATCH 13/15] fix typo --- install-cmdstan/scripts/get-latest-release.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install-cmdstan/scripts/get-latest-release.ps1 b/install-cmdstan/scripts/get-latest-release.ps1 index 0443ee2..318e36d 100644 --- a/install-cmdstan/scripts/get-latest-release.ps1 +++ b/install-cmdstan/scripts/get-latest-release.ps1 @@ -15,7 +15,7 @@ if (-not [string]::IsNullOrWhiteSpace($token)) { for ($attempt = 1; $attempt -le $max_attempts; $attempt++) { try { # Using Invoke-RestMethod to fetch the latest release data - $response = Invoke-RestMethod -Uri "https://api.github.com/repos/stan-dev/cmdstan/releases/latest" -Method Get -ErrorAction Stop -Header $headers + $response = Invoke-RestMethod -Uri "https://api.github.com/repos/stan-dev/cmdstan/releases/latest" -Method Get -ErrorAction Stop -Headers $headers $version = $response.tag_name -replace '^v', '' # Remove 'v' from version if present # Check if the version is successfully retrieved From 279bd1a27ac8c755bba933e787490b381c093043 Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Mon, 23 Sep 2024 15:52:37 +0100 Subject: [PATCH 14/15] message if no token is found --- install-cmdstan/scripts/get-latest-release.ps1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/install-cmdstan/scripts/get-latest-release.ps1 b/install-cmdstan/scripts/get-latest-release.ps1 index 318e36d..dcea9b9 100644 --- a/install-cmdstan/scripts/get-latest-release.ps1 +++ b/install-cmdstan/scripts/get-latest-release.ps1 @@ -10,6 +10,8 @@ if (-not [string]::IsNullOrWhiteSpace($token)) { $headers.Add('Accept','application/vnd.github+json') $headers.Add('Authorization', -join('Bearer: ', $GH_TOKEN)) $headers.Add('X-GitHub-Api-Version','2022-11-28') +} else { + Write-Host "No authentication token found in the environment." } for ($attempt = 1; $attempt -le $max_attempts; $attempt++) { From ed406eef57908de984d4147d8ed3c818214397a7 Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Mon, 23 Sep 2024 16:07:07 +0100 Subject: [PATCH 15/15] use correct variable --- install-cmdstan/scripts/get-latest-release.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install-cmdstan/scripts/get-latest-release.ps1 b/install-cmdstan/scripts/get-latest-release.ps1 index dcea9b9..9bfae1c 100644 --- a/install-cmdstan/scripts/get-latest-release.ps1 +++ b/install-cmdstan/scripts/get-latest-release.ps1 @@ -8,7 +8,7 @@ $token = $env:GH_TOKEN $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]" if (-not [string]::IsNullOrWhiteSpace($token)) { $headers.Add('Accept','application/vnd.github+json') - $headers.Add('Authorization', -join('Bearer: ', $GH_TOKEN)) + $headers.Add('Authorization', -join('Bearer: ', $token)) $headers.Add('X-GitHub-Api-Version','2022-11-28') } else { Write-Host "No authentication token found in the environment."