Skip to content

Commit

Permalink
🚸 automatically use GitHub token
Browse files Browse the repository at this point in the history
  • Loading branch information
burgholzer committed Sep 9, 2024
1 parent eb66033 commit 68feaad
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 26 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ jobs:
cache: npm
- run: npm ci
- run: npm run all
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# test action works running from the graph
test:
Expand All @@ -42,8 +40,6 @@ jobs:
- uses: actions/checkout@v4
- uses: ./
id: z3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: echo "${{ steps.z3.outputs.z3-root }}"
- run: '[ -d "${{ steps.z3.outputs.z3-root }}" ] || exit 1'
- if: runner.os != 'Windows'
Expand Down
12 changes: 0 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,10 @@ To download the latest version of Z3 for the host platform and add it to the `PA
- name: Setup Z3
id: z3
uses: cda-tum/setup-z3@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
This action creates a `z3-root` output variable that contains the path to the root directory of the Z3 installation and exports the `Z3_ROOT` environment variable for subsequent steps in a job. The output variable can be accessed as `${{ steps.z3.outputs.z3-root }}`.

> **Warning**
> The `GITHUB_TOKEN` environment variable is required to download the Z3 binaries from GitHub releases.
> The token is automatically provided by GitHub Actions and does not need to be configured manually.

### Specifying a version

In many cases, it is convenient to use a specific version of Z3. This can be done by specifying the `version` input:
Expand All @@ -30,8 +24,6 @@ In many cases, it is convenient to use a specific version of Z3. This can be don
uses: cda-tum/setup-z3@v1
with:
version: 4.11.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```

> **Note**
Expand All @@ -48,8 +40,6 @@ If you want to explicitly specify the platform and architecture for which Z3 sho
with:
platform: macOS
architecture: arm64
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```

> **Note**
Expand All @@ -70,6 +60,4 @@ By default, the action only adds Z3 into `PATH`, meaning it cannot be used as a
uses: cda-tum/setup-z3@v1
with:
add_to_library_path: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ inputs:
description: "Add Z3 to the library path variables, such that it can be used as a static/dynamic library. Defaults to false."
required: false
default: "false"
token:
description: "The token that the action will use to query the GitHub API. Defaults to the repository's GitHub token."
required: false
default: ${{ github.token }}
outputs:
z3-root:
description: "The root directory of the Z3 installation"
Expand Down
13 changes: 8 additions & 5 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions src/get-download-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ type ReleaseAsset = components["schemas"]["release-asset"]

/**
* Determine the URL of the Z3 release asset for the given platform and architecture.
* @param {string} token - GitHub token
* @param {string} version - Z3 release version (defaults to latest)
* @param {string} platform - platform to look for (either host, linux, macOS, or windows)
* @param {string} architecture - architecture to look for (either host, x64, x86, or arm64)
* @returns {{path: string, asset: string}} - URL path for the Z3 release assets and the asset name
*/
export default async function getDownloadLink(
token: string,
version = "latest",
platform = "host",
architecture = "host"
): Promise<{ path: string; asset: string }> {
const release = await getRelease(version)
const release = await getRelease(token, version)

if (platform === "host") {
platform = determinePlatform()
Expand Down Expand Up @@ -68,11 +70,12 @@ function determineArchitecture(): string {

/**
* Get the Z3 release assets for the given version from GitHub.
* @param {string} token - GitHub token
* @param version - Z3 release version (defaults to latest)
* @returns {Promise<{assets: ReleaseAsset[], version: string}>} - list of assets of a Z3 release and the release version
*/
async function getRelease(version: string): Promise<{ assets: ReleaseAsset[]; version: string }> {
const octokit = new Octokit()
async function getRelease(token: string, version: string): Promise<{ assets: ReleaseAsset[]; version: string }> {
const octokit = new Octokit({ auth: token })
if (version === "latest") {
const response = await octokit.request("GET /repos/{owner}/{repo}/releases/latest", {
owner: "Z3Prover",
Expand Down
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ async function run(): Promise<void> {
const platform = core.getInput("platform", { required: true })
const architecture = core.getInput("architecture", { required: true })
const addToLibraryPath = core.getBooleanInput("add_to_library_path", { required: false })
const token = core.getInput("token", { required: true })

core.debug("==> Determining Z3 asset URL")
const url = await getDownloadLink(version, platform, architecture)
const url = await getDownloadLink(token, version, platform, architecture)
core.debug(`==> Downloading Z3 asset: ${url.path}`)
const file = await tc.downloadTool(url.path)
core.debug("==> Extracting Z3 asset")
Expand Down

0 comments on commit 68feaad

Please sign in to comment.