By default GitHub actions are enabled on any new repo. You can create and access those in Action tab on your repo page.
- SSH connection to the server should be established before hand
- Runner username should ideally not have root access for safety purposes
-
Go to settings page of the repository.
-
In the left sidebar, click
Actions. -
In the left sidebar, under "Actions", click
Runners. -
Click on
New self-hosted runner -
Select the operating system image and architecture of your self-hosted runner machine.
-
You will see instructions showing you how to download the runner application and install it on your self-hosted runner machine.
- Stop the self-hosted runner application if it is currently running.
- Install the service with the following command:
sudo ./svc.sh install - Start the service with the following command:
sudo ./svc.sh start
This action will build webpack packages and push directly onto the development branch. These packages include:
- react-app
- es6-webpack
- new-react-app
- ckeditor-webpack
-
Go to
Actiontab in repository and add a Node.js workflow -
It will generate a
.github/workflows/node.js.ymlfile -
Modify the file like mentioned below:
# react-build.yml name: React App Build on: pull_request: types: [closed] branches: [development] paths: - public/react-app/** # Changes of these files will trigger the workflow jobs: build: runs-on: self-hosted if: github.event.pull_request.merged == true env: CI: false steps: - uses: actions/checkout@v2 - name: Use Node.js 12.x uses: actions/setup-node@v1 with: node-version: 12.x cache: 'npm' - name: Install dependencies run: npm install working-directory: public/react-app - name: Build run: npm run build:production working-directory: public/react-app - name: Add & Commit uses: EndBug/add-and-commit@v7.5.0 with: # The arguments for the `git add` command (see the paragraph below for more info) # Default: '.' add: 'public/react-app/build' # Determines the way the action fills missing author name and email. Three options are available: # - github_actor -> UserName <UserName@users.noreply.github.com> # - user_info -> Your Display Name <your-actual@email.com> # - github_actions -> github-actions <email associated with the github logo> # Default: github_actor default_author: github_actor # The message for the commit. # Default: 'Commit from GitHub Actions (name of the workflow)' message: 'React Build' # The name of the branch to use, if different from the one that triggered the workflow. # Default: the branch that triggered the run branch: development qa-push: runs-on: self-hosted needs: [build] steps: - name: Invoke deployment uses: wei/curl@master with: args: http://link-to-deployment-server.com -
Above mentioned will build
react-appand commit the build ondevelopmentbranch -
This process can be repeated for all the npm apps in the project with separate workflow files
- Checkout: https://github.com/marketplace/actions/checkout
- Node Setup: https://github.com/marketplace/actions/setup-node-js-environment
- Add & Commit: https://github.com/marketplace/actions/add-commit
- cUrl: https://github.com/marketplace/actions/github-action-for-curl
This action periodically scans for branches that are older that configured number of days and deletes them.
- Add a new file
.github/workflows/delete-stale-branches.ymlin repository - Modify the file like mentioned below:
name: Delete Stale Branches on: # Run daily at midnight on 5th of every month schedule: - cron: "0 0 5 * *" # Allow workflow to be manually run from the GitHub UI workflow_dispatch: jobs: cleanup_old_branches: runs-on: self-hosted name: Clean up repo steps: - name: Delete dead branches uses: phpdocker-io/github-actions-delete-abandoned-branches@v1 id: delete_branches with: github_token: ${{ secrets.GITHUB_TOKEN }} last_commit_age_days: 120 ignore_branches: 'development,production,staging' # Disable dry run and actually get stuff deleted dry_run: no - name: Get output run: "echo 'Deleted branches: ${{ steps.delete_branches.outputs.deleted_branches }}'" - Above mentioned workflow should delete the branches that are older than 120 days at every 5th date of the month at mid-night according to UTC time
- Delete abandoned branches: https://github.com/marketplace/actions/delete-abandoned-branches




