Skip to content

Instantly share code, notes, and snippets.

View GustavoAmerico's full-sized avatar

Gustavo Américo GustavoAmerico

View GitHub Profile
@GustavoAmerico
GustavoAmerico / automatic-merge-branchs.ps1
Created January 11, 2024 13:05
Esse script é responsável por executar um merge automático de uma branch base para todas as outras branchs. Em caso de conflitos o script faz rollback e pula a branch conflitante
param([Parameter(Mandatory=$true)][String]$branchNamePattern, $remoteName = 'origin', $branchBase='master')
$branchsToUpdate=(git branch --all|%{$_.ToString().Replace("remotes/$remoteName/",'').Trim()} | Select-String -Pattern $branchNamePattern);
$branchsToUpdate |%{git checkout $_; git merge "$remoteName/$branchBase"; if(-not $?){git merge --abort; git reset --hard}else{ git push } }
@GustavoAmerico
GustavoAmerico / kubectl-help.ps1
Last active September 15, 2023 02:44
Gets the list of certificates (cert-manager) that are scheduled to renew in the next X days
function k8s-certificates-renew{
param([Parameter()][int]$days = 15)
((kubectl get certificates -A -o json | ConvertFrom-Json).items) |
?{[Datetime]($_.status.renewalTime) -lt (Get-Date).AddDays($days) }|
%{ [pscustomobject]@{Name=$_.metadata.name; RenewAt=[DateTime]$_.status.renewalTime; Namespace=$_.metadata. Namespace } }
}
function k8s-Select-Resources {
###Essa função é responsável por extrair as informações
@GustavoAmerico
GustavoAmerico / Delete_Remote_Branch_By_NamePattern.ps1
Last active August 3, 2023 20:17
[danger] Esse comando é utilizado para apagar multiplos branchs que utilizam o mesmo padrão de nomenclatura
/*
ATENÇÃO: Esse comando não verifica se as alterações forma mescladas com a branch principal!! O branch vai ser apagado
*/
param([Parameter(Mandatory=$true)][String]$branchNamePattern, $remoteName = 'origin')
git branch --all --merged | Select-String -Pattern $branchNamePattern | %{$_.ToString().Replace("remotes/$remoteName/",'').Trim()} | %{ git push origin :$_ }
@GustavoAmerico
GustavoAmerico / CopyPRTagsToBuild.ps1
Last active October 22, 2022 18:02
Script to copy Azure DevOps pullrequest tags to AzureDevOps Pipeline Build
$tagNameExpression = "target-*"
# Define the PR URI based in azure devops pipeline runtime variables
$prUri = "$(System.CollectionUri)/$(System.TeamProject)/_apis/git/repositories/$(Build.Repository.ID)/pullRequests/$(System.PullRequest.PullRequestId)/labels?api-version=6.0-preview.1";
$buildUri= "$(System.CollectionUri)/$(System.TeamProject)/_apis/build/builds/$(Build.BuildId)/tags";
# Get PullRequest Details
$FoundTags = Invoke-WebRequest `
-Uri $prUri `
-Authentication Bearer `
@GustavoAmerico
GustavoAmerico / scale_up_and_down_alldeployment.ps1
Created February 10, 2022 15:14
Scale all deployment from namespace on single line, this command should be used for scale down dev and hmo env on day off
param(
[Parameter(Mandatory=$true)][System.String] $namespace,
[Parameter(Mandatory=$true)][int]$numberOfReplicas
)
kubectl get deployments -n $namespace --output jsonpath="{range .items[*]}{.metadata.name}{'\n'}{end}" |%{
kubectl scale deployment/$_ -n $namespace --replicas $numberOfReplicas;
}
@GustavoAmerico
GustavoAmerico / AddOrUpdateTableAndColumnDescription
Last active April 22, 2021 17:32
Procedure for add or update SQL Server table and column description
CREATE PROCEDURE dbo.PROC_AddOrUpdateTableAndColumnDescription
@fullName varchar(255),
@description varchar(255)
AS
/*
Table exemple: <schema>.<table name> dbo.MyTable
Column Exemple: <schema>.<table name>.<column name> dbo.MyTable.Id
*/
/*Extrai o primeiro valor antes do ponto, representa o schema*/
@GustavoAmerico
GustavoAmerico / azure-storage-file-as-windows-disk.ps1
Created February 21, 2021 00:25
azure-storage-file-as-windows-disk
# This script help you setting an azure storage account as a network folder or windows disk
# Is need Azure CLI installed
param(
[System.String]
$resourceGroupName = "<resource group>",
[System.String]
$storageAccountName = "<storage account name>",
[System.String]
$subscription = "<subscription name or id>",
@GustavoAmerico
GustavoAmerico / Cleanup-Azure-Container-Registry.ps1
Last active May 13, 2021 17:32
Cleanup-Azure-Container-Registry.ps1
param(
[Parameter(Mandatory=$true)] $acrAccountName,
$takeLastImages = 5,
$likeRepositories = '',
$selectTagPattern = '^([0-9]+(\.)?){3,4}$'
)
#Get all repository where the name like with parameter $likeRepositories
$repositories = az acr repository list --name $acrAccountName --query ("[?contains(@, '" + $likeRepositories + "')]") | ConvertFrom-Json ;
@GustavoAmerico
GustavoAmerico / azure-database-export.ps1
Created September 18, 2019 02:26
Script para executar a exportação do Azure SQL Database para um Azure Storage
#Esse script pode ser utilizado em tarefa do AzureDevOps para executar o backup da base de dados dentro do processo de Build ou Release
param(
$BaseStorageUri = "https://<your-storage>.blob.core.windows.net/backup-database",
$StorageKey = "<Shared key>",
$DatabaseName = @( "db1","db2","db3"),
$ResourceGroupName = "<database-resource-group-name>",
$ServerName = "<database-server-name>",
$serverAdmin = "<database-user-with-permission-login>",
$serverPassword = "<database-user-with-permission-password>"