Skip to content

Truongphikt is pulling module lowpass_imputation #48

Truongphikt is pulling module lowpass_imputation

Truongphikt is pulling module lowpass_imputation #48

Workflow file for this run

name: Pull module/submodule
run-name: ${{ github.actor }} is pulling ${{inputs.repo_type }} ${{inputs.repo_name }}
on:
workflow_dispatch:
inputs:
repo_name:
description: 'Module/Submodule name to pull'
required: true
type: string
repo_type:
description: 'Type of repo'
default: 'module'
required: true
type: choice
options:
- module
- subworkflow
workflow_call:
inputs:
repo_name:
description: 'Module/Submodule name to pull'
required: true
type: string
repo_type:
description: 'Type of repo'
required: true
type: string
jobs:
pulling_module:
runs-on: ubuntu-20.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Add SSH key
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan github.com >> ~/.ssh/known_hosts
- name: Feching repo
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"
git fetch
- name: Prepare global variables
run: |
echo "CURRENT_REPO=${{ github.repository }}" >> $GITHUB_ENV
echo "[email protected]:KTest-VN/${{inputs.repo_name}}.git" >> $GITHUB_ENV
echo "REPO_NAME=${{inputs.repo_name }}" >> $GITHUB_ENV
echo "REPO_TYPE=${{inputs.repo_type }}" >> $GITHUB_ENV
- name: Check whether the ${{ env.REPO_TYPE }} was pulled.
run: |
if [ -d "./${{ env.REPO_TYPE }}s/ktest/${{ env.REPO_NAME }}" ]; then
echo "REPO_EXIST=1" >> $GITHUB_ENV
echo "${{ env.REPO_TYPE }} ${{ env.REPO_NAME }} was pulled !!!"
else
echo "REPO_EXIST=0" >> $GITHUB_ENV
echo "${{ env.REPO_TYPE }} ${{ env.REPO_NAME }} hasn't been pulled !!!"
fi
echo "NEED_CLONE=1" >> $GITHUB_ENV
- name: Checking ${{ env.REPO_TYPE }} if exist
if: ${{ env.REPO_EXIST == 1 }}
run: |
REMAIN_COMMIT=`git log -n 1 --pretty=format:"%s" ./${{ env.REPO_TYPE }}s/ktest/${{ env.REPO_NAME }}/main.nf | grep -oP '(?<=@).*' || echo 'null'`
REMOTE_COMMIT=`git ls-remote ${{ env.REPO_LINK }}| head -n1 | awk '{print $1}' | grep -oE '^.{7}'`
echo "REMAIN_COMMIT=$REMAIN_COMMIT"
echo "REMOTE_COMMIT=$REMOTE_COMMIT"
if [[ $REMAIN_COMMIT == $REMOTE_COMMIT ]]; then
echo "NEED_CLONE=0" >> $GITHUB_ENV
else
echo "NEED_CLONE=1" >> $GITHUB_ENV
rm -rf ./${{ env.REPO_TYPE }}s/ktest/${{ env.REPO_NAME }}
fi
- name: Clone the ${{ env.REPO_TYPE }}
if: ${{ env.NEED_CLONE == 1 }}
run: |
git clone ${{ env.REPO_LINK }} ./${{ env.REPO_TYPE }}s/ktest/${{ env.REPO_NAME }}
- name: Get last commit of ${{ env.REPO_TYPE }}
if: ${{ env.NEED_CLONE == 1 }}
run: |
cd ./${{ env.REPO_TYPE }}s/ktest/${{ env.REPO_NAME }}
LATEST_COMMIT=`git log -n 1 origin/main --pretty=format:"%h"`
echo "LATEST_COMMIT=$LATEST_COMMIT" >> $GITHUB_ENV
- name: Clean git of ${{ env.REPO_TYPE }}
if: ${{ env.NEED_CLONE == 1 }}
run: |
rm -rf ./${{ env.REPO_TYPE }}s/ktest/${{ env.REPO_NAME }}/.git/
- name: Commit changes
if: ${{ env.NEED_CLONE == 1 }}
run: |
git reset
git add ./${{ env.REPO_TYPE }}s/ktest/${{ env.REPO_NAME }}
git commit -m "${{ github.actor }} add ${{ env.REPO_TYPE }} ${{ env.REPO_NAME }} from KTest-VN/${{ env.REPO_NAME }}@${{ env.LATEST_COMMIT }}"
- name: Push changes
if: ${{ env.NEED_CLONE == 1 }}
run: git push origin main