Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:mission-apprentissage/tjp-pilota…
Browse files Browse the repository at this point in the history
…ge into feat/formations-specifiques
  • Loading branch information
LucasDetre committed Dec 18, 2024
2 parents d12e17f + 4b552cf commit 218234e
Show file tree
Hide file tree
Showing 24 changed files with 381 additions and 24 deletions.
10 changes: 10 additions & 0 deletions .bin/commands.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ function Help() {
echo " init:env Update local env files using values from vault file"
echo " docker:login Login to ghcr.io"
echo " release:interactive Build & Push Docker image releases"
echo " release:manual Build & Push Docker image releases in a new release"
echo " release:candidate Build & Push Docker image releases in a release candidate"
echo " release:generate:rc-label Generate next rc label"
echo " release:generate:manual-label Generate next manual label"
echo " release:app Build & Push Docker image releases"
echo " deploy <env> --user <your_username> Deploy application to <env>"
echo " preview:build Build preview"
Expand Down Expand Up @@ -55,10 +57,18 @@ function release:candidate() {
"${SCRIPT_DIR}/release-candidate.sh" "$@"
}

function release:manual() {
"${SCRIPT_DIR}/release-manual.sh" "$@"
}

function release:generate:rc-label() {
"${SCRIPT_DIR}/generate-rc-label.sh" "$@"
}

function release:generate:manual-label() {
"${SCRIPT_DIR}/generate-manual-label.sh" "$@"
}

function deploy() {
"${SCRIPT_DIR}/deploy-app.sh" "$@"
}
Expand Down
71 changes: 71 additions & 0 deletions .bin/scripts/generate-manual-label.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env bash

set -euo pipefail

# Check if an argument is provided
if [[ $# -lt 1 ]]; then
echo "Error: No arguments provided."
echo "Usage: Provide 'patch', 'minor', or 'major' as the first argument."
exit 1
fi

readonly RC_TYPE=$1

case $RC_TYPE in
patch|minor|major)
;;
*)
echo "Invalid argument: $RC_TYPE"
echo "Usage: Provide 'patch', 'minor', or 'major' as the first argument."
exit 1
;;
esac

readonly VERSION=$("${ROOT_DIR}/.bin/scripts/get-version.sh")

generate_next_version() {
local last_current_branch_tag=$(git describe --tags --abbrev=0 --match="v[0-9]*.[0-9]*.[0-9]*")
local remote_tags=$(git ls-remote --tags origin | awk '{print $2}' | sed 's|refs/tags/||')
local current_commit_id=$(git rev-parse HEAD)
local current_version_commit_id=$(git rev-list -n 1 $VERSION 2> /dev/null)

if [ "$current_commit_id" == "$current_version_commit_id" ]; then
echo $VERSION;
return
fi;

local version=${last_current_branch_tag#v}

if [[ $version =~ ^([0-9]+)\.([0-9]+)\.([0-9]+).*$ ]]; then
major="${BASH_REMATCH[1]}"
minor="${BASH_REMATCH[2]}"
patch="${BASH_REMATCH[3]}"
else
echo "Invalid version format $version"
exit 1
fi

case $RC_TYPE in
major)
((major++))
minor=0
patch=0
;;
minor)
((minor++))
patch=0
;;
patch)
((patch++))
;;
*)
echo "Error: Invalid bump type. Use 'patch', 'minor', or 'major'."
exit 1
;;
esac

manual_version="$major.$minor.$patch"
echo $manual_version
}

echo $(generate_next_version "$@")
4 changes: 2 additions & 2 deletions .bin/scripts/generate-rc-label.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ esac

readonly VERSION=$("${ROOT_DIR}/.bin/scripts/get-version.sh")

generate_next_patch_version() {
generate_next_rc_version() {
local last_current_branch_tag=$(git describe --tags --abbrev=0 --match="v[0-9]*.[0-9]*.[0-9]*")
local remote_tags=$(git ls-remote --tags origin | awk '{print $2}' | sed 's|refs/tags/||')
local current_commit_id=$(git rev-parse HEAD)
Expand Down Expand Up @@ -77,4 +77,4 @@ generate_next_patch_version() {
echo $rc_version
}

echo $(generate_next_patch_version "$@")
echo $(generate_next_rc_version "$@")
35 changes: 35 additions & 0 deletions .bin/scripts/release-manual.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

set -euo pipefail


# Check if an argument is provided
if [[ $# -lt 1 ]]; then
echo "Error: No arguments provided."
echo "Usage: Provide 'patch', 'minor', or 'major' as the first argument."
exit 1
fi

readonly RC_TYPE=$1

case $RC_TYPE in
patch|minor|major)
;;
*)
echo "Invalid argument: $RC_TYPE"
echo "Usage: Provide 'patch', 'minor', or 'major' as the first argument."
exit 1
;;
esac

readonly VERSION=$("${ROOT_DIR}/.bin/scripts/get-version.sh")
NEXT_VERSION=$("$ROOT_DIR/.bin/scripts/generate-manual-label.sh" "$@")

echo "Creating release : $NEXT_VERSION"

echo "Création des images docker locales (docker build)"

echo "Build $NEXT_VERSION ..."
"$ROOT_DIR/.bin/scripts/release-app.sh" $NEXT_VERSION push
git tag -f "v$NEXT_VERSION"
git push -f origin "v$NEXT_VERSION"
8 changes: 4 additions & 4 deletions .github/workflows/_manual_release.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: Release candidate
name: Manual Release

on:
workflow_dispatch:
inputs:
release_type:
description: Le type de Release Candidate à générer
description: Le type de Release à générer
type: choice
required: true
options:
Expand All @@ -15,7 +15,7 @@ on:
workflow_call:
inputs:
release_type:
description: Le type de Release Candidate à générer
description: Le type de Release à générer
type: string
required: false

Expand Down Expand Up @@ -89,7 +89,7 @@ jobs:
run: echo "VERSION=$(git describe --tags --abbrev=0 | cut -c2-)" >> "$GITHUB_OUTPUT"

- name: bump and release
run: yarn release:candidate ${{ inputs.release_type }}
run: yarn release:manual ${{ inputs.release_type }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
Expand Down
141 changes: 141 additions & 0 deletions .github/workflows/_release_candidate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
name: Release candidate

on:
workflow_dispatch:
inputs:
release_type:
description: Le type de Release Candidate à générer
type: choice
required: true
options:
- major
- minor
- patch

workflow_call:
inputs:
release_type:
description: Le type de Release Candidate à générer
type: string
required: false

secrets:
DEPLOY_SSH_PRIVATE_KEY:
description: SSH private key
required: true
DEPLOY_PASS:
description: SSH PWD TO DEPLOY
required: true
SLACK_WEBHOOK:
description: Slack webhook URL
required: true
VAULT_PWD:
description: Vault Password
required: true

jobs:
tests:
uses: "./.github/workflows/ci.yml"

release:
concurrency:
group: "release-${{ github.workflow }}-${{ github.ref }}"
permissions: write-all
outputs:
VERSION: ${{ steps.get-version.outputs.VERSION }}
PREV_VERSION: ${{ steps.get-prev-version.outputs.VERSION }}
runs-on: ubuntu-latest
steps:
- name: Checkout project
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: true

- uses: actions/setup-node@v3
with:
node-version: 20

- uses: actions/cache@v3
with:
path: |
**/node_modules
.yarn/install-state.gz
.yarn/cache
key: yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: yarn-

- name: Install dependencies
run: yarn install

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
platforms: linux/amd64
install: true

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

- name: Expose GitHub Runtime
uses: crazy-max/ghaction-github-runtime@v2

- name: Retrieve previous version
id: get-prev-version
run: echo "VERSION=$(git describe --tags --abbrev=0 | cut -c2-)" >> "$GITHUB_OUTPUT"

- name: bump and release
run: yarn release:candidate ${{ inputs.release_type }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
GITHUB_REF_NAME: ${{ env.GITHUB_REF_NAME }}

- name: Retrieve new version
id: get-version
run: echo "VERSION=$(git describe --tags --abbrev=0 | cut -c2-)" >> "$GITHUB_OUTPUT"

docker-scout:
if: needs.release.outputs.VERSION != needs.release.outputs.PREV_VERSION && needs.release.outputs.PREV_VERSION != ''
concurrency:
group: "scout-${{ github.workflow }}-${{ github.ref }}"
needs: ["release"]
runs-on: ubuntu-latest
steps:
- name: Authenticate to Docker
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PAT }}

- name: Server Docker Scout
uses: docker/scout-action@v1
with:
command: quickview,cves,recommendations,compare
image: ghcr.io/mission-apprentissage/ij_orion_server:${{ needs.release.outputs.VERSION }}
to: ghcr.io/mission-apprentissage/ij_orion_server:${{ needs.release.outputs.PREV_VERSION }}
sarif-file: sarif-server.output.json

- name: Server Docker Upload SARIF result
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: sarif-server.output.json
category: Docker Server

- name: UI Docker Scout
uses: docker/scout-action@v1
with:
command: quickview,cves,recommendations,compare
image: ghcr.io/mission-apprentissage/ij_orion_ui:${{ needs.release.outputs.VERSION }}-production
to: ghcr.io/mission-apprentissage/ij_orion_ui:${{ needs.release.outputs.PREV_VERSION }}-production
sarif-file: sarif-ui.output.json

- name: UI Docker Upload SARIF result
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: sarif-ui.output.json
category: Docker UI
1 change: 1 addition & 0 deletions docs/developpement/developpement.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Commandes:
- `yarn cli migrations:status`: Vérification du status des migrations
- `yarn cli migrations:up`: Execution des migrations
- `yarn cli migrations:create`: Creation d'une nouvelle migration
- `yarn cli migrations:generate-schema`: Génère le schéma de la base de données

### Lancement de l'application

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"prettier:check": "prettier --check -u .",
"release": "semantic-release",
"release:interactive": ".bin/product release:interactive",
"release:manual": ".bin/product release:manual",
"release:candidate": ".bin/product release:candidate",
"postinstall": "husky",
"talisman:add-exception": "yarn node-talisman --githook pre-commit -i",
Expand Down
1 change: 0 additions & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"dev": "tsup-node --env.TSUP_WATCH true",
"build": "tsup-node --env.NODE_ENV production",
"typecheck": "NODE_OPTIONS='--max-old-space-size=8192' tsc --noEmit",
"kysely": "npx kysely-codegen --schema public --out-file=./src/db/schema.ts --dialect postgres && yarn prettier:fix",
"generate:seed": "./seed/generate-seed.sh"
},
"dependencies": {
Expand Down
11 changes: 11 additions & 0 deletions server/src/commands.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { exec } from "node:child_process";
import { setMaxListeners } from "node:events";
import { writeFileSync } from "node:fs";
import path from "node:path";
Expand Down Expand Up @@ -156,6 +157,16 @@ export const down = async (db: Kysely<unknown>) => {};
);
});

program
.command("migrations:generate-schema")
.description("Generate kysely schema")
.action(async () => {
console.log(path.join(__dirname(), "../src", "db/schema.ts"));
exec(
`DATABASE_URL="${config.psql.uri}" npx kysely-codegen --schema public --out-file=${path.join(__dirname(), "../src", "db/schema.ts")} --dialect postgres && yarn prettier:fix`
);
});

productCommands(program);

export async function startCLI() {
Expand Down
1 change: 1 addition & 0 deletions server/src/db/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,7 @@ export interface User {
enabled: Generated<boolean>;
sub: string | null;
lastSeenAt: Timestamp | null;
fonction: string | null;
}

export interface DB {
Expand Down
2 changes: 2 additions & 0 deletions server/src/migrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ import * as migration_1730888921742 from "./migration_1730888921742";
import * as migration_1731666807035 from "./migration_1731666807035";
import * as migration_1732531157506 from "./migration_1732531157506";
import * as migration_1732800962380 from "./migration_1732800962380";
import * as migration_1733743141284 from "./migration_1733743141284";

type Migration = {
up: (db: Kysely<any>) => Promise<void>;
Expand Down Expand Up @@ -199,4 +200,5 @@ export const migrations: Migrations = {
migration_1731666807035,
migration_1732531157506,
migration_1732800962380,
migration_1733743141284,
};
Loading

0 comments on commit 218234e

Please sign in to comment.