ci(docker-build,artifact-publish): publishes the image and artifact a… #136
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Continuous Integration | |
on: | |
workflow_dispatch: {} | |
push: | |
branches: ["main"] | |
pull_request: | |
types: [opened, synchronize, reopened] | |
branches: ["main"] | |
jobs: | |
build: | |
runs-on: ${{ matrix.os }} | |
permissions: | |
actions: read | |
contents: read | |
security-events: write | |
strategy: | |
fail-fast: false | |
matrix: | |
python-version: ["3.12"] | |
os: ["ubuntu-latest", "windows-latest", "macos-latest"] | |
language: ["python"] | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up PDM | |
uses: pdm-project/setup-pdm@v4 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Prepare Environment, Sync Dependences and Run Tox | |
run: | | |
mkdir -p ~/.config/bb | |
cp config.ini ~/.config/bb | |
pdm fix | |
pdm sync | |
pdm run tox | |
- name: SonarCloud Scan | |
if: ${{ matrix.os == 'ubuntu-latest' }} | |
uses: sonarsource/sonarcloud-github-action@master | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
with: | |
args: | | |
-Dsonar.projectKey=psadi_bbcli | |
-Dsonar.organization=psadi | |
-Dsonar.python.version=3 | |
-Dsonar.sources=bb | |
-Dsonar.tests=tests | |
-Dsonar.python.coverage.reportPaths=coverage.xml | |
-Dsonar.exclusions=tests | |
- name: Initialize CodeQL | |
if: ${{ matrix.os == 'ubuntu-latest' }} | |
uses: github/codeql-action/init@v3 | |
with: | |
languages: ${{ matrix.language }} | |
- name: Autobuild | |
if: ${{ matrix.os == 'ubuntu-latest' }} | |
uses: github/codeql-action/autobuild@v3 | |
- name: Perform CodeQL Analysis | |
if: ${{ matrix.os == 'ubuntu-latest' }} | |
uses: github/codeql-action/analyze@v3 | |
with: | |
category: "/language:${{matrix.language}}" | |
paths-ignore: | | |
__pypackages__ | |
__pycache__ | |
.tox | |
.pdm-build | |
.ruff_cache | |
build | |
dist | |
.vscode | |
.github | |
- uses: actions/upload-artifact@v3 | |
with: | |
name: workspace | |
path: . | |
upload_binaries_to_release: | |
name: "Upload binaries to current release" | |
runs-on: ubuntu-latest | |
if: ${{ github.event_name == 'release' }} | |
needs: "build" | |
steps: | |
- uses: actions/download-artifact@v3 | |
with: | |
name: workspace | |
- name: Upload binaries to release | |
uses: svenstaro/upload-release-action@v2 | |
with: | |
repo_token: ${{ secrets.GITHUB_TOKEN }} | |
file: dist/bb-* | |
tag: ${{ github.ref }} | |
overwrite: true | |
file_glob: true | |
push_to_registry: | |
name: Push Docker image to Docker Hub | |
runs-on: ubuntu-latest | |
needs: "build" | |
steps: | |
- uses: actions/download-artifact@v3 | |
with: | |
name: workspace | |
- name: Log in to Docker Hub | |
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 | |
with: | |
images: psadi/bbcli | |
- name: Build and push Docker image | |
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 | |
with: | |
context: . | |
file: ./Dockerfile | |
# push: ${{ github.event_name == 'release' }} | |
push: false | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} |