Skip to content

Commit

Permalink
feat: init repository
Browse files Browse the repository at this point in the history
  • Loading branch information
uanid committed Jun 11, 2024
1 parent fddbf66 commit 2000916
Show file tree
Hide file tree
Showing 12 changed files with 9,691 additions and 1 deletion.
22 changes: 22 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Node.js CI

on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
- run: npm ci
- run: npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.GITHUB_TOKEN }}
FORCE_COLOR: "1"
175 changes: 175 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore

# Logs

logs
_.log
npm-debug.log_
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Caches

.cache

# Diagnostic reports (https://nodejs.org/api/report.html)

report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json

# Runtime data

pids
_.pid
_.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover

lib-cov

# Coverage directory used by tools like istanbul

coverage
*.lcov

# nyc test coverage

.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)

.grunt

# Bower dependency directory (https://bower.io/)

bower_components

# node-waf configuration

.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)

build/Release

# Dependency directories

node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)

web_modules/

# TypeScript cache

*.tsbuildinfo

# Optional npm cache directory

.npm

# Optional eslint cache

.eslintcache

# Optional stylelint cache

.stylelintcache

# Microbundle cache

.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history

.node_repl_history

# Output of 'npm pack'

*.tgz

# Yarn Integrity file

.yarn-integrity

# dotenv environment variable files

.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)

.parcel-cache

# Next.js build output

.next
out

# Nuxt.js build / generate output

.nuxt
dist

# Gatsby files

# 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

# vuepress v2.x temp and cache directory

.temp

# Docusaurus cache and generated files

.docusaurus

# Serverless directories

.serverless/

# FuseBox cache

.fusebox/

# DynamoDB Local files

.dynamodb/

# TernJS port file

.tern-port

# Stores VSCode versions used for testing VSCode extensions

.vscode-test

# yarn v2

.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# IntelliJ based IDEs
.idea

# Finder (MacOS) folder config
.DS_Store
34 changes: 34 additions & 0 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
[
"@semantic-release/changelog",
{
"changelogFile": "CHANGELOG.md"
}
],
[
"@semantic-release/exec",
{
"publish": "npm run build"
}
],
"@semantic-release/npm",
[
"@semantic-release/git",
{
"assets": [
"package.json",
"CHANGELOG.md"
]
}
],
[
"@semantic-release/github",
{
"addReleases": "bottom"
}
]
]
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
# semantic-release-gitlabmonorepo
PUBG DevOps Managed Repository

To install dependencies:

```bash
npm install
```

To build:

```bash
npm run build
```
7 changes: 7 additions & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {publish} from "./publish.js";
import {verifyConditions} from "./verifyConditions.js";

export {
verifyConditions,
publish,
}
68 changes: 68 additions & 0 deletions lib/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import typia from "typia";
import type {VerifyConditionsContext} from "semantic-release";
import {execSync} from "node:child_process";
import gitUrlParse from 'git-url-parse';
import {trim, trimEnd} from 'lodash-es';
import urlJoin from "url-join";

export interface UserConfig {
gitlabUrl: string | undefined;
projectId: string | undefined;
assets: Assets[] | undefined;
commitTitle: string | undefined;
}

export interface Assets {
path: string;
}

export interface PluginConfig {
gitlabBaseUrl: string;
gitlabProjectId: string;
gitlabToken: string;
assets: Assets[];
commitTitle: string;
}

export function resolvePluginConfig(userConfig: UserConfig, context: VerifyConditionsContext): PluginConfig {
assertUserConfig(userConfig);
const gitlabUrl = userConfig.gitlabUrl || context.env['CI_SERVER_URL'] || context.env['CI_SERVER_URL'] || 'https://gitlab.com';
let projectId = userConfig.projectId || context.env['CI_PROJECT_ID'] || context.env['CI_PROJECT_PATH'] || getProjectId(getOriginUrl(context));
if (projectId.includes('/')) {
projectId = encodeURIComponent(projectId);
}
const gitlabToken: string | undefined = context.env['GITLAB_TOKEN'] || context.env['GITLAB_ACCESS_TOKEN'];
if (!gitlabToken) {
throw new Error('GITLAB_TOKEN or GITLAB_ACCESS_TOKEN env is required');
}
const assets = userConfig.assets || [];
const commitTitle = userConfig.commitTitle || 'chore(release): ${nextRelease.version} [skip ci]';

const pluginConfig: PluginConfig = {
gitlabBaseUrl: urlJoin(gitlabUrl, 'api/v4', 'projects', projectId),
gitlabProjectId: projectId,
gitlabToken: gitlabToken,
assets: assets,
commitTitle: commitTitle,
}
return assertPluginConfig(pluginConfig);
}

function getOriginUrl(context: VerifyConditionsContext): string {
context.logger.log('Getting origin url via command call $ git remote get-url origin');
const buf = execSync('git remote get-url origin', { cwd: context.cwd, encoding: 'utf-8' });
return buf.toString().trim();
}

function getProjectId(origin: string): string {
const parsed = gitUrlParse(origin);

// trim start and end "/"
// trim end ".git"
return trim(trimEnd(parsed.pathname, '.git'), '/');
}

export const isUserConfig = typia.createIs<UserConfig>();
export const assertUserConfig = typia.createAssert<UserConfig>();
export const isPluginConfig = typia.createIs<PluginConfig>();
export const assertPluginConfig = typia.createAssert<PluginConfig>();
Loading

0 comments on commit 2000916

Please sign in to comment.