Skip to content

Commit

Permalink
Add Test
Browse files Browse the repository at this point in the history
  • Loading branch information
smashedr committed Jul 26, 2024
1 parent 8b0aa91 commit f10c942
Show file tree
Hide file tree
Showing 9 changed files with 1,361 additions and 46 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"env": {
"es2021": true
"es2021": true,
"node": true
},
"extends": "eslint:recommended",
"parserOptions": {
Expand Down
84 changes: 84 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: "Test"

on:
workflow_dispatch:
push:
paths:
- "src/**"

jobs:
test:
name: "Test"
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- name: "Checkout"
uses: actions/checkout@v4

- name: "Test Local Action"
id: test
uses: ./
with:
token: ${{ secrets.GITHUB_TOKEN }}
major: false
minor: false
tags: test

- name: "Echo Outputs"
run: |
echo '${{ steps.test.outputs.tags }}'
if [ -z '${{ steps.test.outputs.tags }}' ];then
echo "No Output"
exit 1
fi
lint:
name: "Lint"
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- name: "Checkout"
uses: actions/checkout@v4

- name: "Setup Node"
uses: actions/setup-node@v4
with:
node-version: 20

- name: "ESLint"
run: |
npm install
npm run lint
build:
name: "Build"
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- name: "Checkout"
uses: actions/checkout@v4

- name: "Setup Node"
uses: actions/setup-node@v4
with:
node-version: 20

- name: "Build"
run: |
npm install
npm run build
- name: "Verify"
run: |
git status --porcelain dist/
if [ ! -d "dist" ];then
echo "Missing dist directory, run: npm build"
exit 1
fi
if [ -n "$(git status --porcelain dist)" ];then
echo "Build was not run, run: npm build"
exit 1
fi
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.idea/
*.iml
.vscode/
build/
node_modules/
.env
.secrets
.vars
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist/
node_modules/
package-lock.json
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[![Tags](https://img.shields.io/github/actions/workflow/status/cssnr/update-version-tags-action/tags.yaml?logo=github&logoColor=white&label=tags)](https://github.com/cssnr/update-version-tags-action/actions/workflows/tags.yaml)
[![Test](https://img.shields.io/github/actions/workflow/status/cssnr/update-version-tags-action/test.yaml?logo=github&logoColor=white&label=test)](https://github.com/cssnr/update-version-tags-action/actions/workflows/test.yaml)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=cssnr_update-version-tags-action&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=cssnr_update-version-tags-action)
[![GitHub Release Version](https://img.shields.io/github/v/release/cssnr/update-version-tags-action?logo=github)](https://github.com/cssnr/update-version-tags-action/releases/latest)
[![GitHub Last Commit](https://img.shields.io/github/last-commit/cssnr/update-version-tags-action?logo=github&logoColor=white&label=updated)](https://github.com/cssnr/update-version-tags-action/graphs/commit-activity)
[![GitHub Top Language](https://img.shields.io/github/languages/top/cssnr/update-version-tags-action?logo=htmx&logoColor=white)](https://github.com/cssnr/update-version-tags-action)
[![GitHub Org Stars](https://img.shields.io/github/stars/cssnr?style=flat&logo=github&logoColor=white)](https://cssnr.github.io/)
[![Discord](https://img.shields.io/discord/899171661457293343?logo=discord&logoColor=white&label=discord&color=7289da)](https://discord.gg/wXy6m2X8wY)
Expand Down
48 changes: 28 additions & 20 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35017,21 +35017,13 @@ var __webpack_exports__ = {};
(() => {
const core = __nccwpck_require__(2186)
const github = __nccwpck_require__(5438)
const semver = __nccwpck_require__(1383)
const { parse } = __nccwpck_require__(4393)
const semver = __nccwpck_require__(1383)

const Tags = __nccwpck_require__(1123)

;(async () => {
try {
// Check Tag
if (!github.context.ref.startsWith('refs/tags/')) {
core.notice(`Skipping due to non-tags: ${github.context.ref}`)
return
}
const tag = github.context.ref.replace('refs/tags/', '')
console.log('tag:', tag)

// Process Inputs
const token = core.getInput('token', { required: true })
// console.log('token:', token)
Expand All @@ -35044,16 +35036,28 @@ const Tags = __nccwpck_require__(1123)
const inputTags = core.getInput('tags')
console.log('inputTags:', inputTags)

// Check Tag
if (!github.context.ref.startsWith('refs/tags/') && (major || minor)) {
core.notice(`Skipping due to non-tags: ${github.context.ref}`)
return
}
const tag = github.context.ref.replace('refs/tags/', '')
console.log('tag:', tag)

// Set Variables
const { owner, repo } = github.context.repo
console.log('owner:', owner)
console.log('repo:', repo)
const sha = github.context.sha
console.log('sha:', sha)
const majorVer = semver.major(tag)
console.log('majorVer:', majorVer)
const minorVer = semver.minor(tag)
console.log('minorVer:', minorVer)
let parsed
if (major || minor) {
parsed = semver.parse(tag)
console.log('parsed:', parsed)
if (!parsed) {
return core.setFailed(`Unable to parse ${tag} to a semver.`)
}
}

// Collect Tags
const collectedTags = []
Expand All @@ -35067,12 +35071,12 @@ const Tags = __nccwpck_require__(1123)
collectedTags.push(...parsedTags)
}
if (major) {
console.log(`Major Tag: ${prefix}${majorVer}`)
collectedTags.push(`${prefix}${majorVer}`)
console.log(`Major Tag: ${prefix}${parsed.major}`)
collectedTags.push(`${prefix}${parsed.major}`)
}
if (minor) {
console.log(`Minor Tag: ${prefix}${majorVer}.${minorVer}`)
collectedTags.push(`${prefix}${majorVer}.${minorVer}`)
console.log(`Minor Tag: ${prefix}${parsed.major}.${parsed.minor}`)
collectedTags.push(`${prefix}${parsed.major}.${parsed.minor}`)
}
console.log('collectedTags', collectedTags)
if (!collectedTags.length) {
Expand All @@ -35089,19 +35093,23 @@ const Tags = __nccwpck_require__(1123)
// console.log('reference?.data:', reference?.data)
if (reference) {
if (sha !== reference.data.object.sha) {
core.info(`Updating tag "${tag}" to sha ${sha}`)
core.info(`\u001b[32mUpdating tag "${tag}" to sha: ${sha}`)
await tags.updateRef(tag, sha)
} else {
core.info(`Tag "${tag}" already points to sha ${sha}`)
core.info(
`\u001b[36mTag "${tag}" already points to sha: ${sha}`
)
}
} else {
core.info(`Creating new tag "${tag}" to sha ${sha}`)
core.info(`\u001b[33mCreating new tag "${tag}" to sha: ${sha}`)
await tags.createRef(tag, sha)
}
}

// Set Output
core.setOutput('tags', allTags.join(','))

core.info(`\u001b[32;1mFinished Success`)
} catch (e) {
core.debug(e)
core.info(e.message)
Expand Down
Loading

0 comments on commit f10c942

Please sign in to comment.