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 79d18b9 commit 67afe67
Show file tree
Hide file tree
Showing 13 changed files with 480 additions and 176 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 }}
27 changes: 27 additions & 0 deletions .github/workflows/infrastructure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: infrastructure

on:
push:
branches:
- "**"
paths:
- .github/workflows/infrastructure.yml
- infrastructure/**
workflow_dispatch:

defaults:
run:
working-directory: infrastructure

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: lts/*
check-latest: true
- run: npm ci
- run: npm run build
- run: npm run lint
55 changes: 0 additions & 55 deletions appveyor.yml

This file was deleted.

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

This file was deleted.

4 changes: 2 additions & 2 deletions infrastructure/lib/api-gateway/handlers/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ interface HttpResponse {
interface ReceivedRequest {
method: string
path: string
queryStringParameters: { [name: string]: string[] | undefined; } | null
headers: { [name: string]: string[] | undefined; } | null
queryStringParameters: { [name: string]: string[] | undefined } | null
headers: { [name: string]: string[] | undefined } | null
body: string | null
}

Expand Down
2 changes: 1 addition & 1 deletion infrastructure/lib/users/users-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class UsersStack extends Stack {
new PolicyStatement({
actions: ['execute-api:Invoke', 'execute-api:ManageConnections'],
resources: ['arn:aws:execute-api:*:*:*'],
})
}),
)

// Create outputs
Expand Down
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 67afe67

Please sign in to comment.