Skip to content

Commit

Permalink
Merge pull request #884 from NFDI4Chem/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
NishaSharma14 authored Nov 10, 2023
2 parents effc935 + 30cc6e1 commit b633d46
Show file tree
Hide file tree
Showing 121 changed files with 8,999 additions and 1,898 deletions.
File renamed without changes.
33 changes: 33 additions & 0 deletions .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Docs Deployment - GitHub pages
on:
workflow_dispatch: {}
push:
branches:
- development
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-node@v3
with:
node-version: 16
cache: npm
- run: npm ci
- name: Build
run: npm run docs:build
- uses: actions/configure-pages@v2
- uses: actions/upload-pages-artifact@v1
with:
path: docs/.vitepress/dist
- name: Deploy
id: deployment
uses: actions/[email protected]
79 changes: 46 additions & 33 deletions .github/workflows/build.yml → .github/workflows/dev-build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name : Deploy to Dev
name : Setup, Build and Publish to Dev

on:
push:
Expand All @@ -11,11 +11,16 @@ env:
DEPLOYMENT_NAME: nmrxiv-nmrxiv-app
SCHEDULER_DEPLOYMENT_NAME: nmrxiv-scheduler
WORKER_DEPLOYMENT_NAME: nmrxiv-worker
REPOSITORY_NAME: nmrxiv-dev
APP_IMAGE: nmrxiv-app
NGINX_IMAGE: nmrxiv-nginx
DOCKER_HUB_USERNAME : ${{ secrets.DOCKER_HUB_USERNAME }}
DOCKER_HUB_PASSWORD : ${{ secrets.DOCKER_HUB_PASSWORD }}
REPOSITORY_NAME: nmrxiv
REPOSITORY_NAMESPACE: nfdi4chem
DEV_URL: https://dev.nmrxiv.org

jobs:
# php-unit-test:
# uses: NFDI4Chem/nmrxiv/.github/workflows/test.yml@development

php-unit-test:
name: Run test
runs-on: ubuntu-latest
Expand Down Expand Up @@ -43,7 +48,7 @@ jobs:
composer install --ignore-platform-reqs
- name: Prepare Laravel Application
run: |
php -r "file_exists('.env') || copy('.env.ci.dev', '.env');"
php -r "file_exists('.env') || copy('.env.ci.test', '.env');"
echo AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID_DEV }} >> .env
echo AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY_DEV }} >> .env
Expand All @@ -63,12 +68,13 @@ jobs:
- name: Run Test
run: php artisan test --parallel


setup-build-publish-deploy:
name: Build & deploy to development
if: github.ref == 'refs/heads/development'
runs-on: ubuntu-latest
needs: php-unit-test
environment:
name: Dev
url: ${{ env.DEV_URL }}
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -79,40 +85,47 @@ jobs:
service_account_key: ${{ secrets.GKE_SA_KEY }}
project_id: ${{ secrets.GKE_PROJECT }}

# Configure docker to use the gcloud command-line tool as a credential helper
- run: |-
gcloud auth configure-docker europe-west3-docker.pkg.dev
# Get the GKE credentials so we can deploy to the cluster
# Get the GKE credentials
- uses: google-github-actions/[email protected]
with:
cluster_name: ${{ env.GKE_CLUSTER }}
location: ${{ env.GKE_ZONE }}
credentials: ${{ secrets.GKE_SA_KEY }}

# Build the Docker image
- name: Build App Image
run: |-
docker build -f ./resources/ops/docker/app/app.dockerfile \
--tag "europe-west3-docker.pkg.dev/$PROJECT_ID/$REPOSITORY_NAME/$APP_IMAGE:latest" \
--build-arg GITHUB_SHA="$GITHUB_SHA" \
--build-arg GITHUB_REF="$GITHUB_REF" \
.
- name: Build Nginx Image
run: |-
docker build -f ./resources/ops/docker/nginx/nginx.dockerfile \
--tag "europe-west3-docker.pkg.dev/$PROJECT_ID/$REPOSITORY_NAME/$NGINX_IMAGE:latest" \
--build-arg GITHUB_SHA="$GITHUB_SHA" \
--build-arg GITHUB_REF="$GITHUB_REF" \
.
# Push the Docker image to Google Container Registry
- name: Publish App Image to GCR
run: |-
docker push "europe-west3-docker.pkg.dev/$PROJECT_ID/$REPOSITORY_NAME/$APP_IMAGE:latest"
# Login to Docker
- name: Log in to Docker Hub
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
with:
username: ${{ env.DOCKER_HUB_USERNAME }}
password: ${{ env.DOCKER_HUB_PASSWORD }}

- name: Publish Nginx Image to GCR
run: |-
docker push "europe-west3-docker.pkg.dev/$PROJECT_ID/$REPOSITORY_NAME/$NGINX_IMAGE:latest"
# Build and push the app Docker image
- name: Build and push App Docker image
uses: docker/build-push-action@v4
with:
context: .
file: ./resources/ops/docker/app/app.dockerfile
push: true
build-args: |
RELEASE_VERSION=dev-app-latest
tags: ${{ env.REPOSITORY_NAMESPACE }}/${{ env.REPOSITORY_NAME }}:dev-app-latest
username: ${{ env.DOCKER_HUB_USERNAME }}
password: ${{ env.DOCKER_HUB_PASSWORD }}

# Build and push the nginx Docker image
- name: Build and push Nginx Docker image
uses: docker/build-push-action@v4
with:
context: .
file: ./resources/ops/docker/nginx/nginx.dockerfile
push: true
build-args: |
RELEASE_VERSION=dev-nginx-latest
tags: ${{ env.REPOSITORY_NAMESPACE }}/${{ env.REPOSITORY_NAME }}:dev-nginx-latest
username: ${{ env.DOCKER_HUB_USERNAME }}
password: ${{ env.DOCKER_HUB_PASSWORD }}

# Deploy the latest Docker image to the GKE cluster
- name: Deploy
run: |-
kubectl rollout restart deployment/$DEPLOYMENT_NAME
Expand Down
52 changes: 52 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name : Test

on:
workflow_call:

jobs:
php-unit-test:
name: Run test
runs-on: ubuntu-latest
container:
image: kirschbaumdevelopment/laravel-test-runner:8.2

services:
postgres:
image: postgres:13
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: nmrxiv
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

steps:
- uses: actions/checkout@v1
with:
fetch-depth: 1

- name: Install composer dependencies
run: |
composer install --ignore-platform-reqs
- name: Prepare Laravel Application
run: |
php -r "file_exists('.env') || copy('.env.ci.test', '.env');"
echo AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID_DEV }} >> .env
echo AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY_DEV }} >> .env
echo MEILISEARCH_KEY=${{ secrets.MEILISEARCH_KEY_DEV }} >> .env
echo MEILISEARCH_PUBLICKEY=${{ secrets.MEILISEARCH_PUBLICKEY_DEV }} >> .env
echo TWITTER_CLIENT_ID=${{ secrets.TWITTER_CLIENT_ID_DEV }} >> .env
echo TWITTER_CLIENT_SECRET=${{ secrets.TWITTER_CLIENT_SECRET_DEV }} >> .env
echo GITHUB_CLIENT_ID=${{ secrets.CLIENT_ID_GITHUB_DEV }} >> .env
echo GITHUB_CLIENT_SECRET=${{ secrets.CLIENT_SECRET_GITHUB_DEV }} >> .env
php artisan key:generate
php artisan migrate --seed
- name: Install front-end dependencies
run: |
npm install
npm run build
- name: Run Test
run: php artisan test --parallel
146 changes: 81 additions & 65 deletions app/Actions/Project/AssignIdentifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
namespace App\Actions\Project;

use App\Models\Project;
use App\Models\Study;
use App\Models\Ticker;
use App\Services\DOI\DOIService;
use Illuminate\Support\Collection;

class AssignIdentifier
{
Expand All @@ -21,83 +23,97 @@ public function __construct(DOIService $doiService)
}

/**
* Archive the given project.
* Archive the given model.
*
* @param mixed $project
* @param mixed $model
* @return void
*/
public function assign($project)
public function assign($model)
{
$projectIdentifier = $project->identifier ? $project->identifier : null;

if ($projectIdentifier == null) {
$projectTicker = Ticker::whereType('project')->first();
$projectIdentifier = $projectTicker->index + 1;
$projectTicker->index = $projectIdentifier;
$projectTicker->save();

$project->identifier = $projectIdentifier;
$project->save();
$project->fresh()->generateDOI($this->doiService);
$project = null;
$studies = null;
if ($model instanceof Project) {
$project = $model;
} elseif ($model instanceof Collection) {
$studies = $model;
}

$studies = $project->studies;
foreach ($studies as $study) {
$studyIdentifier = $study->identifier ? $study->identifier : null;

if ($studyIdentifier == null) {
$studyTicker = Ticker::whereType('study')->first();
$studyIdentifier = $studyTicker->index + 1;
$study->identifier = $studyIdentifier;
$studyTicker->index = $studyIdentifier;
$studyTicker->save();
}
$study->save();
$study->generateDOI($this->doiService);
if ($project) {
$projectIdentifier = $project->identifier ? $project->identifier : null;

$sample = $study->sample;
$sampleIdentifier = $sample->identifier ? $sample->identifier : null;
if ($projectIdentifier == null) {
$projectTicker = Ticker::whereType('project')->first();
$projectIdentifier = $projectTicker->index + 1;
$projectTicker->index = $projectIdentifier;
$projectTicker->save();

if ($sampleIdentifier == null) {
$sampleTicker = Ticker::whereType('sample')->first();
$sampleIdentifier = $sampleTicker->index + 1;
$sample->identifier = $sampleIdentifier;
$sample->save();

$sampleTicker->index = $sampleIdentifier;
$sampleTicker->save();
$project->identifier = $projectIdentifier;
$project->save();
$project->fresh()->generateDOI($this->doiService);
}

$molecules = $sample->molecules;

foreach ($molecules as $molecule) {
$moleculeIdentifier = $molecule->identifier ? $molecule->identifier : null;
if ($moleculeIdentifier == null) {
$moleculeTicker = Ticker::whereType('molecule')->first();
$moleculeIdentifier = $moleculeTicker->index + 1;
$molecule->identifier = $moleculeIdentifier;
$molecule->save();

$moleculeTicker->index = $moleculeIdentifier;
$moleculeTicker->save();
}
}

$datasets = $study->datasets;
foreach ($datasets as $dataset) {
$dsIdentifier = $dataset->identifier ? $dataset->identifier : null;

if ($dsIdentifier == null) {
$dsTicker = Ticker::whereType('dataset')->first();
$dsIdentifier = $dsTicker->index + 1;
$dataset->identifier = $dsIdentifier;
$studies = $project->studies;
}

$dsTicker->index = $dsIdentifier;
$dsTicker->save();
if ($studies) {
foreach ($studies as $study) {
if ($study instanceof Study) {
$studyIdentifier = $study->identifier ? $study->identifier : null;
if ($studyIdentifier == null) {
$studyTicker = Ticker::whereType('study')->first();
$studyIdentifier = $studyTicker->index + 1;
$study->identifier = $studyIdentifier;
$studyTicker->index = $studyIdentifier;
$studyTicker->save();
}
$study->save();
$study->generateDOI($this->doiService);

$sample = $study->sample;
$sampleIdentifier = $sample->identifier ? $sample->identifier : null;

if ($sampleIdentifier == null) {
$sampleTicker = Ticker::whereType('sample')->first();
$sampleIdentifier = $sampleTicker->index + 1;
$sample->identifier = $sampleIdentifier;
$sample->save();

$sampleTicker->index = $sampleIdentifier;
$sampleTicker->save();
}

$molecules = $sample->molecules;

foreach ($molecules as $molecule) {
$moleculeIdentifier = $molecule->identifier ? $molecule->identifier : null;
if ($moleculeIdentifier == null) {
$moleculeTicker = Ticker::whereType('molecule')->first();
$moleculeIdentifier = $moleculeTicker->index + 1;
$molecule->identifier = $moleculeIdentifier;
$molecule->save();

$moleculeTicker->index = $moleculeIdentifier;
$moleculeTicker->save();
}
}

$datasets = $study->datasets;
foreach ($datasets as $dataset) {
$dsIdentifier = $dataset->identifier ? $dataset->identifier : null;

if ($dsIdentifier == null) {
$dsTicker = Ticker::whereType('dataset')->first();
$dsIdentifier = $dsTicker->index + 1;
$dataset->identifier = $dsIdentifier;

$dsTicker->index = $dsIdentifier;
$dsTicker->save();
}

$dataset->save();
$dataset->generateDOI($this->doiService);
}
}

$dataset->save();
$dataset->generateDOI($this->doiService);
}
}
}
Expand Down
Loading

0 comments on commit b633d46

Please sign in to comment.