Skip to content

Commit

Permalink
upgrade node version, convert to import
Browse files Browse the repository at this point in the history
  • Loading branch information
nonrational committed Feb 20, 2024
1 parent d0a9123 commit a1e2c3c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 16
node-version: 20.11.1
- name: Install deps and build dist
run: npm i

Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ outputs:
result:
description: 'Most recent result'
runs:
using: 'node16'
using: 'node20'
main: 'dist/index.js'
32 changes: 16 additions & 16 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
const core = require('@actions/core')
const github = require('@actions/github')
const cache = require('@actions/cache')
const fs = require('fs')
import { info, getInput, setOutput, summary, setFailed } from '@actions/core'
import { context } from '@actions/github'
import { restoreCache, saveCache } from '@actions/cache'
import { existsSync, writeFileSync, readFileSync } from 'fs'

const RESULT_PATH = '/tmp/prev-result'

const run = async () => {
const sha = github.context.sha
core.info(`Running for current SHA ${sha}`)
const sha = context.sha
info(`Running for current SHA ${sha}`)

try {
// inputResult will be 'unknown' if we're in "restore only" mode.
const inputResult = core.getInput('result')
const cacheGroup = core.getInput('cache-group')
const inputResult = getInput('result')
const cacheGroup = getInput('cache-group')
const keyPrefix = `cache-result-action-${cacheGroup}-${sha}`
const key = keyPrefix + '-' + Math.floor(Date.now() / 1000)

await cache.restoreCache([RESULT_PATH], key, [keyPrefix])
await restoreCache([RESULT_PATH], key, [keyPrefix])

let actualResult = inputResult

// True if we have a previous result already.
const cacheHit = !!fs.existsSync(RESULT_PATH)
const cacheHit = !!existsSync(RESULT_PATH)

let cacheOutcome = cacheHit ? 'hit' : 'miss'

// If the result is 'unknown' then we won't save it to the cache; we're in "restore only" mode.
if (inputResult !== 'unknown') {
fs.writeFileSync(RESULT_PATH, inputResult)
await cache.saveCache([RESULT_PATH], key)
writeFileSync(RESULT_PATH, inputResult)
await saveCache([RESULT_PATH], key)
cacheOutcome = 'write'
} else if (cacheHit) {
actualResult = fs.readFileSync(RESULT_PATH, { encoding: 'utf8' })
actualResult = readFileSync(RESULT_PATH, { encoding: 'utf8' })
}

core.setOutput('result', actualResult)
setOutput('result', actualResult)

await core.summary
await summary
.addTable([
[{data: 'Output', header: true}, {data: 'Result', header: true}],
['result', actualResult],
Expand All @@ -45,7 +45,7 @@ const run = async () => {
])
.write()
} catch(error) {
core.setFailed(error.message)
setFailed(error.message)
}
}

Expand Down

0 comments on commit a1e2c3c

Please sign in to comment.