Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
FantasticFiasco committed Oct 22, 2023
1 parent 2bfaebf commit a0f073f
Show file tree
Hide file tree
Showing 11 changed files with 450 additions and 184 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: CI/CD

on:
push:
branches:
- "**"
paths:
- .github/workflows/ci-cd.yml
- src/**
- scripts/**
- test/**
- Directory.Build.props
tags:
- "**"
workflow_dispatch:

permissions:
contents: write # Needed to create a GitHub Release

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# Build
- run: dotnet build --configuration Release
# Test
- run: dotnet test --configuration Release --no-build --collect:"XPlat Code Coverage"
env:
AWS_REGION: eu-west-1
AWS_USER_WITH_PERMISSIONS_ACCESS_KEY_ID: ${{ secrets.AWS_USER_WITH_PERMISSIONS_ACCESS_KEY_ID }}
AWS_USER_WITH_PERMISSIONS_SECRET_ACCESS_KEY: ${{ secrets.AWS_USER_WITH_PERMISSIONS_SECRET_ACCESS_KEY }}
AWS_USER_WITHOUT_PERMISSIONS_ACCESS_KEY_ID: ${{ secrets.AWS_USER_WITHOUT_PERMISSIONS_ACCESS_KEY_ID }}
AWS_USER_WITHOUT_PERMISSIONS_SECRET_ACCESS_KEY: ${{ secrets.AWS_USER_WITHOUT_PERMISSIONS_SECRET_ACCESS_KEY }}
AWS_ROLE_ARN: ${{ secrets.AWS_ROLE_ARN }}
AWS_API_GATEWAY_URL: ${{ secrets.AWS_API_GATEWAY_URL }}
AWS_S3_BUCKET_NAME: ${{ secrets.AWS_S3_BUCKET_NAME }}
AWS_S3_BUCKET_URL: ${{ secrets.AWS_S3_BUCKET_URL }}
- uses: codecov/codecov-action@v3
# Pack
- run: dotnet pack --configuration Release --no-build
- run: |
mkdir dist
mv src/bin/Release/*.nupkg ./dist
mv src/bin/Release/*.snupkg ./dist
# Release
- run: |
pushd ./scripts
npm ci
npm run release
popd
if: startsWith(github.ref, 'refs/tags/')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
20 changes: 0 additions & 20 deletions .github/workflows/ci.yml

This file was deleted.

55 changes: 0 additions & 55 deletions appveyor.yml

This file was deleted.

109 changes: 0 additions & 109 deletions build/build.ps1

This file was deleted.

1 change: 1 addition & 0 deletions scripts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules
12 changes: 12 additions & 0 deletions scripts/github-actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// @ts-check

// GitHub token
export const GITHUB_TOKEN = process.env.GITHUB_TOKEN ?? '';

// git tag
const prefix = 'refs/tags/';
const ref = process.env.GITHUB_REF ?? '';
export const GIT_TAG = ref.startsWith(prefix) ? ref.substring(prefix.length) : '';

// Repo slug, e.g. "owner_name/repo_name"
export const REPO = process.env.GITHUB_REPOSITORY ?? '';
57 changes: 57 additions & 0 deletions scripts/github.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// @ts-check

import { Octokit } from '@octokit/rest';
import { readFileSync } from 'fs';
import { basename } from 'path';
import { info } from './log.js';

/**
* @param {string} githubToken
* @param {string} owner
* @param {string} repo
* @param {string} tagName
* @param {string} version
*/
export const createRelease = async (githubToken, owner, repo, tagName, version) => {
info(`github: create release from tag ${tagName}`);

const octokit = new Octokit({
auth: githubToken,
});

const release = await octokit.repos.createRelease({
owner,
repo,
tag_name: tagName,
name: `Release ${version}`,
body: 'TODO',
draft: true,
});

return {
releaseId: release.data.id,
};
};

/**
* @param {string} githubToken
* @param {string} owner
* @param {string} repo
* @param {number} releaseId
* @param {string} assetFileName
*/
export const uploadAsset = async (githubToken, owner, repo, releaseId, assetFileName) => {
info(`github: upload asset ${assetFileName}`);

const octokit = new Octokit({
auth: githubToken,
});

await octokit.repos.uploadReleaseAsset({
owner,
repo,
release_id: releaseId,
name: basename(assetFileName),
data: readFileSync(assetFileName).toString(),
});
};
34 changes: 34 additions & 0 deletions scripts/log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// @ts-check

export const RED = '[31m';
export const YELLOW = '[33;1m';

/**
* @param {string} message
*/
export const info = (message) => {
console.log(message);
};

/**
* @param {string} message
*/
export const error = (message) => {
log(RED, message);
};

/**
* @param {string} message
*/
export const fatal = (message) => {
log(RED, message);
process.exitCode = 1;
};

/**
* @param {string} color
* @param {string} message
*/
export const log = (color, message) => {
console.log('\x1b%s%s\x1b[0m', color, message);
};
Loading

0 comments on commit a0f073f

Please sign in to comment.