forked from ontoportal-lirmm/ncbo_cron
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/create-triples-migration-scripts' into biodivpo…
…rtal
- Loading branch information
Showing
21 changed files
with
892 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." |
Oops, something went wrong.