Skip to content

Commit

Permalink
Merge pull request #13 from zendesk/shoukoo.version_bug
Browse files Browse the repository at this point in the history
Remove unused code
  • Loading branch information
shoukoo authored Jan 4, 2022
2 parents 0a4fda6 + 5138934 commit d055f33
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 76 deletions.
28 changes: 24 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,48 @@ jobs:
install_specific_version:
name: Install specific version of Jsonnet and print version
runs-on: ubuntu-latest
env:
version: v0.16.0
steps:
- uses: zendesk/checkout@v2
- uses: zendesk/setup-go@v2
with:
go-version: '^1.16.0' # Go >= 1.16 to have go install
- name: Setup Jsonnet
uses: ./
with:
version: v0.15.0
version: ${{ env.version }}
github_token: ${{ github.token }}
- name: Print Jsonnet version
run: jsonnet -v
run: |
jsonnet_version=$(jsonnet -v)
echo "$jsonnet_version"
if [[ ${jsonnet_version} != *"$version"* ]];then
echo "Cannot find $version"
echo 1
fi
- name: Print Jsonnet reformatter version
run: jsonnetfmt -v
run: |
jsonnet_version=$(jsonnetfmt -v)
echo "$jsonnet_version"
if [[ ${jsonnet_version} != *"$version"* ]];then
echo "Cannot find $version"
echo 1
fi
install_latest:
name: Install latest version of Jsonnet and print version
runs-on: ubuntu-latest
steps:
- uses: zendesk/checkout@v2
- uses: zendesk/setup-go@v2
with:
go-version: '^1.16.0' # Go >= 1.16 to have go install
- name: Setup Jsonnet
uses: ./
with:
github_token: ${{ github.token }}
- name: Print Jsonnet version
run: jsonnet -v
- name: Print Jsonnet reformatter version
run: jsonnetfmt -v
run: jsonnetfmt -v
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
![Latest Release](https://img.shields.io/github/v/release/zendesk/setup-jsonnet?label=Latest%20Release)
![Examples](https://github.com/zendesk/setup-jsonnet/workflows/Test/badge.svg?branch=master)

A GitHub action to install a specific version of Jsonnet. This action will add
A GitHub action to install a specific version of [Go Jsonnet](https://github.com/google/go-jsonnet). This action will add
`jsonnet` and `jsonnetfmt` to the `PATH` making them available for subsequent
actions.

Expand Down
71 changes: 2 additions & 69 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,77 +1,10 @@
const core = require('@actions/core')
const io = require('@actions/io')
const { exec } = require('@actions/exec')
const https = require('https')
const path = require('path')

const fetchReleases = async () => {
const version = core.getInput('version')
const versionPath = version == 'latest' ? 'latest' : `tags/${version}`
const url = `https://api.github.com/repos/google/jsonnet/releases/${versionPath}`

core.info(`Fetching Jsonnet releases from ${url}`)

let release

try {
release = JSON.parse(await get(url))
} catch (error) {
core.setFailed(
`Failed to fetch releases from GitHub API, providing a token may help.\nError: ${error}`
)
return
}

const pattern = new RegExp(`jsonnet-bin-v[0-9.]+-linux\.tar\.gz`, 'i')

const jsonnetAsset = release.assets.find(asset =>
pattern.test(asset.name)
)

return jsonnetAsset.browser_download_url
}

const get = url => {
return new Promise((resolve, reject) => {
const headers = {
'User-Agent': 'setup-jsonnet Github action',
}

const token = core.getInput('github_token')

if (token) {
headers['Authorization'] = `token ${token}`
}

const request = https.get(url, { headers })

request.on('response', res => {
let data = ''

res.on('data', chunk => {
data += chunk
})

res.on('end', () => {
if (res.statusCode == 200) {
resolve(data)
} else {
reject(data)
}
})
})

request.on('error', err => {
reject(err)
})
})
}

const run = async () => {
//const url = await fetchReleases()

//await exec(path.join(__dirname, 'install-jsonnet.sh'), [url])
await exec(path.join(__dirname, 'install-jsonnet.sh'))
const version = core.getInput('version')
await exec(path.join(__dirname, 'install-jsonnet.sh'), version)
}

try {
Expand Down
5 changes: 3 additions & 2 deletions install-jsonnet.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/bin/bash -ex

# Install go-jsonnet
go get github.com/google/go-jsonnet/cmd/jsonnet
go get github.com/google/go-jsonnet/cmd/jsonnetfmt
version="$1"
go install "github.com/google/go-jsonnet/cmd/jsonnet@${version}"
go install "github.com/google/go-jsonnet/cmd/jsonnetfmt@${version}"

# Add jsonnet executables to the path for future actions
echo "$HOME/go/bin" >> "$GITHUB_PATH"

0 comments on commit d055f33

Please sign in to comment.