Skip to content
Merged
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
26 changes: 26 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
feature:
- head-branch: ["^feature/", "^feat/"]

enhancement:
- head-branch: ["^enhancement/", "^enh/"]

bugfix:
- head-branch: ["^bugfix/", "^fix/"]

chore:
- changed-files:
- any-glob-to-any-file: [".github/**", "**/Dockerfile", "**/docker-compose*.yml"]
- head-branch: ["^chore/", "^deps/"]

docs:
- changed-files:
- any-glob-to-any-file: ["**/*.md"]

refactor:
- head-branch: ["^refactor/"]

security:
- head-branch: ["^security/"]

tests:
- head-branch: ["^test/", "^tests/"]
10 changes: 10 additions & 0 deletions .github/labels.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{ "name": "feature", "color": "1f883d", "description": "New feature" },
{ "name": "enhancement", "color": "a2eeef", "description": "Enhancement to existing feature" },
{ "name": "bugfix", "color": "d73a4a", "description": "Bug fix" },
{ "name": "chore", "color": "8f5bff", "description": "Maintenance/devex" },
{ "name": "docs", "color": "0e8a16", "description": "Documentation" },
{ "name": "refactor", "color": "fbca04", "description": "Refactor" },
{ "name": "security", "color": "b60205", "description": "Security fix/hardening" },
{ "name": "tests", "color": "5319e7", "description": "Test changes" }
]
19 changes: 19 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: CI

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Build Docker image
uses: docker/build-push-action@v6
with:
context: .
push: false
56 changes: 56 additions & 0 deletions .github/workflows/label-policy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
name: Label Policy
on:
push:
branches: [main]
pull_request:
types: [opened, synchronize, reopened, labeled, unlabeled]
workflow_dispatch:

permissions:
contents: read
issues: write
pull-requests: write

jobs:
label-sync:
name: Label Sync
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: EndBug/label-sync@v2
with:
config-file: .github/labels.json
delete-other-labels: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

auto-label:
name: Auto Label
if: github.event_name == 'pull_request'
needs: [label-sync]
runs-on: ubuntu-latest
steps:
- uses: actions/labeler@v5
with:
configuration-path: .github/labeler.yml
repo-token: ${{ secrets.GITHUB_TOKEN }}

require-label:
name: Require Label
if: github.event_name == 'pull_request'
needs: [auto-label]
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v7
with:
script: |
const required = ['feature','enhancement','bugfix','chore','docs','refactor','security','tests'];
const labels = await github.paginate(
github.rest.issues.listLabelsOnIssue,
{ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.payload.pull_request.number }
);
const present = labels.map(l => l.name);
const ok = required.some(l => present.includes(l));
if (!ok) core.setFailed(`PR must include at least one of: ${required.join(', ')}`);

36 changes: 36 additions & 0 deletions .github/workflows/pr-title.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
name: PR Title Check
on:
pull_request:
types: [opened, synchronize, reopened, edited]

permissions:
pull-requests: read

jobs:
pr-title:
name: PR Title Check
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
types: |
feature
feat
enhancement
enh
bugfix
fix
chore
docs
doc
refactor
security
sec
tests
test
subjectPattern: "^[A-Z0-9].+"
subjectPatternError: "Start the subject with a capital letter."

121 changes: 121 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
name: Release

on:
push:
tags:
- "v*"

jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write

steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}

- name: Log in to ghcr.io
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract version from tag
id: version
run: echo "version=${GITHUB_REF_NAME#v}" >> $GITHUB_OUTPUT

- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: |
ghcr.io/kleffio/alertmanager-alerting:${{ steps.version.outputs.version }}
ghcr.io/kleffio/alertmanager-alerting:latest

- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
generate_release_notes: true

- name: Generate app token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.KLEFF_APP_ID }}
private-key: ${{ secrets.KLEFF_APP_PRIVATE_KEY }}
owner: kleffio
repositories: plugin-registry

- name: Open PR to plugin-registry
uses: actions/github-script@v7
with:
github-token: ${{ steps.app-token.outputs.token }}
script: |
const version = "${{ steps.version.outputs.version }}";
const branch = `update/alertmanager-alerting-${version}`;

const { data: file } = await github.rest.repos.getContent({
owner: "kleffio",
repo: "plugin-registry",
path: "plugins.json",
});

const plugins = JSON.parse(Buffer.from(file.content, "base64").toString());
const idx = plugins.findIndex(p => p.id === "alertmanager-alerting");
if (idx !== -1) plugins[idx].version = version;

const { data: ref } = await github.rest.git.getRef({
owner: "kleffio",
repo: "plugin-registry",
ref: "heads/main",
});

try {
await github.rest.git.createRef({
owner: "kleffio",
repo: "plugin-registry",
ref: `refs/heads/${branch}`,
sha: ref.object.sha,
});
} catch (e) {
if (e.status === 422) {
await github.rest.git.updateRef({
owner: "kleffio",
repo: "plugin-registry",
ref: `heads/${branch}`,
sha: ref.object.sha,
force: true,
});
} else throw e;
}

await github.rest.repos.createOrUpdateFileContents({
owner: "kleffio",
repo: "plugin-registry",
path: "plugins.json",
message: `chore: bump alertmanager-alerting to v${version}`,
content: Buffer.from(JSON.stringify(plugins, null, 2) + "\n").toString("base64"),
branch,
sha: file.sha,
});

const { data: pr } = await github.rest.pulls.create({
owner: "kleffio",
repo: "plugin-registry",
title: `chore: bump alertmanager-alerting to v${version}`,
head: branch,
base: "main",
body: `Automated release PR from \`kleffio/alertmanager-alerting\` tag \`v${version}\`.`,
});

await github.rest.pulls.merge({
owner: "kleffio",
repo: "plugin-registry",
pull_number: pr.number,
merge_method: "squash",
});
Loading