Skip to content

Merge pull request #34 from vnsamsonov/main #89

Merge pull request #34 from vnsamsonov/main

Merge pull request #34 from vnsamsonov/main #89

Workflow file for this run

name: CI
on:
push:
branches:
- '**'
tags:
- 'v*.*.*'
pull_request:
branches:
- '**'
jobs:
lint:
name: Linter
permissions:
contents: read
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.10.7
- name: Setup dependencies
run: pip install -r requirements.txt
- name: Run linter
run: pylint ./kubedeployer ./tests
unit-tests:
name: Run unit tests
permissions:
contents: read
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Build docker image
run: docker build -t deployer-unit-tests --target tests .
- name: Run unit tests
run: docker run --rm -v $PWD:/srv -i deployer-unit-tests pytest /srv/tests/unit/
integration-tests:
name: Run integration tests
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Run integration tests
run: |
chmod +x scripts/run_tests.sh
./scripts/run_tests.sh --rm
create-release:
name: Create release
runs-on: ubuntu-latest
if: github.ref_type == 'tag'
needs: [ lint, unit-tests, integration-tests ]
steps:
- name: Build changelog
id: build_changelog
uses: mikepenz/release-changelog-builder-action@v3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
configurationJson: |
{
"template": "#{{CHANGELOG}}\n\n<details>\n<summary>Uncategorized</summary>\n\n#{{UNCATEGORIZED}}\n</details>",
"categories": [
{
"title": "## 🚀 Features",
"labels": ["feature"]
},
{
"title": "## 🐛 Fixes",
"labels": ["fix"]
},
{
"title": "## 🔧 Refactoring",
"labels": ["refactor"]
},
{
"title": "## 🧪 Tests",
"labels": ["test"]
},
{
"title": "## 💬 Other",
"labels": ["other"]
}
]
}
- name: Create release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
body: ${{ steps.build_changelog.outputs.changelog }}
publish-to-test-pypi:
name: publish to test pypi
permissions:
contents: read
needs: [ create-release ]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- run: python3 -m pip install --upgrade build && python3 -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
e2e-tests:
name: run e2e tests
needs: [ publish-to-test-pypi ]
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: itlabsio/kubedeployer
- id: get_version
uses: battila7/get-version-action@v2
- name: build
env:
LIB_VERSION: ${{ steps.get_version.outputs.version-without-v }}
run: |
chmod +x scripts/run_e2e_tests.sh
./scripts/run_e2e_tests.sh -v ${LIB_VERSION}
publish-to-pypi:
name: publish to pypi
permissions:
contents: read
needs: [ lint, unit-tests, integration-tests, e2e-tests ]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- run: python3 -m pip install --upgrade build && python3 -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
push-to-registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
if: github.ref_type == 'tag'
needs: [ lint, unit-tests, integration-tests, publish-to-pypi, e2e-tests ]
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Log in to Docker Hub
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: itlabsio/kubedeployer
- id: get_version
uses: battila7/get-version-action@v2
- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
target: release
build-args: |
LIB_VERSION=${{ steps.get_version.outputs.version-without-v }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
trigger-pipeline-by-main:
name: Trigger Gitlab pipeline by main
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
needs: [lint, unit-tests, integration-tests]
steps:
- name: Run pipeline
env:
URL: ${{ secrets.GITLAB_URL }}
TOKEN: ${{ secrets.GITLAB_TOKEN }}
run: |
curl -v --request POST --fail --header "PRIVATE-TOKEN: ${TOKEN}" --header "Content-Type: application/json" --data '{"ref": "master", "variables": [{"key": "FROM_GITHUB", "value": "YES"}]}' ${URL}
trigger-pipeline-by-tag:
name: Trigger Gitlab pipeline by tag
runs-on: ubuntu-latest
if: github.ref_type == 'tag'
needs: [ lint, unit-tests, integration-tests ]
steps:
- id: get_version
uses: battila7/get-version-action@v2
- name: Run pipeline
env:
URL: ${{ secrets.GITLAB_URL }}
TOKEN: ${{ secrets.GITLAB_TOKEN }}
LIB_VERSION: ${{ steps.get_version.outputs.version-without-v }}
run: |
curl -v --request POST --fail --header "PRIVATE-TOKEN: ${TOKEN}" --header "Content-Type: application/json" --data '{"ref": "master", "variables": [{"key": "LIB_VERSION", "value": "'$LIB_VERSION'"}]}' ${URL}