Skip to content

Instantly share code, notes, and snippets.

View philip-gai's full-sized avatar

Philip Gai philip-gai

View GitHub Profile
@philip-gai
philip-gai / encrypt-secret.sh
Created December 8, 2022 06:17
Encrypt a secret using a GitHub user's public SSH Key (WIP)
#!/bin/bash
# The first argument is the username
username=$1
if [ -z "$username" ]; then
echo "Please provide a username"
exit 1
fi
@philip-gai
philip-gai / add-issues-to-project-v2.sh
Created August 19, 2022 19:28
Add open issues of a repository to a ProjectV2 organization project using gh cli
#!/bin/bash
# This script will add the first 500 open issues of a repository to a ProjectV2 organization project.
set -e
# Only needed the first time
gh auth refresh --scopes project,repo
repository_name='<org>/<repo>'
project_org='<org>'
@philip-gai
philip-gai / cancel-in-progress.yml
Last active June 24, 2022 17:39
Actions: Cancel workflow when new commits are pushed
name: CI with in-progress cancellations
on:
pull_request:
branches: [ main ]
workflow_dispatch:
# This is what will cancel the workflow
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
@philip-gai
philip-gai / rerun-workflow-test.yml
Created March 30, 2022 19:21
GitHub Actions: Automatically rerun failed jobs
name: Rerun workflow test
on:
workflow_dispatch:
inputs:
maxAttempts:
required: true
type: number
default: 3
rerunFailedOnly:
@philip-gai
philip-gai / pipeline.yml
Created March 28, 2022 21:23
Azure DevOps Pipeline Dependencies Example
name: Pipeline
stages:
- stage: set_output_variables_stage
displayName: Set output variables
pool: ubuntu-latest
jobs:
- job: set_output_variables_job
displayName: Set output variables
steps:
@philip-gai
philip-gai / send_reminders.yml
Last active March 30, 2022 20:03
GitHub Actions: Update repository issues using the gh cli
# Sends a reminder to assignees of all open issues in a repo using pwsh
# Uses the built-in GITHUB_TOKEN: https://docs.github.com/en/actions/security-guides/automatic-token-authentication
# Replace the GITHUB_TOKEN environment variable with your own PAT to make the issue comment as yourself
# See example runs: https://github.com/philip-gai/philip-gai/actions/workflows/send_reminders.yml
name: Send Reminders
on:
workflow_dispatch: {}
@philip-gai
philip-gai / update_githubtoken.sh
Created February 7, 2022 22:14
Update GITHUB_TOKEN in Codespace to work for multiple repositories
# You have to unset the GITHUB_TOKEN, otherwise gh cli will use it and skip auth
unset GITHUB_TOKEN
# List of scopes: https://docs.github.com/en/developers/apps/building-oauth-apps/scopes-for-oauth-apps#available-scopes
gh auth login --hostname 'github.com' --scopes 'read:org,repo,read:packages'
token="$(gh config get -h github.com oauth_token)"
export GITHUB_TOKEN="$token"
@philip-gai
philip-gai / github-drawio-demo.md
Last active February 27, 2024 20:26
How to integrate diagrams.net (draw.io) with your GitHub repo

Embedding Diagrams in GitHub Markdown

This explains and demos how to use diagrams.net (draw.io) diagrams in your GitHub repo.

  • See repo for more details

Benefits of using diagrams.net in GitHub repositories

  1. Diagrams are stored in your repository with your code and docs
  2. Diagram access is controlled by GitHub repository access
@philip-gai
philip-gai / gh-set-secret.yml
Last active January 14, 2024 18:11
GitHub Actions: Set a repo environment secret using the gh cli in 1-2 steps
# Prerequisites:
# - Create a secret with your PAT token. Permissions needed: repo (all) and read:org
# - Create the HELLO_WORLD secret in your environment with some dummy initial value
#
# Notes:
# - You can tell that it works because it masks the secret_body in the echo secret step after it creates the secret 😄
# - If you don't want to have to pass --repo to gh secret set, then put the actions/checkout@v2 step before the gh secret set step
name: gh-set-secret