Skip to content

Commit

Permalink
Use summaraizer binary (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
StefMa authored Aug 9, 2024
1 parent 22a927e commit 0aa210e
Show file tree
Hide file tree
Showing 8 changed files with 4,581 additions and 1,788 deletions.
26 changes: 21 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ jobs:
with:
node-version: '20'

- name: Install Go to install summaraizer
uses: actions/setup-go@v5
with:
go-version: '1.22.2'

- name: Install ollama to call it via summaraizer
run: curl -fsSL https://ollama.com/install.sh | sh

Expand All @@ -33,6 +28,27 @@ jobs:
- run: npm install

- run: npm test
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

testInstallSummaraizer:
strategy:
matrix:
os: [macos-13, macos-14, ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: '20'

- run: npm install

- run: npm test -- --grep "installSummaraizer"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

distUpToDateCheck:
runs-on: ubuntu-latest
Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,11 @@ jobs:
permissions:
issues: write
steps:
- name: Install go
uses: actions/setup-go@v5
with:
go-version: 1.22.2
- name: Summarize
uses: ioki-mobility/summaraizer-action@main
with:
provider: 'ollama'
provider-args: '--url https://ollama.example.com --model llama3'
provider-args: '--url https://ollama.example.com --model llama3.1'
gh-token: ${{ secrets.GITHUB_TOKEN }}
```
Expand All @@ -45,6 +41,8 @@ Checkout the [summaraizer project](https://github.com/ioki-mobility/summaraizer)
Please note that you could also run `ollama` [within your GitHub Action](https://stackoverflow.com/a/78539440).

The permission `issue: write` is required to add the comment to your issue.

## Why?

Ever run into a situation to got a bit overhelmed with the amound of comments
Expand Down
69 changes: 61 additions & 8 deletions action.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ const core = require('@actions/core')
const github = require('@actions/github')
const exec = require('@actions/exec')
const os = require('os')
const fs = require('fs')
const tc = require('@actions/tool-cache')

async function run() {
await installSummaraizerCli()
let ghToken = core.getInput("gh-token", {required: true})
let summaraizerVersion = core.getInput("summaraizer-version", {required: false})
let provider = core.getInput("provider", {required: true})
let providerArgs = core.getInput("provider-args", {required: true})

let ghToken = core.getInput("gh-token", {required: true,})
let provider = core.getInput("provider", {required: true,})
let providerArgs = core.getInput("provider-args", {required: true,})
await installSummaraizerCli(ghToken, summaraizerVersion)

let sourceOutput = await runSummaraizerSource(
ghToken,
Expand All @@ -31,8 +34,58 @@ async function run() {
)
}

function installSummaraizerCli() {
return exec.exec('go install github.com/ioki-mobility/summaraizer/cmd/summaraizer@85b0914475ae755231446fc5a748f30a23301c36')
async function installSummaraizerCli(githubToken, summaraizerVersion) {
const octokit = github.getOctokit(githubToken)
const release = await octokit.rest.repos.getReleaseByTag({
owner: 'ioki-mobility',
repo: 'summaraizer',
tag: summaraizerVersion
})

const assetId = release.data.assets.find(a => a.name === findAssetName())?.id
if (!assetId) {
throw new Error(`Unable to locate asset for summaraizer release version: ${summaraizerVersion}`)
}

const asset = await octokit.rest.repos.getReleaseAsset({
owner: 'ioki-mobility',
repo: 'summaraizer',
asset_id: assetId
})

const binaryPath = await tc.downloadTool(asset.data.browser_download_url)
const permissionsMode = 0o711
await fs.chmod(binaryPath, permissionsMode, (err) => {
})
const cachedPath = await tc.cacheFile(
binaryPath,
'summaraizer',
'summaraizer',
summaraizerVersion
)
core.addPath(cachedPath)
}

function findAssetName() {
const op = os.platform()
const arch = os.arch()

switch (op) {
case 'linux':
return 'summaraizer-linux-amd64'
case 'darwin':
switch (arch) {
case 'x64':
return 'summaraizer-macos-amd64'
case 'arm64':
return 'summaraizer-macos-arm64'
}
break
case 'win32':
return 'summaraizer-windows-amd64'
}

throw new Error(`Couldn't find asset name for ${op}-${arch}`)
}

async function runSummaraizerSource(token, owner, repo, issue_number) {
Expand All @@ -44,7 +97,7 @@ async function runSummaraizerSource(token, owner, repo, issue_number) {
},
}
}
let command = `${os.homedir()}/go/bin/summaraizer github --issue ${owner}/${repo}/${issue_number} `
let command = `summaraizer github --issue ${owner}/${repo}/${issue_number} `
if (token !== "") {
command += `--token ${token}`
}
Expand All @@ -63,7 +116,7 @@ async function runSummaraizerProvider(sourceInput, provider, providerArgs) {
},
input: Buffer.from(sourceInput)
}
await exec.exec(`${os.homedir()}/go/bin/summaraizer ${provider} ${providerArgs}`, [], options)
await exec.exec(`summaraizer ${provider} ${providerArgs}`, [], options)
return output
}

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ inputs:
description: 'The GitHub token that read and write access to your repository.'
required: false
default: ${{ github.token }}
summaraizer-version:
description: 'The version of summaraizer to install and use'
required: false
default: 'v0.0.1-alpha.00'
provider:
description: 'The AI provider to use. Default is openai.'
required: false
Expand Down
Loading

0 comments on commit 0aa210e

Please sign in to comment.