Skip to content

finally...

finally... #80

Workflow file for this run

name: Node.js CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20] # Specify Node.js 20
# Output whether the build job runs based on the file changes
outputs:
should_run_build: ${{ steps.build_check.outputs.build_ran }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 2 # Fetch the last two commits to ensure `git diff` works
- name: Check if TypeScript files were modified
id: build_check
run: |
# Get modified files that are in the 'src/' folder and end with '.ts'
MODIFIED_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep '^src/.*\.ts$')
# Print the modified files for debugging
echo "Modified files:"
echo "$MODIFIED_FILES"
# Check if the modified_files.txt has any content
if [[ -n "$MODIFIED_FILES" ]]; then
echo "Build should run."
echo "::set-output name=build_ran::true"
else
echo "No TypeScript files were modified."
echo "::set-output name=build_ran::false"
fi
- name: Setup Node.js
if: steps.build_check.outputs.build_ran == 'true'
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
if: steps.build_check.outputs.build_ran == 'true'
run: npm install
- name: Compile TypeScript
if: steps.build_check.outputs.build_ran == 'true'
run: npx tsc
- name: Run tests
if: steps.build_check.outputs.build_ran == 'true'
run: npm test
- name: Upload artifacts
if: steps.build_check.outputs.build_ran == 'true'
uses: actions/upload-artifact@v3
with:
name: dist
path: ./dist
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 2 # Fetch the last two commits to ensure `git diff` works
- name: Get modified files
id: get_changed_files
run: |
# Get modified files that are in the 'scripts/' folder and end with '-func.sql' or '-proc.sql'
MODIFIED_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep '^scripts/.*\(-func\.sql\| -proc\.sql\)$')
# Output the filtered list of modified files
echo "$MODIFIED_FILES" > modified_files.txt
# Check if the modified_files.txt has any content
if [[ -s modified_files.txt ]]; then
echo "::set-output name=modified_files_exist::true"
else
echo "::set-output name=modified_files_exist::false"
fi
# Print the modified files for debugging purposes
echo "Modified files:"
cat modified_files.txt
- name: Download artifacts
if: needs.build.outputs.should_run_build == 'true' && (steps.get_changed_files.outputs.modified_files_exist == 'true')
uses: actions/download-artifact@v3
with:
name: dist
- name: Authenticate to Google Cloud for clingen-swc
if: needs.build.outputs.should_run_build == 'true'
uses: google-github-actions/auth@v1
with:
credentials_json: ${{ secrets.GCP_SA_KEY }}
- name: Setup Google Cloud SDK
if: needs.build.outputs.should_run_build == 'true' && (steps.get_changed_files.outputs.modified_files_exist == 'true')
uses: google-github-actions/setup-gcloud@v1
with:
version: 'latest'
- name: Execute clingen-stage BigQuery Function Scripts
if: steps.get_changed_files.outputs.modified_files_exist == 'true'
run: |
echo "Executing BigQuery function scripts for clingen-stage in alphabetical order..."
for file in $(find ./scripts -type f -name '*-func.sql' | sort); do
relative_file=$(realpath --relative-to=. "$file") # Get relative path of the file
if grep -q "$relative_file" modified_files.txt; then
echo "Executing $file..."
bq query --use_legacy_sql=false --project_id=$PROJECT_ID < "$file"
else
echo "Skipping $file as it was not modified."
fi
done
env:
PROJECT_ID: 'clingen-stage'
- name: Execute clingen-dev BigQuery Function Scripts
if: steps.get_changed_files.outputs.modified_files_exist == 'true'
run: |
echo "Executing BigQuery function scripts for clingen-dev in alphabetical order..."
for file in $(find ./scripts -type f -name '*-func.sql' | sort); do
relative_file=$(realpath --relative-to=. "$file") # Get relative path of the file
if grep -q "$relative_file" modified_files.txt; then
echo "Executing $file..."
bq query --use_legacy_sql=false --project_id=$PROJECT_ID < "$file"
else
echo "Skipping $file as it was not modified."
fi
done
env:
PROJECT_ID: 'clingen-dev'
- name: Execute clingen-dev BigQuery Procedure Scripts
if: steps.get_changed_files.outputs.modified_files_exist == 'true'
run: |
echo "Executing BigQuery procedure scripts for clingen-dev in alphabetical order..."
for file in $(find ./scripts -type f -name '*-proc.sql' | sort); do
relative_file=$(realpath --relative-to=. "$file") # Get relative path of the file
if grep -q "$relative_file" modified_files.txt; then
echo "Executing $file..."
bq query --use_legacy_sql=false --project_id=$PROJECT_ID < "$file"
else
echo "Skipping $file as it was not modified."
fi
done
env:
PROJECT_ID: 'clingen-dev'