Github action
Github action is a platform used to automate the workflow of creating an application, such as automated testing and deployment (CI/CD)
Rifki ahmad fahrezi
Creating a runner
A runner is simply a task created by a developer (in the form of a script) to be run by github action automatically, to create it you can follow the following step-by-step:
-
Open the repository where you want to install Github action
-
Click
settings
then click theactions
dropdown on the left menu then clickRunners
-
Click the
New self-hosted runner
button -
Select the runner image (adjust to the server), we choose Linux.
-
Then follow the commands below one by one on our server
If there is a question to name the runner and others, just click enter
so that the default name is used
- If the last command
./run.sh
has been successfully executed, return to the repo then clicksettings
thenRunners
andactions
then your server will appear in the list displayed
If on our server we click ctrl + c
then the run.sh
command will be stopped and we can check the runner again by refreshing the page, so we can see our server status becomes offline
- Run the command below, then check the status with the command below install
then you can see the status of our runner that has not been activated, to activate it with the following command
If you want to stop it, you can use the command sudo ./svh.sh stop
(only if necessary), if the start command has been run, the status on our server should return to idle
- then click the
actions
menu above, you can search for a script runner template according to the technology in the application you are using. If you are using Next.js you can clickset up workflow yourself
, then paste this script you can adjust it according to the runtime used (nodejs or bun and so on), then click thecommit changes
button. This script runs theinstall
command with Bun and also runspm2
for the deploy which is triggered when we push to the repository.
If you click the actions
menu again, you can see the runner script that we created will be automatically run (ignore if there is still an error because we have not set the repo in the action-runner folder).
Note: If you need to set environment variables, you can set it in the settings
→ Secret and variables
→ Actions
section
- Point the server to the
_work
folder, by running this command
then try running ls -1
whether the repository we added to the github action already exists, if it does then run cd nama_repo/nama_repo
, if it does try running ls -1
again if there is a package.json
file or one related to your repo, then you are in the right folder and the previous action script should have run properly. and you can run pm2 startup
so that PM2 can run when the server or system reboots.
And that's how to setup github action on VPS server on Next.js application, if you haven't added domain to our server IP you can follow this method to install domain and SSL. Then try to make changes to our project then push to its repository, then see if the CI/CD process will run.