Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-enplore committed Jan 23, 2023
1 parent f5445be commit acb6308
Show file tree
Hide file tree
Showing 8 changed files with 6,484 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.vscode
node_modules
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Version filer

The ever looming nut cracker has been solved, and the solution is here to benefit everyone.

Allright. You have a github repo, you want the version to be automatically bumped. But the new version needs to be persisted in a file in the repository, the issue is your organization uses branch protection rules and reviewed PRs to merge with main.

You and your team have been fighting this issue for years on end. Prehooks? Github allows apps to pass branch protection rules?
- No, the solution is so simple you will reconsider your career when you see it.

Simply do the file committing on the PR, and have another action create a release (git tag) on merge with main.

- But PRs get outdated?
- Yes they do, but doesn't your organization require PRs to be up to date with main before merging? They do, and github automatically brings PR-branches up to date with the base branch before merging.

- Have this action rerun on all commits to the PR and you should be golden. I hope.

Enjoy!
35 changes: 35 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: 'Version Filer'
description: 'Agnostic way of writing a string to a file'
author: 'Simon Blomsterlund'
inputs:
prepend:
required: false
description: 'string that goes before the value'
default: '__version__='

value:
required: true
description: 'the actual value'

append:
required: false
description: 'string that goes after the value'
default: ''

filename:
required: false
description: 'Name of the file'
default: '__version__.py'

filelocation:
required: false
description: 'File location relative to root, leave empty for root'
default: '/'

one_line_comment_sign:
required: false
description: 'Sign that goes before a single line comment in your programming language'
default: '#'
runs:
using: 'node18'
main: 'dist/index.js'
66 changes: 66 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(require("@actions/core"));
const fs = __importStar(require("node:fs/promises"));
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
const prepend = core.getInput('prepend');
const value = core.getInput('value');
const append = core.getInput('append');
const filename = core.getInput('filename');
const filelocation = core.getInput('filelocation');
const one_line_comment_sign = core.getInput('one_line_comment_sign');
const createdAt = new Date().toISOString();
core.info(`Going to write ${prepend}${value}${append} to file ${filelocation}${filename}`);
const comment = `${one_line_comment_sign} Written by version-filer, manual editing of this file might not cause desired effect. ${createdAt}`;
const valueString = `${prepend}${value}${append}`;
yield writeFile(filename, filelocation, comment, valueString);
core.setOutput('time', new Date().toTimeString());
}
catch (error) {
if (error instanceof Error)
core.setFailed(error.message);
}
});
}
function writeFile(filename, filelocation, comment, value) {
return __awaiter(this, void 0, void 0, function* () {
const file = filelocation + filename;
const content = comment + "\n" + value;
return fs.writeFile(file, content);
});
}
run();
Loading

0 comments on commit acb6308

Please sign in to comment.