Skip to content

Instantly share code, notes, and snippets.

View jonico's full-sized avatar
🪐
@ home

Johannes Nicolai jonico

🪐
@ home
View GitHub Profile
@jonico
jonico / count-committers-on-ghes.sh
Last active April 16, 2024 19:20
Count all unique committers in the last 90 days on GitHub Enterprise Server
ghe-console -y <<'ENDSCRIPT'
ActiveRecord::Base.connected_to(role: :reading) do
puts "Version 0.2.0"
emails = Set.new
start_time = 90.days.ago.beginning_of_day
Repository.where(active: true).find_each do |repo|
Push
.where(repository: repo)
.where("created_at >= ?", start_time)
.find_each do |push|
@jonico
jonico / Jenkinsfile
Last active January 31, 2024 09:43
Example for a full blown Jenkins pipeline script with CodeQL analysis steps, multiple stages, Kubernetes templates, shared volumes, input steps, injected credentials, heroku deploy, sonarqube and artifactory integration, Docker containers, multiple Git commit statuses, PR merge vs branch build detection, REST API calls to GitHub deployment API, …
#!groovy
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
def label = "mypod-${UUID.randomUUID().toString()}"
podTemplate(label: label, yaml: """
spec:
containers:
- name: mvn
image: maven:3.3.9-jdk-8
@jonico
jonico / Jenkinsfile
Last active January 17, 2024 14:12
Jenkinsfile showing advanced Postman CLI, portman (contract test generation) and newman integration including custom reporters and reporting status back to Postman
def checkout () {
context="continuous-integration/jenkins/"
context += isPRMergeBuild()?"pr-merge/checkout":"branch/checkout"
def scmVars = checkout scm
setBuildStatus ("${context}", 'Checking out completed', 'SUCCESS')
if (isPRMergeBuild()) {
prMergeRef = "refs/pull/${getPRNumber()}/merge"
mergeCommit=sh(returnStdout: true, script: "git show-ref ${prMergeRef} | cut -f 1 -d' '")
echo "Merge commit: ${mergeCommit}"
return [prMergeRef, mergeCommit]
@jonico
jonico / modify-examples.js
Created December 12, 2023 14:39
Duplicate Postman collection responses
var fs = require('fs'), // needed to read JSON file from disk
Collection = require('postman-collection').Collection,
Response = require('postman-collection').Response,
myCollection;
// Load a collection to memory from a JSON file on disk (say, sample-collection.json)
myCollection = new Collection(JSON.parse(fs.readFileSync('sample-collection.json').toString()));
// iterate through all requests in the collection
myCollection.forEachItem(function (item) {
@jonico
jonico / dynamic-runner-selection.yaml
Last active November 2, 2023 04:33
Dynamic selection of GitHub Runners - as GitHub Action matrix builds currently do not allow dynamic values
name: CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
@jonico
jonico / optional-job-based-on-presence-of-a-secret.yaml
Created June 29, 2020 17:05
GitHub Actions optional job based on the presence of a secret
name: Build and publish Docker image + Container Scanning
on: [push]
jobs:
build:
name: Build
runs-on: ubuntu-latest
outputs:
dockerimage: ${{ steps.dockerimage.outputs.dockerimage }}
enablecontainerscanning: ${{ steps.enablecontainerscanning.outputs.enablecontainerscanning }}
@jonico
jonico / README.md
Last active September 14, 2023 15:13
How to create an RDS database that is suitable for PlanetScale's import feature

MySQL on RDS configured for import to PlanetScale example

This folder contains an example Terraform configuration that deploys a MySQL database - using RDS in an Amazon Web Services (AWS) account - that is properly configured for PlanetScale's DB import feature.

It will make sure that the RDS database has the binlog exposed, gtid-mode set to ON and is using ROW-based replication. All these are pre-requisites for imports to work without zero downtime.

If you are going to write a lot of data in your database in a very short amount of time, don't forget the only manual step after the Terraform setup.

@jonico
jonico / postman-issue-ops.yml
Created June 20, 2023 13:44
GitHub Action based IssueOps workflow to create Postman releases and a tag directly from a pull request by issuing a comment starting with /pm-release [<release-name>] ["release notes"]
name: Postman IssueOps commands
on:
issue_comment:
types: [created]
jobs:
prechecks:
name: Permission pre-check
if: github.event.issue.pull_request != null && (startsWith(github.event.comment.body, '/pm-release') || startsWith(github.event.comment.body, '/pm-publish'))
@jonico
jonico / MySQLBYOD.py
Last active July 12, 2023 21:20
Copying from one PlanetScale table to another using AWS Glue (and MySQL 8.0 JDBC driver)
import sys
from awsglue.transforms import *
from awsglue.utils import getResolvedOptions
from pyspark.context import SparkContext, SparkConf
from awsglue.context import GlueContext
from awsglue.job import Job
import time
from pyspark.sql.types import StructType, StructField, IntegerType, StringType
sc = SparkContext()
@jonico
jonico / .env
Last active June 1, 2023 09:04
How to run PlanetScale alongside with an MySQL enabled app that does not have any other internet access
PLANETSCALE_DB=brandnewdb
PLANETSCALE_BRANCH=mybranch
PLANETSCALE_ORG=jonico
PLANETSCALE_SERVICE_TOKEN=pscale_tkn_loCzIH7NktDK-GWJ71eX97Qr5D3a9iEO_pgHCSHUtw
PLANETSCALE_SERVICE_TOKEN_NAME=69xrlIwgs4ms