Skip to content

Commit

Permalink
Fix ref_name output and upgrade dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
smac89 committed Jul 3, 2020
1 parent e01e643 commit 90e5ff8
Show file tree
Hide file tree
Showing 16 changed files with 6,253 additions and 3,869 deletions.
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# https://devhints.io/editorconfig
root = true

[*]
Expand All @@ -11,3 +12,4 @@ indent_size = 3

[*.{ts,js}]
indent_size = 4
max_line_length = 90
4 changes: 2 additions & 2 deletions .github/workflows/tag-latest.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Tag latest release of action tagger :zap:'
name: "Tag latest release of action tagger :zap:"

on:
release:
Expand All @@ -16,4 +16,4 @@ jobs:
publish_latest_tag: true
prefer_branch_releases: false
env:
GITHUB_TOKEN: '${{secrets.GITHUB_TOKEN}}'
GITHUB_TOKEN: "${{ github.token }}"
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ on:
pull_request:
push:
branches:
- 'release/**'
- "release/**"
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
- "v[0-9]+.[0-9]+.[0-9]+"

jobs:
run-tests:
Expand All @@ -15,5 +15,5 @@ jobs:
- uses: actions/checkout@v2
- name: jest
run: |
yarn --frozen-lockfile
yarn --immutable
yarn test
45 changes: 38 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Created by https://www.gitignore.io/api/node,visualstudiocode
# Edit at https://www.gitignore.io/?templates=node,visualstudiocode
# Created by https://www.toptal.com/developers/gitignore/api/node,visualstudiocode,yarn
# Edit at https://www.toptal.com/developers/gitignore?templates=node,visualstudiocode,yarn

### Node ###
# Logs
Expand Down Expand Up @@ -57,6 +57,12 @@ typings/
# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

Expand All @@ -73,14 +79,18 @@ typings/
# parcel-bundler cache (https://parceljs.org/)
.cache

# next.js build output
# Next.js build output
.next

# nuxt.js build output
# Nuxt.js build / generate output
.nuxt
dist

# react / gatsby
public/
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist
Expand All @@ -94,15 +104,36 @@ public/
# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace

### VisualStudioCode Patch ###
# Ignore all local history of files
.history

# End of https://www.gitignore.io/api/node,visualstudiocode
### yarn ###
# https://yarnpkg.com/advanced/qa#which-files-should-be-gitignored

# .yarn/unplugged and .yarn/build-state.yml should likely always be ignored since
# they typically hold machine-specific build artifacts. Ignoring them might however
# prevent Zero-Installs from working (to prevent this, set enableScripts to false).
.yarn/*

# .yarn/cache and .pnp.* may be safely ignored, but you'll need to run yarn install
# to regenerate them between each branch switch.
# Uncomment the following lines if you're not using Zero-Installs:
# .yarn/cache
.pnp.*

# End of https://www.toptal.com/developers/gitignore/api/node,visualstudiocode,yarn
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"arcanis.vscode-zipfs"
]
}
8 changes: 5 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"files.exclude": {
"node_modules": true
}
"files.exclude": {
"node_modules": true
},
"typescript.tsdk": ".yarn/sdks/typescript/lib",
"typescript.enablePromptUseWorkspaceTsdk": true
}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ Was the latest tag also published?

### `GITHUB_TOKEN`

**Required** A github token used for creating an octoclient for making API calls
**Required** A github token used for creating an octoclient for making API calls. Use `github.token`

## Debug Logging

This action supports [debug logging](https://help.github.com/en/actions/configuring-and-managing-workflows/managing-a-workflow-run#enabling-debug-logging). When enabled, it will dump the output of the
api call for creating the tags/branches.
This is useful for testing and should be included when reporting bugs.

# Usage
# Sample Usage

`versioning.yml`

Expand All @@ -61,7 +61,7 @@ jobs:
steps:
- uses: Actions-R-Us/actions-tagger@latest
env:
GITHUB_TOKEN: "${{secrets.GITHUB_TOKEN}}"
GITHUB_TOKEN: "${{ github.token }}"
with:
- publish_latest_tag: true
```
Expand Down
16 changes: 13 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
// https://kulshekhar.github.io/ts-jest/user/config/
// https://jestjs.io/docs/en/configuration

// https://docs.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables
const bail = process.env.CI == "true" ? 0 : 1;

module.exports = {
bail,
preset: "ts-jest",
testEnvironment: "node",
modulePaths: ["<rootDir>/"],
verbose: true,
globalSetup: "<rootDir>/test-setup.ts",
moduleNameMapper: {
// Note: Order is IMPORTANT!
// Inner modules before outer ones
"^src(?:/(.+))?$": ["<rootDir>/src/$1", "<rootDir>/src"],
},
verbose: false,
globalSetup: "<rootDir>/tests/test-setup.ts",
};
2 changes: 1 addition & 1 deletion lib/index.js

Large diffs are not rendered by default.

21 changes: 12 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,28 @@
"main": "lib/index.js",
"scripts": {
"watch": "ncc build src/action.ts --watch --minify --out lib",
"test": "jest"
"test": "jest",
"vscode:pnp": "pnpify --sdk vscode"
},
"author": {
"name": "Actions-R-Us",
"url": "https://github.com/Actions-R-Us"
},
"license": "MIT",
"dependencies": {
"@actions/core": "^1.2.3",
"@actions/github": "^2.1.1",
"@actions/core": "^1.2.4",
"@actions/github": "^4.0.0",
"@octokit/core": "3.1.0",
"semver": "^7.3.2"
},
"devDependencies": {
"@types/jest": "~25.2.1",
"@types/jest": "~26.0.3",
"@types/node": "^12.12.18",
"@types/semver": "^7.1.0",
"@zeit/ncc": "^0.22.1",
"jest": "~25.5.3",
"ts-jest": "~25.4.0",
"typescript": "3.8.3"
"@types/semver": "^7.3.1",
"@yarnpkg/pnpify": "^2.0.0-rc.25",
"@zeit/ncc": "^0.22.3",
"jest": "~26.1.0",
"ts-jest": "~26.1.1",
"typescript": "~3.9.6"
}
}
28 changes: 21 additions & 7 deletions src/action.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as core from "@actions/core";
import { GitHub } from "@actions/github";
import github from "@actions/github";
import semverGte from "semver/functions/gte";
import {
isSemVersionedRelease,
Expand All @@ -21,6 +21,14 @@ function ifErrorSubmitBug() {
}
}

function outputRefName(refName: string) {
core.setOutput("ref_name", refName);
}

function outputLatest(isLatest: boolean) {
core.setOutput("latest", isLatest.toString());
}

async function run() {
try {
if (!isPublishedRelease() && !isEditedRelease()) {
Expand All @@ -36,19 +44,25 @@ async function run() {
}

if (process.env.GITHUB_TOKEN) {
const octokit = new GitHub(process.env.GITHUB_TOKEN);
const octokit = github.getOctokit(process.env.GITHUB_TOKEN);
const { repoLatest, majorLatest } = await findLatestReleases(octokit);

const releaseVer = releaseTag();

if (semverGte(releaseVer, majorLatest)) {
const overridePubLatest = preferences.publishLatestTag && semverGte(releaseVer, repoLatest);
const overridePubLatest =
preferences.publishLatestTag && semverGte(releaseVer, repoLatest);

const { ref, latest } = await createRequiredRefs(octokit, overridePubLatest);
core.setOutput("ref", ref);
core.setOutput("latest", latest.toString());
const { ref, latest } = await createRequiredRefs(
octokit,
overridePubLatest
);
outputRefName(ref);
outputLatest(latest);
} else {
core.info("Nothing to do because release commit is earlier than major tag commit");
core.info(
"Nothing to do because release commit is earlier than major tag commit"
);
ifErrorSubmitBug();
}
} else {
Expand Down
18 changes: 9 additions & 9 deletions src/functions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import SemVer from "semver/classes/semver";
import * as core from "@actions/core";
import { context, GitHub } from "@actions/github";
import { context } from "@actions/github";
import { Octokit as GitHub } from "@octokit/core";
import coerce from "semver/functions/coerce";
import valid from "semver/functions/valid";
import major from "semver/functions/major";
Expand Down Expand Up @@ -122,8 +123,8 @@ export async function findLatestReleases(github: GitHub): Promise<LatestRelease>
pagination: nextPage,
});

for (const ref of repository.refs.refsList) {
const semverRef = semverParse(ref.ref.name);
for (const { ref } of repository.refs.refsList) {
const semverRef = semverParse(ref.name);
if (semverRef !== null) {
if (semverRef.major === major && semverGt(semverRef, majorLatest)) {
majorLatest = semverRef;
Expand All @@ -132,10 +133,6 @@ export async function findLatestReleases(github: GitHub): Promise<LatestRelease>
if (semverGt(semverRef, repoLatest)) {
repoLatest = semverRef;
}

if (core.isDebug()) {
core.debug(semverRef.version);
}
}
}

Expand All @@ -154,7 +151,10 @@ export async function findLatestReleases(github: GitHub): Promise<LatestRelease>
*
* @param {GitHub} github The octokit client for making requests
*/
export async function createRequiredRefs(github: GitHub, overridePublishLatest?: boolean): Promise<TaggedRelease> {
export async function createRequiredRefs(
github: GitHub,
overridePublishLatest?: boolean
): Promise<TaggedRelease> {
const mayor = majorVersion();

const ref = `${getPreferredRef()}/v${mayor}`;
Expand All @@ -181,7 +181,7 @@ async function createRef(github: GitHub, refName: string) {
ref: refName,
});

const matchingRef = matchingRefs.find((refObj) => {
const matchingRef = matchingRefs.find((refObj: { ref: string }) => {
return refObj.ref.endsWith(refName);
});

Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 1 addition & 3 deletions test-setup.ts → tests/test-setup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { Config } from "@jest/types";

export default async (_: Config.GlobalConfig) => {
export default async () => {
process.env.INPUT_PUBLISH_LATEST_TAG = "false";
process.env.INPUT_PREFER_BRANCH_RELEASES = "false";
};
Loading

0 comments on commit 90e5ff8

Please sign in to comment.