Ceci est une ancienne révision du document !
Github actions
Ajout d'une clé SSH
Pour pouvoir pousser sur un dépôt automatiquement.
- Création de la clé
Il faut commencer par créer la clé d'authentification (sans mot de passe, au format RSA PRIVATE KEY
).
- Ajout de la clé au dépôt à modifier
Puis ouvrir le fichier file.key.pub
et créer une clé de déploiement à l'adresse https://github.com/USER/PROJET/settings/keys
Bien sûr, cocher Allow write access
.
- Ajout de la clé au dépôt voulant pousser vers le dépôt à modifier
Ajouter le contenu du fichier key converti au format -----BEGIN RSA PRIVATE KEY-----
(voir Création d'une clé) à l'adresse https://github.com/USER/PROJET/settings/secrets/actions
- Configurer le projet pour utiliser la clé
- name: Install SSH key uses: shimataro/ssh-key-action@v2 with: key: ${{ secrets.SSH_KEY_TRAVIS_CI }} known_hosts: # write here the content of `ssh-keyscan localhost` when executed on the CI machine of course. - name: Publish results run: | eval `ssh-agent` # ~/.ssh/id_rsa is when shimataro/ssh-key-action@v2 installed the key. ssh-add ~/.ssh/id_rsa git clone depot_a_modifier cd xxx # insert modification git add git commit -m "text" # Here you should success git push
Sous Windows, ssh-keyscan localhost
ne fonctionne pas. On peut directement mettre le résultat de ssh-keyscan -t rsa github.com
.
/proc/cpuinfo
2 processeurs :
processor : 1 et 2 vendor_id : GenuineIntel cpu family : 6 model : 79 model name : Intel(R) Xeon(R) CPU E5-2673 v4 @ 2.30GHz stepping : 1 microcode : 0xffffffff cpu MHz : 2294.686 cache size : 51200 KB physical id : 0 siblings : 2 core id : 0 cpu cores : 2 apicid : 0 initial apicid : 0 fpu : yes fpu_exception : yes cpuid level : 20 wp : yes flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology cpuid pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single pti fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm rdseed adx smap xsaveopt md_clear bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs taa itlb_multihit bogomips : 4589.37 clflush size : 64 cache_alignment : 64 address sizes : 46 bits physical, 48 bits virtual power management:
Exemples
- cmake
En plus de cmake, il y a une procédure pour initialiser et commiter vers un dépôt externe.
Sous Linux :
- .github/workflows/build-linux.yml
--- name: Linux build on: workflow_run: workflows: ['format'] types: - completed jobs: build: runs-on: ubuntu-22.04 strategy: matrix: include: - name: ubuntu-gcc ar: /usr/bin/ar cc: /usr/bin/gcc-12 cxx: /usr/bin/g++-12 ranlib: /usr/bin/ranlib - name: ubuntu-clang ar: /usr/bin/llvm-ar-14 cc: /usr/bin/clang-14 cxx: /usr/bin/clang++-14 ranlib: /usr/bin/llvm-ranlib-14 steps: - name: Stop if format failed if: ${{ github.event.workflow_run.conclusion != 'success' }} run: | echo ${{ github.event.workflow_run.conclusion }} exit 1 - uses: bansan85/action-workflow_run-status@main env: MATRIX_CONTEXT: ${{ toJSON(matrix) }} - uses: actions/checkout@v3 with: submodules: recursive ref: ${{ github.event.workflow_run.head_commit.id }} - name: Install SSH key if: ${{ github.event.workflow_run.head_branch == 'master' }} uses: shimataro/ssh-key-action@v2 with: key: ${{ secrets.GITHUBCI_PRIVATE_KEY }} known_hosts: localhost ssh-rsa ${{ secrets.GITHUBCI_KNOW_HOSTS }} - name: Install gcc if: contains(matrix.cc, 'gcc') run: sudo apt-get install -yq g++-12 gcc-12 - name: Install clang if: contains(matrix.cc, 'clang') run: sudo apt-get install -yq clang-14 llvm-14 - name: Install 3rdparty run: xargs -a config/apt-get.txt sudo apt-get install -yq - name: cmake run: | ls /usr/bin mkdir build cmake -S . -B build -DCMAKE_C_COMPILER="${{ matrix.cc }}" -DCMAKE_CXX_COMPILER="${{ matrix.cxx }}" -DCMAKE_AR="${{ matrix.ar }}" -DCMAKE_RANLIB="${{ matrix.ranlib }}" -DCMAKE_CXX_FLAGS="-DSPDLOG_FMT_EXTERNAL -DFMT_HEADER_ONLY" cmake --build build/ --target all --config Release - name: ctest shell: bash run: | cd build || exit 1 ctest -O test-result.xml --output-on-failure --verbose cd .. || exit 1 - name: Publish test if: ${{ github.event.workflow_run.head_branch == 'master' }} env: COMMIT_MESSAGE: ${{ github.event.workflow_run.head_commit.message }} run: | eval `ssh-agent` git clone --depth 1 ssh://git@github.com/bansan85/jessica-ci.git -b ${{ matrix.name }} rm -Rf jessica-ci/* cp build/test-result.xml jessica-ci apt list --installed > jessica-ci/apt-installed.txt ssh-add ~/.ssh/id_rsa gpg --version gpg --quiet --batch --yes --decrypt --passphrase="${{ secrets.ENCRYPT_PASSWORD }}" --output .github/encrypted/github-ci-private.key .github/encrypted/github-ci-private.key.gpg gpg --import .github/encrypted/github-ci-private.key cd jessica-ci || exit 1 git config --global user.name "Github CI" git config --global user.email "github-ci@le-garrec.fr" git add . if [ -n "$(git diff-index --name-only HEAD --)" ]; \ then \ git commit -S${{ secrets.GPG_KEY_ID }} -m "${COMMIT_MESSAGE//\"/\"\"}" -m "Update from bansan85/jessica@$GITHUB_SHA"; \ git push || { echo "Failure git push" && exit 1; } \ fi cd .. || exit 1
Sous Windows, inclus vcpkg :
- .github/workflows/build-windows.yml
--- name: Windows build on: workflow_run: workflows: ['format'] types: - completed jobs: build: runs-on: windows-latest strategy: matrix: include: - name: windows-msbuild cc: cl cxx: cl env: VCPKG_DEFAULT_TRIPLET: 'x64-windows' VCPKG_INSTALLED_DIR: '${{ github.workspace }}/vcpkg/installed' steps: - name: Stop if format failed if: ${{ github.event.workflow_run.conclusion != 'success' }} run: | echo ${{ github.event.workflow_run.conclusion }} exit 1 - uses: bansan85/action-workflow_run-status@main env: MATRIX_CONTEXT: ${{ toJSON(matrix) }} - uses: actions/checkout@v3 with: submodules: recursive ref: ${{ github.event.workflow_run.head_commit.id }} - name: Install SSH key if: ${{ github.event.workflow_run.head_branch == 'master' }} uses: shimataro/ssh-key-action@v2 with: key: ${{ secrets.GITHUBCI_PRIVATE_KEY }} known_hosts: github.com ssh-rsa ${{ secrets.GITHUBCI_KNOW_HOSTS_WINDOWS }} - name: Install Windows Vcpkg uses: lukka/run-vcpkg@v10 with: vcpkgJsonGlob: '**/config/windows/vcpkg.json' runVcpkgInstall: true - name: CMake run: | mkdir "${{ github.workspace }}/build" cmake -S "${{ github.workspace }}" -B "${{ github.workspace }}/build" -G "Visual Studio 17 2022" -A x64 -DCMAKE_TOOLCHAIN_FILE="${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake" cmake --build "${{ github.workspace }}/build" --target ALL_BUILD --config Debug - name: ctest shell: bash run: | cd build || exit 1 ctest -C Debug -O test-result.xml --output-on-failure --verbose cd .. || exit 1 - name: Publish test shell: bash if: ${{ github.event.workflow_run.head_branch == 'master' }} env: COMMIT_MESSAGE: ${{ github.event.workflow_run.head_commit.message }} run: | eval `ssh-agent` git clone --depth 1 ssh://git@github.com/bansan85/jessica-ci.git -b ${{ matrix.name }} rm -Rf jessica-ci/* cp build/test-result.xml jessica-ci ssh-add ~/.ssh/id_rsa gpg --version gpg --quiet --batch --yes --decrypt --passphrase="${{ secrets.ENCRYPT_PASSWORD }}" --output .github/encrypted/github-ci-private.key .github/encrypted/github-ci-private.key.gpg gpg --import .github/encrypted/github-ci-private.key cd jessica-ci || exit 1 git config --global user.name "Github CI" git config --global user.email "github-ci@le-garrec.fr" git add . if [ -n "$(git diff-index --name-only HEAD --)" ]; \ then \ git commit -S${{ secrets.GPG_KEY_ID }} -m "${COMMIT_MESSAGE//\"/\"\"}" -m "Update from bansan85/jessica@$GITHUB_SHA"; \ git push || { echo "Failure git push" && exit 1; } \ fi cd .. || exit 1
Extensions
codecov
Envoyer les données à codecov :
git clone --depth 1 https://github.com/henry2cox/lcov.git -b diffcov_initial ./lcov/bin/lcov --capture --directory build --gcov-tool /usr/bin/gcov-10 --rc lcov_branch_coverage=1 --output-file build/coverage.info ./lcov/bin/lcov --remove build/coverage.info "/usr/include/*" --rc lcov_branch_coverage=1 -o build/coverage2.info bash <(curl -s https://codecov.io/bash) -f build/coverage2.info
Le badge par défaut : https://codecov.io/gh/bansan85/jessica/branch/master/graph/badge.svg
- Flags
Les flags peuvent se définir de deux façons différentes. Soit les flags pour la validation des build Github, soit les flags pour le badge.
Pour la validation des build Github, un simple fichier de configuration est possible. Il va s'occuper de séparer les pourcentages de couverture en fonction des chemins des fichiers.
- .codecov.yml
--- coverage: status: project: backend: target: auto paths: - src/backend - include/jessica
Cela va bien ajouter une ligne. Exemple ci-dessous avec demo
et index
.
Par contre, les flags ne fonctionnent pas avec les badges. Pour les faire fonctionner, il faut pousser une couverture de code spécifique au flag dédié avec l'option -F
.
git clone --depth 1 https://github.com/henry2cox/lcov.git -b diffcov_initial ./lcov/bin/lcov --capture --directory build --gcov-tool /usr/bin/gcov-10 --rc lcov_branch_coverage=1 --output-file build/coverage.info ./lcov/bin/lcov --remove build/coverage.info "/usr/include/*" --rc lcov_branch_coverage=1 -o build/coverage2.info bash <(curl -s https://codecov.io/bash) -f build/coverage2.info ./lcov/bin/lcov --extract build/coverage.info "*/include/jessica/*" "*/src/backend/*" --rc lcov_branch_coverage=1 -o build/coverage_backend.info bash <(curl -s https://codecov.io/bash) -f build/coverage_backend.info -F backend
Là, le badge https://codecov.io/gh/bansan85/jessica/branch/master/graph/badge.svg?flag=backend
fonctionne.