Raised This Month: $32 Target: $400
 8% 

[suggestion] Git as workflow template


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
aleeexxx
Member
Join Date: May 2014
Location: Valhalla
Old 04-20-2020 , 21:04   [suggestion] Git as workflow template
Reply With Quote #1

Hello guys,

before to start: this is an idea and shouldn't be taken as absolute workflow! use at your own risk

for me programming in sourcepawn is really slow, at least the way I was coding was a headache

1. code
2. compile
3. upload files via ftp
4. start server or refresh plugins
5. test and if error try again

...pff

Why not encourage the use of GIT? and maybe discuss one or more types of structures for git projects:

I propose 2 types(yea are basics):

type 1 "big plugin"

Code:
addons
  sourcemod
    gamedata...
    plugins...
      include...
cfg
  ...
type 2 "simple plugin"

Code:
include...
...
This can help with:

1. automate installations
2. CLI terminal creation
- sm compile => compile current git project
- sm debug => compile && upload files to local test server
- sm deploy => compile && upload files to remote test server
- sm release => compile && upload files to remote producion server
3. all the benefits of GIT, Github or whatever want to use for manage a project
- for example: in github we have workflows, this can be used to verify if a plugin compiled correctly when a user wants to contribute
4. Improvement coding practices
5. Fast code, fast test, fast results...


So I will tell you about my progress:

My current work stack:

- Windows10(v2004) & Ubuntu using WSL-2
- Linux GSM
- VsCode with Remote WSL for code

I code this tools that I write for type 2(basic plugin):

Script for primitive CLI(sm_tools.sh)

use in git project with type 2(basic plugin):

- sm compile
- sm debug
- sm deploy
- sm release

PHP Code:
#!/bin/bash

# here replace your new path
deploy_command="/home/alejandro/gameservers/l4d2/deploy.sh"

function str_replace() {
  
# $1 search
  # $2 replace
  # $3 string
  # example:
  # str_replace "include/" "" "include/file.sp"
  # return: file.sp
  
echo "${3/$1/$2}"
}

# Compila todos
function compile_edited_files() {
  if 
git rev-parse --git-dir > /dev/null 2>&1then
    
    directory
=$(git rev-parse --show-toplevel)
    
# Cambiando a directorio principal
    
cd $directory
    
# Archivos modificados
    
files_edited=$(git status -cut -c 4- | grep -".sp$|.inc$")
    
compiler="$(pwd)/spcomp64"
    
compile_path="$(pwd)/compiled"
    
    
files_compiled=()
    
    function 
compile_file() {
      
local filename=$1
      
if [[ ! "${files_compiled[@]}=~ "${filename}]]; then
        printf 
"\nCompiling: $filename\n\n"
        
path="$(pwd)/$filename"
        
$compiler $path -D $compile_path -v 2 -i
        files_compiled
+=($filename)
        
printf "\n"
      
fi
    
}
    
    for 
file_edited in $files_edited; do
      if [[ 
$file_edited =~ ^include ]];
      
then
        include_file
=$(str_replace "include/" "" $file_edited)
        
include_file=$(str_replace ".inc" "" $include_file)
        
scripts=$(ls grep -".sp$")
        for 
script in $scripts; do
          
contains=$(cat $script grep "^#include <$include_file>")
          if [ -
"$contains]; then
            compile_file $script
          fi
        done
      
else
        
compile_file $file_edited
      fi
    done
  
else
    echo 
"The current directory is not a folder with git"
  
fi
}

function 
debug() {
  if 
git rev-parse --git-dir > /dev/null 2>&1then
    
echo "Updating compiled files to the server"
    
cd $(git rev-parse --show-toplevel)
    
local compile_path="$(pwd)/compiled"
    
cd $compile_path
    cp 
-* /home/alejandro/gameservers/l4d2/serverfiles/left4dead2/addons/sourcemod/plugins
  
else
    echo 
"The current directory is not a folder with git"
  
fi
}

function 
release() {
  
# here replace your path
  
$deploy_command  "user_production"
}

function 
deploy() {
  
# here replace your path
  
$deploy_command  "user_test"
}
work_type=$1

if [[ "${work_type}=~ "compile" ]]; then
  compile_edited_files
elif 
[[ "${work_type}=~ "debug" ]]; then
  debug
elif 
[[ "${work_type}=~ "deploy" ]]; then
  deploy
elif 
[[ "${work_type}=~ "release" ]]; then
  release
fi 
Script for PUSH from Local to Remote(deploy.sh)

Install lftp:
PHP Code:
sudo apt-get install lftp 
Require:
- user($1)


Use: ./deploy "remote-username"

PHP Code:
#!/bin/bash
PORT=21
HOST
="yourhost.com"
USER=$1

addons_path_source
="$HOME/gameservers/l4d2/serverfiles/left4dead2/addons"
addons_path_target="/home/$USER/serverfiles/left4dead2/addons"

cfg_path_source="$HOME/gameservers/l4d2/serverfiles/left4dead2/cfg"
cfg_path_target="/home/$USER/serverfiles/left4dead2/cfg"

function lftp_sync() {
  
lftp -u $USER "sftp://$HOST:$PORT-"
    lcd 
$addons_path_source
    mirror --reverse --delete --verbose 
$addons_path_source $addons_path_target
    lcd 
$cfg_path_source
    mirror --reverse --delete --verbose 
$cfg_path_source $cfg_path_target
    bye
  "
}

lftp_sync
ssh $USER
@$HOST -p $PORT './l4d2server restart'

echo "Correct $USER has been synchronized" 

for use this files you need to download and save in any folder you want, remember if you want to test them you will need to update the files by the corresponding paths...

I recommend you add these files to bash aliases, whit sm_tools.sh it's enough:

PHP Code:
alias sm=/home/alejandro/gameservers/l4d2/sm_tools.sh 





Current problems(very evidents):

1. Non-dynamic paths
2. Still requiring includes from sourcemod in git project, I exclude this files in .gitignore

Solutions:

1. Make a config file in the user profile(like: /home/user/.smconf => file conf)
2. Save sourcemod inside a folder in the user profile(like: /home/user/.smfiles => folder)





could it be this post the start of a primitive idea?

ps1. I know there are some tools like spedit, but what I want more is a CLI terminal.

ps2. If I don't make all the project, it's because I don't have much time, but maybe this encourage to people with time to make this.

thanks!
Attached Files
File Type: zip sm_tools.zip (1.6 KB, 74 views)
__________________

Last edited by aleeexxx; 04-21-2020 at 01:22.
aleeexxx is offline
Send a message via MSN to aleeexxx
aleeexxx
Member
Join Date: May 2014
Location: Valhalla
Old 04-20-2020 , 21:06   Re: Why not encourage the use of GIT?
Reply With Quote #2

Another idea I have is why not have all the approved plugins in an official community account?

so if a developer leave the work of a plugin, another one can continue
__________________
aleeexxx is offline
Send a message via MSN to aleeexxx
RumbleFrog
Great Tester of Whatever
Join Date: Dec 2016
Location: Fish Tank
Old 04-20-2020 , 23:32   Re: Why not encourage the use of GIT?
Reply With Quote #3

Quote:
Originally Posted by aleeexxx View Post
Another idea I have is why not have all the approved plugins in an official community account?

so if a developer leave the work of a plugin, another one can continue
Nothing is preventing you from forking the repository and continue to work on it. Aggregating everything into a single account sounds like an access-control nightmare.

For the other points mentioned above, I don't think encouraging a structure would help develop an ecosystem any faster, if anything, it would slow it down.
__________________

Last edited by RumbleFrog; 04-20-2020 at 23:37.
RumbleFrog is offline
aleeexxx
Member
Join Date: May 2014
Location: Valhalla
Old 04-21-2020 , 00:10   Re: Why not encourage the use of GIT?
Reply With Quote #4

Quote:
Originally Posted by RumbleFrog View Post
Nothing is preventing you from forking the repository and continue to work on it. Aggregating everything into a single account sounds like an access-control nightmare.

For the other points mentioned above, I don't think encouraging a structure would help develop an ecosystem any faster, if anything, it would slow it down.
what about the plugins that are not using git?,

the idea is to have a official version and sometimes coders want to contribute and they upload(attach the file) here, and then the people don't will know what version use or download

git is for have organized projects, and organizing can be slow or fast depending the tool you use

don't worry about pull requests, the original author should still have access to his repository and manage it as he likes.

anyway that idea is to think deeply
__________________

Last edited by aleeexxx; 04-21-2020 at 00:17.
aleeexxx is offline
Send a message via MSN to aleeexxx
aleeexxx
Member
Join Date: May 2014
Location: Valhalla
Old 04-21-2020 , 01:11   Re: Why not encourage the use of GIT?
Reply With Quote #5

After DarkDevil told me his point of view, I concluded that maybe I should handle this as a workflow style!

instead of encourage , I suggest a optional new workflow
__________________
aleeexxx is offline
Send a message via MSN to aleeexxx
aleeexxx
Member
Join Date: May 2014
Location: Valhalla
Old 05-17-2020 , 23:42   Re: [suggestion] Git as workflow template
Reply With Quote #6

Ok I worked for weeks with this idea and it's working fine. Here the link for those who want to check it: https://github.com/draenorg/sm-client-terminal
__________________
aleeexxx is offline
Send a message via MSN to aleeexxx
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 08:09.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode