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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# example
learning and experimenting
# Github-Examples
A repo containing GitHub for programmatic examples
212 changes: 212 additions & 0 deletions git-crash-course/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
## Git Hidden Folder

There is a hidden folder called `.git` which tells you that our project is a git repo.

If we wanted to create a git repo in a new project we' create the folder and the initalize that repo using `git init`

```
mkdir /workspaces/tmp/new-project
cd /workspaces/tmp/new-project
git init
touch Readme.md
code Readme.md
git status
git add Readme.md
# makes changes to readme.md
git commit -m "add readme file"
```


## Cloning

We can clone three ways: HTTPS, SSH, Github CLI

Since we are using GitHub Codespaecs we'll a create temporary directory in our workspace

```sh
mkdir /workspace/tmp
cd /workspace/tmp
```


### HTTPS

```sh
git clone https://github.com/andrew-wc-brown/Github-Examples.git
cd GitHub-Examples
```

> You'll need to generate a Personal Access Token (PAT)
https://github.com/settings/token

You will use the PAT as your password when you login

- Give it access to Contents for Commits

### SSH

```ssh
git clone git@github.com:andrew-wc-brown/Github-Examples.git
cd GitHub-Examples
```

We will need to create our own SSH rsa key pair

```sh
sshe-keygen -t rsa
```

For WSL users and if you crete a non default key you might need to add it

```sh
eval `ssh-agent`
ssh-add /home/andrew/.ssh/alt-github_id_rsa
```

We can test our connection here:
```
ssh -T git@github.com
```

### Github CLI

Install the CLI

eg. Linux (Ubuntu)

```sh
type -p curl >/dev/null || (sudo apt update && sudo apt install curl -y)
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
&& sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
&& sudo apt update \
&& sudo apt install gh -y
```

```
gh auth login
gh repo clone andrew-wc-brown/Github-Examples
```

## Commits


When we want to commit code we can write git commit which will open up the commit edit message in the editor of choice.

```sh
git commit
```

Set the global editor
```
git config --global core.editor emacs
```

Make a commit and commit message without opening an editor
```sh
git commit -m "add another exclamation"
```

## Branches

List of branches

```
git branch
```

Create a new branch
```
git branch branch-name
```

Checkout the branch

```
git checkout dev
```


## Remotes

We can add remote but often you will just add remote via upsteam when adding a branch

```sh
git remote add ...
git branch -u origin new-feature
```

## Stashing

```
git stash list
git stash
git stash save my-name
git stash apply
git stash pop
```

## Merging

```
git checkout dev
git merge main
```

## Add

When we want to stage changes that will be included in the commit
We can use the . to add all possible files.

```
git add Readme.md
git add .
```

## Reset

Reset allows you to move Staged changes to be unstaged.
This is useful when you to revert all files not to be not commited

```
git add .
git reset
```

> git reset will revet a git add.

## Status

Git status shows you what files will or will not be commited.

```
git status
```

## Gitconfig file

The gitconfig file is what stores your global configurations for git such as email, name, editor and more.

Showing the contnets of our .gitconfig file
```
git config --list
```

When you first install Git on a machine you are suppose to set up your name and email

```sh
git config --global user.name "John Doe"
git config --global user.email johndoe@example.com
```

## Log

git log will show recent git commits to the git tree

## Push

When we want to push a repo to our remote origin

```
git push
```
1 change: 1 addition & 0 deletions git-crash-course/hello
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello!!!!
16 changes: 16 additions & 0 deletions github-actions/Readme.me
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## Manual Trigger

```sh
gh workflow run greet.yml -f name=mona -f greeting=hello -F data=@myfile.txt
echo '{"name":"mona", "greeting":"hello"}' | gh workflow run greet.yml --json
```

## Webhook Event

```sh
curl -X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: token {PAT} \
-d '{"event_type": "webhook", "client_payload": {"key": "value"} }' \
https://api.github.com/repos/{owner}/{repo}/dispatches
```
1 change: 1 addition & 0 deletions github-actions/mydata
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SGVsbG8gTWFycw==
3 changes: 3 additions & 0 deletions github-actions/myscript.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
echo "Hello from the bash script!"
date
29 changes: 29 additions & 0 deletions github-actions/pg/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const { Client } = require('pg');

const pgclient = new Client({
host: process.env.POSTGRES_HOST,
port: process.env.POSTGRES_PORT,
user: 'postgres',
password: 'postgres',
database: 'postgres'
});

pgclient.connect();

const table = 'CREATE TABLE student(id SERIAL PRIMARY KEY, firstName VARCHAR(40) NOT NULL, lastName VARCHAR(40) NOT NULL, age INT, address VARCHAR(80), email VARCHAR(40))'
const text = 'INSERT INTO student(firstname, lastname, age, address, email) VALUES($1, $2, $3, $4, $5) RETURNING *'
const values = ['Mona the', 'Octocat', 9, '88 Colin P Kelly Jr St, San Francisco, CA 94107, United States', 'octocat@github.com']

pgclient.query(table, (err, res) => {
if (err) throw err
});

pgclient.query(text, values, (err, res) => {
if (err) throw err
});

pgclient.query('SELECT * FROM student', (err, res) => {
if (err) throw err
console.log(err, res.rows) // Print the data in student table
pgclient.end()
});
15 changes: 15 additions & 0 deletions github-actions/pg/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "example-project",
"version": "1.0.0",
"description": "A simple Node.js project using PostgreSQL",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Your Name",
"license": "ISC",
"dependencies": {
"pg": "^8.7.1"
}
}
50 changes: 50 additions & 0 deletions github-actions/templates/azure-static-web-apps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Deploy web app to Azure Static Web Apps

env:
APP_LOCATION: "/" # location of your client code
API_LOCATION: "api" # location of your api source code - optional
OUTPUT_LOCATION: "build" # location of client code build output

on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened, closed]
branches:
- main

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

jobs:
build_and_deploy:
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
runs-on: ubuntu-latest
name: Build and Deploy
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Build And Deploy
uses: Azure/static-web-apps-deploy@1a947af9992250f3bc2e68ad0754c0b0c11566c9
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }}
repo_token: ${{ secrets.GITHUB_TOKEN }}
action: "upload"
app_location: ${{ env.APP_LOCATION }}
api_location: ${{ env.API_LOCATION }}
output_location: ${{ env.OUTPUT_LOCATION }}

close_pull_request:
if: github.event_name == 'pull_request' && github.event.action == 'closed'
runs-on: ubuntu-latest
name: Close Pull Request
steps:
- name: Close Pull Request
uses: Azure/static-web-apps-deploy@1a947af9992250f3bc2e68ad0754c0b0c11566c9
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }}
action: "close"
22 changes: 22 additions & 0 deletions github-actions/templates/bash-script.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Run Bash Script

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
run-script:
runs-on: ubuntu-latest

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

- name: Run the script
run: |
chmod u+x ./github-actions/myscript.sh
./github-actions/myscript.sh
14 changes: 14 additions & 0 deletions github-actions/templates/conditional.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: example-workflow
on: [push]
jobs:
hello-world:
if: github.repository == 'octo-org/octo-repo-prod'
runs-on: ubuntu-latest
steps:
- name: "Hello World"
run: echo "Hello World!"
goodbye-moon:
runs-on: ubuntu-latest
steps:
- name: "Goodbye Moon"
run: echo "Goodbye Moon!"
Loading