diff --git a/.github/workflows/check-dist.yml b/.github/workflows/check-dist.yml index 839606f..d3d8792 100644 --- a/.github/workflows/check-dist.yml +++ b/.github/workflows/check-dist.yml @@ -1,51 +1,51 @@ -# `dist/index.js` is a special file in Actions. -# When you reference an action with `uses:` in a workflow, -# `index.js` is the code that will run. -# For our project, we generate this file through a build process from other source files. -# We need to make sure the checked-in `index.js` actually matches what we expect it to be. -name: Check dist/ - -on: - push: - branches: - - master - paths-ignore: - - '**.md' - pull_request: - paths-ignore: - - '**.md' - workflow_dispatch: - -jobs: - check-dist: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Set Node.js 20.x - uses: actions/setup-node@v4 - with: - node-version: 20.x - - - name: Install dependencies - run: npm ci - - - name: Rebuild the dist/ directory - run: npm run build - - - name: Compare the expected and actual dist/ directories - run: | - if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then - echo "Detected uncommitted changes after build. See status below:" - git diff - exit 1 - fi - id: diff - - # If index.js was different than expected, upload the expected version as an artifact - - uses: actions/upload-artifact@v3 - if: ${{ failure() && steps.diff.conclusion == 'failure' }} - with: - name: dist - path: dist/ \ No newline at end of file +# `dist/index.js` is a special file in Actions. +# When you reference an action with `uses:` in a workflow, +# `index.js` is the code that will run. +# For our project, we generate this file through a build process from other source files. +# We need to make sure the checked-in `index.js` actually matches what we expect it to be. +name: Check dist/ + +on: + push: + branches: + - master + paths-ignore: + - '**.md' + pull_request: + paths-ignore: + - '**.md' + workflow_dispatch: + +jobs: + check-dist: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Set Node.js 20.x + uses: actions/setup-node@v4 + with: + node-version: 20.x + + - name: Install dependencies + run: npm ci + + - name: Rebuild the dist/ directory + run: npm run build + + - name: Compare the expected and actual dist/ directories + run: | + if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then + echo "Detected uncommitted changes after build. See status below:" + git diff + exit 1 + fi + id: diff + + # If index.js was different than expected, upload the expected version as an artifact + - uses: actions/upload-artifact@v4 + if: ${{ failure() && steps.diff.conclusion == 'failure' }} + with: + name: dist + path: dist/ diff --git a/.github/workflows/release-new-action-version.yml b/.github/workflows/release-new-action-version.yml index db7bf2a..589dd81 100644 --- a/.github/workflows/release-new-action-version.yml +++ b/.github/workflows/release-new-action-version.yml @@ -1,26 +1,26 @@ -name: Release new action version -on: - release: - types: [released] - workflow_dispatch: - inputs: - TAG_NAME: - description: 'Tag name that the major tag will point to' - required: true - -env: - TAG_NAME: ${{ github.event.inputs.TAG_NAME || github.event.release.tag_name }} -permissions: - contents: write - -jobs: - update_tag: - name: Update the major tag to include the ${{ github.event.inputs.TAG_NAME || github.event.release.tag_name }} changes - environment: - name: releaseNewActionVersion - runs-on: ubuntu-latest - steps: - - name: Update the ${{ env.TAG_NAME }} tag - uses: actions/publish-action@v0.1.0 - with: - source-tag: ${{ env.TAG_NAME }} +name: Release new action version +on: + release: + types: [released] + workflow_dispatch: + inputs: + TAG_NAME: + description: 'Tag name that the major tag will point to' + required: true + +env: + TAG_NAME: ${{ github.event.inputs.TAG_NAME || github.event.release.tag_name }} +permissions: + contents: write + +jobs: + update_tag: + name: Update the major tag to include the ${{ github.event.inputs.TAG_NAME || github.event.release.tag_name }} changes + environment: + name: releaseNewActionVersion + runs-on: ubuntu-latest + steps: + - name: Update the ${{ env.TAG_NAME }} tag + uses: actions/publish-action@v0.1.0 + with: + source-tag: ${{ env.TAG_NAME }} diff --git a/action.yml b/action.yml index 240ccf2..79fd0c9 100644 --- a/action.yml +++ b/action.yml @@ -1,15 +1,15 @@ -name: 'Set up Nullstone' -description: 'Set up Nullstone and add it to the PATH' -author: 'Nullstone' -branding: - icon: arrow-down-circle - color: blue -inputs: - nullstone-version: - description: 'The Nullstone CLI version to download and use.' - required: false - default: 'latest' -runs: - using: node20 - main: dist/index.js - post-if: success() +name: 'Set up Nullstone' +description: 'Set up Nullstone and add it to the PATH' +author: 'Nullstone' +branding: + icon: arrow-down-circle + color: blue +inputs: + nullstone-version: + description: 'The Nullstone CLI version to download and use.' + required: false + default: 'latest' +runs: + using: node20 + main: dist/index.js + post-if: success() diff --git a/dist/index.js b/dist/index.js index 46128ce..28d16e5 100644 --- a/dist/index.js +++ b/dist/index.js @@ -28249,7 +28249,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) { Object.defineProperty(exports, "__esModule", ({ value: true })); exports.run = run; const core = __importStar(__nccwpck_require__(2186)); -const httpm = __importStar(__nccwpck_require__(6255)); const tc = __importStar(__nccwpck_require__(7784)); const os_1 = __importDefault(__nccwpck_require__(2037)); const repo = 'nullstone-io/nullstone'; @@ -28281,20 +28280,17 @@ function getVersion() { function getLatestVersion() { return __awaiter(this, void 0, void 0, function* () { core.info(`Detecting latest version from github.com/${repo} releases`); - let http = new httpm.HttpClient('setup-nullstone-action', [], { - allowRedirects: true, - maxRedirects: 3 - }); - const GITHUB_TOKEN = process.env.GITHUB_TOKEN; - const requestUrl = `https://api.github.com/repos/${repo}/releases/latest`; - const headers = Object.assign({ 'Accept': 'application/vnd.github.v3+json' }, (GITHUB_TOKEN ? { - Authorization: `Bearer ${GITHUB_TOKEN}` - } : {})); - const response = yield http.getJson(requestUrl, headers); - if (response && response.result) { - return response.result.tag_name || ''; + const res = yield fetch(`https://github.com/${repo}/releases/latest`, { redirect: 'follow' }); + if (!res.url) { + throw new Error('Could not determine final URL after redirects'); } - return ''; + // Extract the version tag from the final URL + const segments = res.url.split('/'); + const version = segments[segments.length - 1]; + if (!version) { + throw new Error(`Could not extract version from URL: ${res.url}`); + } + return version; }); } function getDownloadUrl(version) { diff --git a/src/main.ts b/src/main.ts index e955a62..3a49442 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,89 +1,79 @@ -import * as core from '@actions/core' -import * as httpm from '@actions/http-client' -import * as tc from '@actions/tool-cache' -import os from 'os' - -const repo = 'nullstone-io/nullstone' - -export async function run() { - const version = await getVersion() - const downloadUrl = getDownloadUrl(version) - - core.info(`Downloading nullstone ${version} from ${downloadUrl}`) - const downloadPath = await tc.downloadTool(downloadUrl) - - core.info(`Extracting nullstone`) - let installPath = await tc.extractTar(downloadPath) - - core.info(`Adding nullstone to the path`) - core.addPath(installPath) -} - -async function getVersion(): Promise { - let version = core.getInput('nullstone-version') - if (!version || version === 'latest') { - version = await getLatestVersion() - } - // Drop first character 'v' - if (version.indexOf('v') === 0) { - version = version.substring(1) - } - return version -} - -interface GithubRelease { - tag_name: string; -} - -async function getLatestVersion(): Promise { - core.info(`Detecting latest version from github.com/${repo} releases`) - let http: httpm.HttpClient = new httpm.HttpClient('setup-nullstone-action', [], { - allowRedirects: true, - maxRedirects: 3 - }) - const GITHUB_TOKEN = process.env.GITHUB_TOKEN; - const requestUrl = `https://api.github.com/repos/${repo}/releases/latest` - const headers = { - 'Accept': 'application/vnd.github.v3+json', - ...( - GITHUB_TOKEN ? { - Authorization: `Bearer ${GITHUB_TOKEN}` - } : {} - ) - } - const response = await http.getJson(requestUrl, headers) - if (response && response.result) { - return response.result.tag_name || '' - } - return '' -} - -function getDownloadUrl(version: string): string { - let platform: string = os.platform() - switch (os.platform()) { - case "linux": - break - case "win32": - platform = "windows" - break - case "darwin": - break - default: - throw new Error(`Platform not supported: ${os.platform()}`) - } - let arch: string = os.arch() - switch (os.arch()) { - case "arm64": - break - case "x64": - arch = "amd64" - break - case "x32": - arch = "386" - break - default: - throw new Error(`Architecture not supported: ${os.arch()}`) - } - - return `https://github.com/${repo}/releases/download/v${version}/nullstone_${version}_${platform}_${arch}.tar.gz` -} +import * as core from '@actions/core' +import * as tc from '@actions/tool-cache' +import os from 'os' + +const repo = 'nullstone-io/nullstone' + +export async function run() { + const version = await getVersion() + const downloadUrl = getDownloadUrl(version) + + core.info(`Downloading nullstone ${version} from ${downloadUrl}`) + const downloadPath = await tc.downloadTool(downloadUrl) + + core.info(`Extracting nullstone`) + let installPath = await tc.extractTar(downloadPath) + + core.info(`Adding nullstone to the path`) + core.addPath(installPath) +} + +async function getVersion(): Promise { + let version = core.getInput('nullstone-version') + if (!version || version === 'latest') { + version = await getLatestVersion() + } + // Drop first character 'v' + if (version.indexOf('v') === 0) { + version = version.substring(1) + } + return version +} + +async function getLatestVersion(): Promise { + core.info(`Detecting latest version from github.com/${repo} releases`) + + const res = await fetch(`https://github.com/${repo}/releases/latest`, { redirect: 'follow' }) + if (!res.url) { + throw new Error('Could not determine final URL after redirects') + } + + // Extract the version tag from the final URL + const segments = res.url.split('/') + const version = segments[segments.length - 1] + if (!version) { + throw new Error(`Could not extract version from URL: ${res.url}`) + } + + return version +} + +function getDownloadUrl(version: string): string { + let platform: string = os.platform() + switch (os.platform()) { + case "linux": + break + case "win32": + platform = "windows" + break + case "darwin": + break + default: + throw new Error(`Platform not supported: ${os.platform()}`) + } + let arch: string = os.arch() + switch (os.arch()) { + case "arm64": + break + case "x64": + arch = "amd64" + break + case "x32": + arch = "386" + break + default: + throw new Error(`Architecture not supported: ${os.arch()}`) + } + + return `https://github.com/${repo}/releases/download/v${version}/nullstone_${version}_${platform}_${arch}.tar.gz` +}