Skip to content

Commit

Permalink
Add Support for CI/CD Workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
eq19 committed Jul 14, 2020
1 parent 3460a15 commit 2a4981a
Show file tree
Hide file tree
Showing 20 changed files with 818 additions and 242 deletions.
3 changes: 2 additions & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ about: Create a report to help us improve
<!-- If applicable, add screenshots to help explain your problem. -->

**System information**
Operating system:
Operating system:
Browser:
5 changes: 0 additions & 5 deletions .github/ISSUE_TEMPLATE/config.yml

This file was deleted.

35 changes: 19 additions & 16 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
I want to merge this change because...

### Summary
<!-- Please mention all relevant issue numbers. -->
Main Code:
```
```

# Impact
### Pull Request Checklist

* [ ] New migrations
* [ ] New/Updated API fields or mutations
* [ ] Deprecated API fields or mutations
* [ ] Removed API types, fields, or mutations
* [ ] Documentation needs to be updated
<!-- Please keep this section. It will make maintainer's life easier. -->

# Pull Request Checklist
1. [ ] Privileged views and APIs are guarded by proper permission checks.
1. [ ] All visible strings are translated with proper context.
1. [ ] All data-formatting is locale-aware (dates, numbers, and so on).
1. [ ] Database queries are optimized and the number of queries is constant.
1. [ ] Database migration files are up to date.
1. [ ] The changes are tested.
1. [ ] The code is documented (docstrings, project documentation).
1. [ ] GraphQL schema and type definitions are up to date.
1. [ ] Changes are mentioned in the changelog.

<!-- Please keep this section. It will make the maintainer's life easier. -->
### Screenshots

* [ ] Privileged queries and mutations are guarded by proper permission checks
* [ ] Database queries are optimized and the number of queries is constant
* [ ] Database migration files are up to date
* [ ] The changes are tested
* [ ] GraphQL schema and type definitions are up to date
* [ ] Changes are mentioned in the changelog
<!-- If your changes affect the UI, providing "before" and "after" screenshots will
greatly reduce the amount of work needed to review your work. -->
60 changes: 0 additions & 60 deletions .github/stale.yml

This file was deleted.

1 change: 1 addition & 0 deletions .github/workflows/__init__
1 change: 1 addition & 0 deletions .github/workflows/builders/__init__
56 changes: 56 additions & 0 deletions .github/workflows/builders/ubuntu/artifact.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash

echo -e "WHOAMI\n$hr"
whoami
echo $HOME
id

if [[ -x "$(command -v gcloud)" ]]
then
echo -e "$hr\nPROJECT CONFIG\n$hr"
gcloud config list --all

echo -e "\n$hr\nSYSTEM INFO\n$hr"
gcloud info
python --version
fi

echo -e "\n$hr\nHOME PROFILES\n$hr"
ls -al $HOME

echo -e "$hr\nROOT PROFILES\n$hr"
[[ "$(whoami)" == "root" ]] && ls -alL /root || sudo bash -c 'ls -alL /root'

echo -e "$hr\nSSH FILES\n$hr"
echo $(whoami) /root/.ssh
[[ "$(whoami)" == "root" ]] && ls -alL /root/.ssh || sudo bash -c 'ls -alL /root/.ssh'

echo -e "$hr\nBIN FILES\n$hr"
echo $HOME/.local/bin
ls -al $HOME/.local/bin

echo -e "\n$hr\nFILE SYSTEM\n$hr"
df -h

echo -e "\n$hr\nALL REPOSITORY\n$hr"
pwd
ls -al /

echo -e "\n$hr\nCURRENT REPOSITORY\n$hr"
pwd
ls -al .

if [[ ! -x "$(command -v docker)" ]]
then
echo -e "\n$hr\nDOCKER VERSION\n$hr"
docker version

echo -e "\n$hr\nDOCKER INFO\n$hr"
docker info

echo -e "$hr\nIMAGE BUILDERS\n$hr"
docker images --all | sort

echo -e "\n$hr\nCURRENTLY RUNNING\n$hr"
docker ps
fi
23 changes: 23 additions & 0 deletions .github/workflows/init.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Init CI
on:
push:
branches:
- '*'
- '!master'
- '!deploy'
- '!compose'
- '!production'
- '!development'
- '!Chetabahana'
jobs:
job1:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Initializing Repositories
run: |
bash .github/workflows/builders/__init__
env:
GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }}
GCP_ACCOUNT: ${{ secrets.GCP_ACCOUNT }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
!.flowconfig
!.github
!.gitignore
!.google
!.gqlconfig
!.npmrc
!.nvmrc
Expand Down
39 changes: 39 additions & 0 deletions .google/cloud/__init__
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

# Unmark the 2 line below to see all commands available
#echo -e "\n$hr\nPATH COMMANDS\n$hr"
#compgen -c | xargs which -a | sort && dpkg -l

# Collumn numbers
COL=130
case $HOME in
/root) COL=140;;
/builder/home) COL=180;;
esac

printf -v res %${COL}s
export hr=`printf '%s\n' "${res// /-}"`
export hrd=`printf '%s\n' "${res// /=}"`

# Set Environtment
export WORKSPACE=$(realpath .)
export PATH=$HOME/.local/bin:$PATH

if [[ -n "${GITHUB_REPOSITORY+set}" ]]
then
[[ -z $TAG_NAME ]] && export TAG_NAME=ubuntu
[[ -z $REPO_NAME ]] && export REPO_NAME=${GITHUB_REPOSITORY##*/}
[[ -z $REPO_OWNER ]] && export REPO_OWNER=${GITHUB_REPOSITORY%/*}
[[ -z $BRANCH_REF_HEADS ]] && export BRANCH_REF_HEADS=${GITHUB_REF##*/}
[[ -z $BRANCH_NAME ]] && export BRANCH_NAME=$(basename $(git name-rev --name-only HEAD))
[[ -z $PROJECT_ID ]] && export PROJECT_ID=$(echo "$REPO_OWNER" | tr '[:upper:]' '[:lower:]')
fi

# Set the path to output volume
( [[ -n "${TAG_REPO+set}" ]] && [[ "$REPO_NAME" == "github_"* ]] ) && export REPO_NAME=$TAG_REPO
[[ -n "${RUNNER_WORKSPACE+set}" ]] && export OUTPUTS_VOLUME=$RUNNER_WORKSPACE/outputs/volume
[[ -n "${BUILDER_OUTPUT+set}" ]] && export OUTPUTS_VOLUME=/builder/outputs/volume
[[ -z "${OUTPUTS_VOLUME}" ]] && export OUTPUTS_VOLUME=$RWORKSPACE/outputs
[[ -z "${DEBIAN_FRONTEND}" ]] && export DEBIAN_FRONTEND=noninteractive
[[ -n "${INVOCATION_ID+set}" ]] && export BUILD_ID=${INVOCATION_ID}
[[ ! -d $OUTPUTS_VOLUME ]] && mkdir -p $OUTPUTS_VOLUME
124 changes: 124 additions & 0 deletions .google/cloud/builders/__init__
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#!/bin/bash

# Parameters
while [[ "$1" != "" ]]; do
eval export "$1" &> /dev/null
shift
done

# Environtment
get_workspace()
{
echo Set Environtments..
export NAMESPACE=$(realpath ${0%/*})

# Namespace Environtments
INHERIT=$(dirname ${NAMESPACE})/__init__
if [[ -f $INHERIT ]]; then source $INHERIT; fi

# Workspace Environtments
if [[ -f $WORKSPACE/env_vars_to_export ]]
then
while read -r LINE; do
#Fetch variable names
EXPORT=$(sed -e 's/[[:space:]]*$//' <<<${LINE})
VAR=`echo $EXPORT | cut -d '=' -f1`;

#Verify each variables
ENV_VAR=$(echo $VAR)
if [[ -n ${ENV_VAR+set} ]]; then continue;
else eval export "$EXPORT" &> /dev/null; fi
done <$WORKSPACE/env_vars_to_export
fi

# Injected Environtments
if ( [[ -z $DATA ]] && [[ -n ${JSON_DATA+set} ]] && [[ -x "$(command -v cf_export)" ]] ); \
then echo $JSON_DATA > data.json && cf_export DATA=$(realpath data.json); fi
}

# Get private repository
get_repository()
{
# Set the workflows
echo Initializing Workflows..

# Set Google App Credentials
if [[ -x "$(command -v gcloud)" ]]
then
if [[ -z $(gcloud config get-value account 2> /dev/null) ]]
then
# Dependencies: GCP_ACCOUNT & GCP_SA_KEY
if [[ -z $GOOGLE_APPLICATION_CREDENTIALS ]]
then
echo $GCP_SA_KEY > .google-app-creds.json
export GOOGLE_APPLICATION_CREDENTIALS=$(realpath .google-app-creds.json)
fi

# Activate account
gcloud config set project $PROJECT_ID &> /dev/null
gcloud auth activate-service-account $GCP_ACCOUNT --project=$PROJECT_ID \
--key-file=$GOOGLE_APPLICATION_CREDENTIALS &> /dev/null

[[ -x "$(command -v cf_export)" ]] && cf_export $GCP_ACCOUNT=$GCP_ACCOUNT \
GOOGLE_APPLICATION_CREDENTIALS=$GOOGLE_APPLICATION_CREDENTIALS
fi
fi

if [[ ! -d $WORKSPACE/.io ]]
then
if [[ -x "$(command -v gcloud)" ]]
then
# Dependencies: Set the repository in to Google Repository
# Name the target repo to be on top of the list and Set IAM role to clone it
export REPOSITORY=$(gcloud source repos list --limit=1 --format 'value(REPO_NAME)')
gcloud source repos clone --verbosity=none $REPOSITORY $WORKSPACE/.io &> /dev/null
[[ -x "$(command -v cf_export)" ]] && cf_export REPOSITORY=$REPOSITORY
fi
fi

# Send to environtment
[[ -d $WORKSPACE/.io ]] && cd $WORKSPACE/.io || exit 0;
[[ -z $REPOSITORY ]] && export REPOSITORY=$(git remote get-url origin)
export MATCH_REPOSITORY=${REPOSITORY##*_} RUNNER=$HOME/.local/bin/run

# Locate the branch
if [[ "$BRANCH_NAME" != "master" ]]
then
if grep -q origin/$BRANCH_NAME << EOF
`git branch -r`
EOF
then
git checkout $BRANCH_NAME
fi
fi

# Locate the files
if [[ ! -f $RUNNER ]]
then
for i in $(ls -d */)
do
mkdir -p $HOME/.local/$(basename ${i%%/})
cp -frpT ${i%%/} $HOME/.local/$(basename ${i%%/})
done
fi
}

# Run the current step
while [[ -z $ORIGIN ]]
do
# Loop for environtments
[[ $ENV == true ]] && printenv | sort
if [[ -z $WORKSPACE ]]; then get_workspace;
elif [[ -z $MATCH_REPOSITORY ]]; then get_repository;
elif [[ $(command -v run) == $RUNNER ]]; then run $TAG_NAME;
elif [[ $(command -v push) == $PUSHER ]]; then push $TAG_NAME;
else echo "uncathed profiles and settings.."; fi

# Avoid unwanted iteration
[[ -z $num ]] && num=0 || (( num += 1 ))
if [[ $num > 1 ]]
then
[[ ! -d $HOME/.ssh ]] && echo "step was failed, halted to continue.."
exit 0;
fi
done
Loading

0 comments on commit 2a4981a

Please sign in to comment.