Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implements httprequest lego k8s operator (do not merge) #27

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
name: Bug report
about: Create a bug report to help us improve
title: ""
labels: ["bug"]
assignees: ''
---

#### Describe the bug
<!-- A clear and concise description of what the bug is. -->

#### To Reproduce
<!-- Steps that can be taken to reproduce the behaviour -->

1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

#### Expected behavior
<!-- A clear and concise description of what you expected to happen. -->

#### Screenshots
<!-- If applicable, add screenshots to help explain your problem. -->

#### Logs
<!-- If applicable, add logs to help explain your problem. -->

#### Environment

- Charm / library version (if relevant): <!-- e.g. 1.2 -->
- Juju version (output from `juju --version`):
- Cloud Environment: <!-- e.g. GKE -->
- Kubernetes version (output from `kubectl version --short`):

#### Additional context

<!-- Add any other context about the problem here. -->
13 changes: 13 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Description

Please include a summary of the change. Please also include relevant motivation and context. List any dependencies that are required for this change.

# Checklist:

- [ ] My code follows the [style guidelines](/CONTRIBUTING.md) of this project
- [ ] I have performed a self-review of my own code
- [ ] I have made corresponding changes to the documentation
- [ ] I have added tests that validate the behaviour of the software
- [ ] I validated that new and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream modules
- [ ] I have bumped the version of the library
74 changes: 74 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ "main" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "main" ]
schedule:
- cron: '25 13 * * 0'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'python' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality


# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
31 changes: 31 additions & 0 deletions .github/workflows/issues.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Issues to JIRA

on:
issues:
types: [opened, reopened, closed]

jobs:
update:
name: Update Issue
runs-on: ubuntu-latest
steps:
- name: Create JIRA ticket
env:
ISSUE_TITLE: ${{ github.event.issue.title }}
ISSUE_DESCRIPTION: ${{ github.event.issue.body }}
run: |
if ${{ contains(github.event.*.labels.*.name, 'Bug') }}; then
type=bug
else
type=story
fi
data=$( jq -n \
--arg title "$ISSUE_TITLE" \
--arg url '${{ github.event.issue.html_url }}' \
--arg submitter '${{ github.event.issue.user.login }}' \
--arg body "" \
--arg type "$type" \
--arg action '${{ github.event.action }}' \
'{title: $title, url: $url, submitter: $submitter, body: $body, type: $type, action: $action}' )

curl -X POST -H 'Content-type: application/json' --data "${data}" "${{ secrets.JIRA_URL }}"
20 changes: 20 additions & 0 deletions .github/workflows/lint-pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: "Lint PR"

on:
pull_request_target:
types:
- opened
- edited
- synchronize

permissions:
pull-requests: read

jobs:
main:
name: Validate PR title
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
107 changes: 107 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: CI

on:
push:
branches: ["main"]
pull_request:
# The branches below must be a subset of the branches above
branches: ["main"]

jobs:
lint-report:
name: Lint report
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Install tox
run: pip install tox
- name: Run tests using tox
run: tox -e lint

static-analysis:
name: Static analysis
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Install tox
run: pip install tox
- name: Run tests using tox
run: tox -e static

unit-tests-with-coverage:
name: Unit tests
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Install tox
run: pip install tox
- name: Run tests using tox
run: tox -e unit

integration-test:
name: Integration tests
runs-on: ubuntu-22.04

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add some requirements for this workflow. Integration tests hog CI resources during peak hours so best to run this when the other reqs are met

  needs:
      - lint-report
      - static-analysis
      - unit-tests-with-coverage

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR #29 addresses this

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup LXD
uses: canonical/setup-lxd@main
with:
channel: 5.17/stable
- name: Setup operator environment
uses: charmed-kubernetes/actions-operator@main
with:
provider: microk8s
channel: 1.28-strict/stable
juju-channel: 3.3/stable
- name: Run integration tests
run: tox -e integration
- name: Archive Tested Charm
uses: actions/upload-artifact@v4
if: ${{ github.event_name == 'push' }}
with:
name: tested-charm
path: .tox/**/httprequest-lego-k8s_ubuntu-22.04-amd64.charm
retention-days: 5
- name: Archive charmcraft logs
if: failure()
uses: actions/upload-artifact@v4
with:
name: charmcraft-logs
path: /home/runner/.local/state/charmcraft/log/*.log
- name: Archive juju crashdump
if: failure()
uses: actions/upload-artifact@v4
with:
name: juju-crashdump
path: juju-crashdump-*.tar.xz

publish-charm:
name: Publish Charm
needs:
- lint-report
- static-analysis
- unit-tests-with-coverage
- integration-test
runs-on: ubuntu-22.04
if: ${{ github.event_name == 'push' }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install charmcraft
run: sudo snap install charmcraft --classic
- name: Fetch Tested Charm
uses: actions/download-artifact@v4
with:
name: tested-charm
- name: Move charm in current directory
run: find ./ -name httprequest-lego-k8s_ubuntu-22.04-amd64.charm -exec mv -t ./ {} \;
- name: Select Charmhub channel
uses: canonical/charming-actions/channel@2.4.0
id: channel
- name: Upload charm to Charmhub
uses: canonical/charming-actions/upload-charm@2.4.0
with:
credentials: "${{ secrets.CHARMHUB_TOKEN }}"
github-token: "${{ secrets.GITHUB_TOKEN }}"
channel: "${{ steps.channel.outputs.name }}"
43 changes: 43 additions & 0 deletions .github/workflows/promote.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Promote Charm

on:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this workflow file. I've actually never seen it before.

Question: is anyone authorised to run this workflow? Might be good to set this to management / senior eng

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everyone in the team yes as the whole team is admin on this github project, but this is configurable through github permission.

workflow_dispatch:
inputs:
promotion:
type: choice
description: Channel to promote from
options:
- edge -> beta
- beta -> candidate
- candidate -> stable

jobs:
promote:
name: Promote Charm
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set target channel
env:
PROMOTE_FROM: ${{ github.event.inputs.promotion }}
run: |
if [ "${PROMOTE_FROM}" == "edge -> beta" ]; then
echo "promote-from=edge" >> ${GITHUB_ENV}
echo "promote-to=beta" >> ${GITHUB_ENV}
elif [ "${PROMOTE_FROM}" == "beta -> candidate" ]; then
echo "promote-from=beta" >> ${GITHUB_ENV}
echo "promote-to=candidate" >> ${GITHUB_ENV}
elif [ "${PROMOTE_FROM}" == "candidate -> stable" ]; then
echo "promote-from=candidate" >> ${GITHUB_ENV}
echo "promote-to=stable" >> ${GITHUB_ENV}
fi
- name: Promote Charm
uses: canonical/charming-actions/release-charm@2.4.0
with:
base-channel: 22.04
credentials: ${{ secrets.CHARMHUB_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
destination-channel: latest/${{ env.promote-to }}
origin-channel: latest/${{ env.promote-from }}
charmcraft-channel: latest/stable
54 changes: 54 additions & 0 deletions .github/workflows/update-libs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Auto-update Charm Libraries
on:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this too

workflow_dispatch:
schedule:
- cron: "0 0,12 * * *"

permissions:
contents: write
pull-requests: write

jobs:
update-lib:
name: Check libraries
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up SSH Key for Signing Commits
run: |
mkdir -p ~/.ssh
echo "${{ secrets.BOT_PRIVATE_SIGNING_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
echo "${{ secrets.BOT_PUBLIC_SIGNING_KEY }}" > ~/.ssh/id_rsa.pub
chmod 644 ~/.ssh/id_rsa.pub
git config --global user.email "telco-engineers@lists.canonical.com"
git config --global user.name "telcobot"
git config --global user.signingkey ~/.ssh/id_rsa.pub
git config --global commit.gpgsign true
git config --global gpg.format ssh

- name: Fetch charm libraries
run: |
sudo snap install charmcraft --classic --channel latest/stable
charmcraft fetch-lib
env:
CHARMCRAFT_AUTH: "${{ secrets.CHARMCRAFT_AUTH }}"

- name: Create a PR for local changes
uses: peter-evans/create-pull-request@v5.0.2
with:
token: ${{ secrets.TELCO_GITHUB_BOT_TOKEN }}
commit-message: "chore: update charm libraries"
committer: "Telcobot <telco-engineers@lists.canonical.com>"
author: "Telcobot <telco-engineers@lists.canonical.com>"
title: "chore: Update charm libraries"
body: |
Automated action to fetch latest version of charm libraries. The branch of this PR
will be wiped during the next check. Unless you really know what you're doing, you
most likely don't want to push any commits to this branch.
branch: "chore/auto-libs"
delete-branch: true
Loading