Skip to content

Commit

Permalink
Merge branch 'feature/create-triples-migration-scripts' into biodivpo…
Browse files Browse the repository at this point in the history
…rtal
  • Loading branch information
syphax-bouazzouni committed Jan 20, 2025
2 parents 99c8566 + 7f6e739 commit 5ce8c55
Show file tree
Hide file tree
Showing 21 changed files with 892 additions and 36 deletions.
93 changes: 93 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Workflow to deploy NCBO Cron to stage/prod systems
#
# Required github secrets:
#
# CONFIG_REPO - github repo containing config and customizations for NCBO_CRON. Format 'author/private_config_repo'
# it is used for getting capistrano deployment configuration for stages on the github actions runner and
# PRIVATE_CONFIG_REPO env var is constructed from it which is used by capistrano on the API hosts for pulling configs.
#
# GH_PAT - github Personal Access Token for accessing private config repo
#
# SSH_JUMPHOST - ssh jump/proxy host though which deployments have to though if API nodes live on private network.
# SSH_JUMPHOST_USER - username to use to connect to the ssh jump/proxy.
#
# DEPLOY_ENC_KEY - key for decrypting deploymnet ssh key residing in config/
# this SSH key is used for accessing jump host, API nodes, and private github repo.

name: Capistrano Deployment
# Controls when the action will run.
on:
push:
branches:
- stage
- development
# Allows running this workflow manually from the Actions tab
workflow_dispatch:
inputs:
BRANCH:
description: "Branch/tag to deploy"
type: choice
options:
- stage
- development
- master
default: stage
required: true
environment:
description: "target environment to deploy to"
type: choice
options:
- staging
- test
- agroportal
default: stage
jobs:
deploy:
runs-on: ubuntu-latest
env:
BUNDLE_WITHOUT: default #install gems required primarely for deployment in order to speed up workflow
PRIVATE_CONFIG_REPO: ${{ format('[email protected]:{0}.git', secrets.CONFIG_REPO) }}
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: set branch/tag and environment to deploy from inputs
run: |
# workflow_dispatch default input doesn't get set on push so we need to set defaults
# via shell parameter expansion
USER_INPUT_BRANCH="${{ inputs.branch || github.head_ref || 'master' }}"
echo "BRANCH=${USER_INPUT_BRANCH}" >> $GITHUB_ENV
USER_INPUT_ENVIRONMENT=${{ inputs.environment }}
echo "TARGET=${USER_INPUT_ENVIRONMENT:-test}" >> $GITHUB_ENV
CONFIG_REPO=${{ secrets.CONFIG_REPO }}
GH_PAT=${{ secrets.GH_PAT }}
echo "PRIVATE_CONFIG_REPO=https://${GH_PAT}@github.com/${CONFIG_REPO}" >> $GITHUB_ENV
echo "SSH_JUMPHOST=${{ secrets.SSH_JUMPHOST }}" >> $GITHUB_ENV
echo "SSH_JUMPHOST_USER=${{ secrets.SSH_JUMPHOST_USER }}" >> $GITHUB_ENV
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7.8 # Not needed with a .ruby-version file
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- name: get-deployment-config
uses: actions/checkout@v3
with:
repository: ${{ secrets.CONFIG_REPO }} # repository containing deployment settings
token: ${{ secrets.GH_PAT }} # `GH_PAT` is a secret that contains your PAT
path: deploy_config
- name: copy-deployment-config
run: cp -r deploy_config/ncbo_cron/${{ inputs.environment }}/* .
# add ssh hostkey so that capistrano doesn't complain
- name: Add jumphost's hostkey to Known Hosts
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_JUMPHOST }}"
ssh-keyscan -H ${{ secrets.SSH_JUMPHOST }} > ~/.ssh/known_hosts
shell: bash
- uses: miloserdow/capistrano-deploy@master
with:
target: ${{ env.TARGET }} # which environment to deploy
deploy_key: ${{ secrets.DEPLOY_ENC_KEY }} # Name of the variable configured in Settings/Secrets of your github project
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ repo*
.DS_Store
tmp

vendor/bundle/*

# Code coverage reports
coverage*

Expand All @@ -29,3 +31,5 @@ logs/

# Ignore jEnv files
.java-version

processed_files/
34 changes: 17 additions & 17 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GIT
remote: https://github.com/ontoportal-lirmm/goo.git
revision: f8ac7b00e8d8b46d1eea04de014175525c1cdd83
revision: 8d108c23a043039e9675b36f8f444d29a87b11fe
branch: development
specs:
goo (0.0.2)
Expand Down Expand Up @@ -29,7 +29,7 @@ GIT

GIT
remote: https://github.com/ontoportal-lirmm/ontologies_linked_data.git
revision: 6fd6960a1f134ec8c8aff07a5897bb0da12bcc8d
revision: 0aa6219c44143b94135e01c78eb94ad99a5e8b32
branch: development
specs:
ontologies_linked_data (0.0.1)
Expand All @@ -49,7 +49,7 @@ GIT

GIT
remote: https://github.com/ontoportal-lirmm/sparql-client.git
revision: 59251e59346c9a69a67c88552ba55a1244eec602
revision: 24bccbd0f4a5150fa6ce2af50d7c378c681027ea
branch: development
specs:
sparql-client (3.2.2)
Expand Down Expand Up @@ -101,8 +101,8 @@ GEM
capistrano (~> 3.1)
sshkit (~> 1.3)
coderay (1.1.3)
concurrent-ruby (1.3.4)
connection_pool (2.4.1)
concurrent-ruby (1.3.5)
connection_pool (2.5.0)
cube-ruby (0.0.3)
dante (0.2.0)
debug_inspector (1.2.0)
Expand Down Expand Up @@ -138,7 +138,7 @@ GEM
google-cloud-errors (~> 1.0)
google-apis-analytics_v3 (0.16.0)
google-apis-core (>= 0.15.0, < 2.a)
google-apis-core (0.15.1)
google-apis-core (0.16.0)
addressable (~> 2.5, >= 2.5.1)
googleauth (~> 1.9)
httpclient (>= 2.8.3, < 3.a)
Expand All @@ -157,7 +157,7 @@ GEM
google-protobuf (>= 3.18, < 5.a)
googleapis-common-protos-types (~> 1.7)
grpc (~> 1.41)
googleapis-common-protos-types (1.16.0)
googleapis-common-protos-types (1.18.0)
google-protobuf (>= 3.18, < 5.a)
googleauth (1.11.2)
faraday (>= 1.0, < 3.a)
Expand All @@ -176,7 +176,7 @@ GEM
httpclient (2.8.3)
i18n (0.9.5)
concurrent-ruby (~> 1.0)
json (2.9.0)
json (2.9.1)
json-canonicalization (0.4.0)
json-ld (3.2.5)
htmlentities (~> 4.3)
Expand All @@ -185,13 +185,13 @@ GEM
multi_json (~> 1.15)
rack (>= 2.2, < 4)
rdf (~> 3.2, >= 3.2.10)
jwt (2.9.3)
jwt (2.10.1)
base64
launchy (2.5.2)
addressable (~> 2.8)
libxml-ruby (5.0.3)
link_header (0.0.8)
logger (1.6.2)
logger (1.6.5)
macaddr (1.7.2)
systemu (~> 2.6.5)
mail (2.6.6)
Expand All @@ -200,7 +200,7 @@ GEM
mime-types (3.6.0)
logger
mime-types-data (~> 3.2015)
mime-types-data (3.2024.1203)
mime-types-data (3.2025.0107)
mini_mime (1.1.5)
minitest (4.7.5)
mlanett-redis-lock (0.2.7)
Expand All @@ -215,7 +215,7 @@ GEM
net-ssh (>= 5.0.0, < 8.0.0)
net-ssh (7.3.0)
netrc (0.11.0)
oj (3.16.7)
oj (3.16.9)
bigdecimal (>= 3.0)
ostruct (>= 0.2)
omni_logger (0.1.4)
Expand All @@ -226,12 +226,12 @@ GEM
parseconfig (1.1.2)
pony (1.13.1)
mail (>= 2.0)
pry (0.15.0)
pry (0.15.2)
coderay (~> 1.1)
method_source (~> 1.0)
public_suffix (5.1.1)
rack (3.1.8)
rack-test (2.1.0)
rack-test (2.2.0)
rack (>= 1.3)
rake (13.2.1)
rdf (3.2.11)
Expand All @@ -251,7 +251,7 @@ GEM
rexml (~> 3.2)
redis (5.3.0)
redis-client (>= 0.22.0)
redis-client (0.23.0)
redis-client (0.23.2)
connection_pool
representable (3.2.0)
declarative (< 0.1.0)
Expand All @@ -265,13 +265,13 @@ GEM
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
retriable (3.1.2)
rexml (3.3.9)
rexml (3.4.0)
rsolr (2.6.0)
builder (>= 2.1.2)
faraday (>= 0.9, < 3, != 2.0.0)
ruby-xxHash (0.4.0.2)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
rubyzip (2.4.1)
rufus-scheduler (2.0.24)
tzinfo (>= 0.3.22)
signet (0.19.0)
Expand Down
42 changes: 42 additions & 0 deletions bin/migrations/4s-to-graph-files
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env ruby

require 'fileutils'

# Usage: ruby migrate_and_extract.rb <source_folder> <target_folder>
# Check if the correct number of arguments are provided
if ARGV.size != 2
puts "Usage: #{$PROGRAM_NAME} <source_folder> <target_folder>"
exit 1
end

source_folder = ARGV[0]
target_folder = ARGV[1]
processed_dir = File.join(target_folder, 'processed_files')

# Create the target directory if it doesn't exist
FileUtils.mkdir_p(processed_dir)

# Find all files in the source folder and process them
Dir.glob(File.join(source_folder, '**', '*')).select { |file| File.file?(file) }.each do |file|
puts "Processing file: #{file}"

# Define the new filename with .n3 extension
filename = File.basename(file)
new_file = File.join(processed_dir, "#{filename}.n3")

# Copy the original file to the target folder with .n3 extension
FileUtils.cp(file, new_file)
puts "Copied to: #{new_file}"

# Extract the first line and remove the "## GRAPH " prefix, then save it to .graph file
graph_file = "#{new_file}.graph"
first_line = File.open(file, &:readline).sub(/^## GRAPH /, '').strip
File.write(graph_file, first_line)
puts "Extracted graph URI to: #{graph_file}"

# Remove the first line from the copied .n3 file
File.write(new_file, File.readlines(new_file).drop(1).join)
puts "Removed the first line from: #{new_file}"
end

puts "Migration and extraction complete."
Loading

0 comments on commit 5ce8c55

Please sign in to comment.