Skip to content

CI

CI #72

Workflow file for this run

name: CI
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for branch 1 and on start directory, command.txt file changes or by manually running the workflow from actions tab
on:
push:
branches: [ 1 ]
paths:
- 'command.txt'
workflow_dispatch:
inputs:
cmdval:
description: 'Command'
required: true
argval:
description: 'Arguments'
required: false
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- uses: actions/setup-node@v3
with:
node-version: '19'
# Partial clone
- name: Partial clone
shell: bash
run: |
REPO="https://${GITHUB_ACTOR}:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git"
git config --global user.email [email protected]
git config --global user.name github-actions
git clone --filter=blob:none --no-checkout --depth 1 --sparse $REPO .
git sparse-checkout reapply --no-cone
git sparse-checkout add start/*
git checkout
- name: Setting the command values from command.txt
if: ${{ github.event_name != 'workflow_dispatch' }}
shell: bash
run: |
echo "mycmd=$(sed -n '1 p' command.txt)" >> $GITHUB_ENV
echo "myargs=$(sed -n '2 p' command.txt)" >> $GITHUB_ENV
- name: Setting the command values using the manually entered values
if: ${{ github.event_name == 'workflow_dispatch' }}
shell: bash
run: |
echo "mycmd=${{ github.event.inputs.cmdval }}" >> $GITHUB_ENV
echo "myargs=${{ github.event.inputs.argval }}" >> $GITHUB_ENV
- name: Print command with args for debug
shell: bash
run: |
echo ${{ env.mycmd }} ${{ env.myargs }}
- name: Add folders to sparse-checkout only if the command is search or create
if: ${{ contains(env.mycmd, 'create') || contains(env.mycmd, 'search') }}
shell: bash
run: git sparse-checkout add database/linebyline/*
# Add folders to sparse-checkout
- name: Add folders to sparse-checkout only if the command is update or delete
if: ${{ contains(env.mycmd, 'update') || contains(env.mycmd, 'delete') }}
shell: bash
# delargs gets the arguments in command.txt, then remove start spaces if any, then adds space at end, then replace spaces with *, then remove if only single * exists
# updateargs lists all files in startDir, replaced .txt with * and then replace \n with space
# sparse checkout will have editionName*, which means all files and folders starting with editionName will be checkeout
run: |
delargs=`echo ${{ env.myargs }} | sed -E 's/^\s+//g' | sed -E 's/$/ /g' | sed -E 's/\s+/* /g' | sed -E 's/^\* $//'`
updateargs=`ls -1 start | sed -e 's/\.txt$/*/' | tr '\n' ' '`
git sparse-checkout add database/linebyline/* $delargs $updateargs
- name: Install Dependencies
run: |
npm install
- name: Running the command
run: |
node infofixer.js && node apiscript.js ${{ env.mycmd }} ${{ env.myargs }}
# Emptying command.txt as the command from command.txt was already run in previous step
- name: Emptying command.txt
run: |
> command.txt
- name: Saving the log.txt as artifcat
uses: actions/upload-artifact@v2
with:
name: log
path: log.txt
# commiting and pushing changes
- name: commit and push
shell: bash
run: |
git pull
git add --sparse -A
git commit -m ${{ env.mycmd }}
git push