Continuous Integration - Developers submit their code usually on a daily basis to the main codebase and those changes are automatically tested

Dans votre projet favoris il faut rajouter un dossier .github , creer un dossier workflows a l’interieur

Et dans le dossier workflow on va creer un fichier .yml

Dans cet exemple on veux tester le code qui a été soumis dans chaque pull request

main.yml
name: Node continuous integration
// on which event to run
on: 
	pull_request:
// wichi branch
		branches: [master]
// every workflow should have one or more jobs
jobs:
// give the job a name
	test_pull_request:
// which VM to run on 
		runs-on: ubuntu-latest
// set of steps or instructions
		steps:
			- uses: actions/checkout@v2
			- uses: actions/setup-node@v1 
				with: 
					node-version: 12
// runs npm i and installs all dependencies we need
			-	run : npm ci
			- run : npm test
			- run : npm run build
		
// exemple 
name: LotteryApp 

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [16.x]

    steps:
    - uses: actions/checkout@v3
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v3
      with:
        node-version: ${{ matrix.node-version }}
        cache: 'npm'
        cache-dependency-path: ethereum/package-lock.json
    - name: Setup
      run: npm ci
      working-directory: ethereum
    - name: Install Truffle
      run: npm install truffle -g
      working-directory: ethereum
    - name: Test
      run: truffle test
      working-directory: ethereum
    - name: Deploy
      if: github.event_name != 'pull_request'
      env:
        GH_TOKEN: ${{ secrets.GH_TOKEN }}
      run: npm run deploy --if-present

Pour le faire fonctionner il suffit de commit le tout dans la master branch

ensuite pour le tester on va vouloir creer un pull request

git checkout -b test

Depuis github on aura une info indiquant qu’un pull request est en attente

en cliquant dessus on pourra voir le status de notre github action qui execute le test

Untitled

Depuis le repo github dans l’onglet ACTIONS on va pouvoir suivre nos workflow. Quand un workflow est triggered Github vas suivre les instructions dans le fichier .yml et loguer le status de chaque étapes

Untitled