Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add continuous integration and deployment #1

Merged
merged 3 commits into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: continuous deployment

on:
workflow_dispatch:
push:
branches: [main]

jobs:
deployment:
runs-on: ubuntu-latest
steps:

- name: Checkout source files
uses: actions/checkout@v3

- name: Install dependencies
run: npm ci

- name: Build project
run: npm exec nx build --prod

- name: Find new product version
uses: arwynfr/actions-conventional-versioning/get-newVersion@v3
id: next-version
with:
allow-additional-modifiers: true
feat-upgrades-minor: false
strict-types: true

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and publish docker image
run: >
docker build --push
--file build/Dockerfile
--tag ghcr.io/team-gsri/apps-admin-client:${{ steps.next-version.outputs.next-version }}
dist/gsri-admin

- name: Publish GitHub release
uses: arwynfr/actions-conventional-versioning@v2
26 changes: 26 additions & 0 deletions .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: continuous integration

on:
workflow_dispatch:
pull_request:
branches: [main]

jobs:
integration:
runs-on: ubuntu-latest
steps:

- name: Checkout source files
uses: actions/checkout@v3

- name: Install dependencies
run: npm ci

- name: Lint sources
run: npm exec nx lint

- name: Run unit tests
run: npm exec nx test

- name: Build project
run: npm exec nx build
2 changes: 2 additions & 0 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM nginx:1.25.0-alpine
COPY . /srv/www
28 changes: 28 additions & 0 deletions build/Dockerize.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[CmdletBinding()]
param (
[Parameter()]
[ValidateScript({ $_ | Test-Path -PathType Container }, ErrorMessage = 'Path must be a valid directory')]
[string]
$Path = (Join-Path $PSScriptRoot ../dist/gsri-admin | Convert-Path),

[Parameter()]
[string]
$Image = 'ghcr.io/team-gsri/apps-admin-client',

[Parameter()]
[semver]
$Tag,

[Parameter()]
[ValidateScript({ $_ | Test-Path -PathType Leaf }, ErrorMessage = 'Path must be a valid file')]
[string]
$Dockerfile = (Join-Path $PSScriptRoot Dockerfile | Convert-Path)
)

if ($null -eq $Tag) {
Import-Module -Force StepSemVer
$Tag = [semver]$(git describe --tags 2>&1) | Step-SemVer -BumpType patch -PreRelease 'SNAPSHOT'
Write-Verbose "Docker tag: $Tag"
}

docker build --file "$Dockerfile" --tag "${Image}:${Tag}" "${Path}"
19 changes: 17 additions & 2 deletions project.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@
"sourceRoot": "./src",
"tags": [],
"targets": {
"dockerize": {
"command": "pwsh build/Dockerize.ps1 -Verbose",
"dependsOn": ["build"]
},
"analyze": {
"executor": "nx:run-commands",
"options": {
"commands": [
"nx build --configuration=development",
"source-map-explorer dist/gsri-admin/*.js --sort"
],
"parallel": false
},
"outputs": ["{workspaceRoot}/dist/gsri-admin/stats.json"]
},
"build": {
"executor": "@angular-devkit/build-angular:browser",
"outputs": ["{options.outputPath}"],
Expand All @@ -24,8 +39,8 @@
"budgets": [
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1mb"
"maximumWarning": "2mb",
"maximumError": "5mb"
},
{
"type": "anyComponentStyle",
Expand Down
2 changes: 1 addition & 1 deletion src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="container-fluid p-5 bg-dark text-white text-center">
<h1> {{title}} </h1>
<h1>{{title}}</h1>
</div>

<nav class="navbar navbar-expand-sm bg-primary navbar-dark">
Expand Down
6 changes: 3 additions & 3 deletions src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ describe('AppComponent', () => {
fixture.detectChanges();
const compiled = fixture.nativeElement as HTMLElement;
expect(compiled.querySelector('h1')?.textContent).toContain(
'Welcome gsri-admin'
'GSRI Administration'
);
});

it(`should have as title 'gsri-admin'`, () => {
it(`should have as title 'GSRI Administration'`, () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app.title).toEqual('gsri-admin');
expect(app.title).toEqual('GSRI Administration');
});
});
4 changes: 2 additions & 2 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { Component } from '@angular/core';
import { RouterModule } from '@angular/router';
import { FormsModule } from '@angular/forms';
import { MessagesComponent } from './messages/messages.component';
import { JoueursComponent } from './joueurs/joueurs-list/joueurs-list.component';
import { JoueursListComponent } from './joueurs/joueurs-list/joueurs-list.component';

@Component({
standalone: true,
imports: [
RouterModule,
FormsModule,
JoueursComponent,
JoueursListComponent,
MessagesComponent,
],
selector: 'gsri-admin-root',
Expand Down
4 changes: 2 additions & 2 deletions src/app/app.routes.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Route } from '@angular/router';
import { JoueursComponent } from './joueurs/joueurs-list/joueurs-list.component';
import { JoueursListComponent } from './joueurs/joueurs-list/joueurs-list.component';
import { JoueursDetailsComponent } from './joueurs/joueurs-details/joueurs-details.component';

export const appRoutes: Route[] = [
{ path: '', redirectTo: '/joueurs', pathMatch: 'full' },
{ path: 'joueurs/:id', component: JoueursDetailsComponent },
{ path: 'joueurs', component: JoueursComponent },
{ path: 'joueurs', component: JoueursListComponent },
];
5 changes: 4 additions & 1 deletion src/app/configuration/configuration.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { TestBed } from '@angular/core/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';

import { ConfigurationService } from './configuration.service';

describe('ConfigurationService', () => {
let service: ConfigurationService;

beforeEach(() => {
TestBed.configureTestingModule({});
TestBed.configureTestingModule({
imports: [HttpClientTestingModule]
});
service = TestBed.inject(ConfigurationService);
});

Expand Down
5 changes: 4 additions & 1 deletion src/app/joueurs/joueur.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { TestBed } from '@angular/core/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';

import { JoueurService } from './joueur.service';

describe('JoueursService', () => {
let service: JoueurService;

beforeEach(() => {
TestBed.configureTestingModule({});
TestBed.configureTestingModule({
imports: [HttpClientTestingModule]
});
service = TestBed.inject(JoueurService);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { JoueursDetailsComponent } from './joueurs-details.component';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { RouterTestingModule } from '@angular/router/testing';

describe('JoueursDetailsComponent', () => {
let component: JoueursDetailsComponent;
let fixture: ComponentFixture<JoueursDetailsComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [JoueursDetailsComponent],
imports: [
JoueursDetailsComponent,
HttpClientTestingModule,
RouterTestingModule
],
}).compileComponents();

fixture = TestBed.createComponent(JoueursDetailsComponent);
Expand Down
11 changes: 6 additions & 5 deletions src/app/joueurs/joueurs-list/joueurs-list.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { JoueursComponent } from './joueurs-list.component';
import { JoueursListComponent } from './joueurs-list.component';
import { HttpClientTestingModule } from '@angular/common/http/testing';

describe('JoueursComponent', () => {
let component: JoueursComponent;
let fixture: ComponentFixture<JoueursComponent>;
let component: JoueursListComponent;
let fixture: ComponentFixture<JoueursListComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [JoueursComponent],
imports: [JoueursListComponent, HttpClientTestingModule],
}).compileComponents();

fixture = TestBed.createComponent(JoueursComponent);
fixture = TestBed.createComponent(JoueursListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
Expand Down
2 changes: 1 addition & 1 deletion src/app/joueurs/joueurs-list/joueurs-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { RouterModule } from '@angular/router';
templateUrl: './joueurs-list.component.html',
styleUrls: ['./joueurs-list.component.scss'],
})
export class JoueursComponent implements OnInit {
export class JoueursListComponent implements OnInit {

joueurs: Joueur[] = [];

Expand Down