Skip to content

Commit

Permalink
Initial commit (#1)
Browse files Browse the repository at this point in the history
* Testing

* It worked, changing branch to main

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
ep-93 and github-actions[bot] authored Sep 10, 2024
1 parent 2dbb54f commit efa7a9d
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 0 deletions.
49 changes: 49 additions & 0 deletions .github/code-formatter/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: "Code-Formatter"
description: "Format Ruby, Terraform, YAML/YML, Python, Markdown, JSON and html.md.erb files within a PR"
inputs:
ignore-files:
description: "Files to ignore"
required: false
default: ""

runs:
using: "composite"
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
repository: ${{ github.repository }}

- name: Check Branch exists and is not a fork.
id: branch-exists
run: |
git fetch origin
branch_name=${{ github.head_ref }}
if [[ $( git rev-parse --verify origin/$branch_name ) ]]; then
echo "result=$((0))" >> ${GITHUB_OUTPUT}
else
echo "Warning: Cannot code-format a forked branch or cannot find the branch!"
echo $branch_name
echo "Finished: no Code Formatter changes."
echo "result=$((1))" >> ${GITHUB_OUTPUT}
fi
shell: bash


- name: Setup git
run: echo ${{ github.head_ref || github.ref_name }}

- name: Create a change
working-directory: code
run: |
echo "Another change " >> test.txt
git add test.txt
# Run steps that make changes to the local repo here.

# Commit all changed files back to the repository
- uses: planetscale/ghcommit-action@v0.1.6
with:
commit_message: "🤖 fmt"
repo: ${{ github.repository }}
branch: ${{ github.head_ref || github.ref_name }}
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
7 changes: 7 additions & 0 deletions .github/workflows/graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
mutation($input: CreateCommitOnBranchInput!) {
createCommitOnBranch(input: $input) {
commit {
url
}
}
}
104 changes: 104 additions & 0 deletions .github/workflows/test-commit-signing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@

name: fmt

on:
# NOTE: Need to run on a PR so that the ${{ github.head_ref }} (branch) is non-null
pull_request:
types:
- opened
- synchronize
- reopened

jobs:
fmt-code:
runs-on: ubuntu-latest

permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the
# added or changed files to the repository.
contents: write

steps:
- uses: actions/checkout@v4
# Include the pull request ref in the checkout action to prevent merge commit
# https://github.com/actions/checkout?tab=readme-ov-file#checkout-pull-request-head-commit-instead-of-merge-commit
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Setup git
run: echo ${{ github.head_ref || github.ref_name }}

- name: Create Commit on Branch using GraphQL API
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Define GraphQL mutation
mutation='mutation($input: CreateCommitOnBranchInput!) {
createCommitOnBranch(input: $input) {
commit {
url
}
}
}'
# Define the branch and repository
branch="main" # Target branch
repositoryNameWithOwner="ep-93/house-of-fun" # Combine owner and repository name
# Define the commit message as a key-value object (headline and body)
message_headline="Automated commit"
message_body="This commit was created via the GitHub GraphQL API."

# Convert file content to Base64 encoding
filePath="README.md" # The file you want to modify
fileContent="This is an automated update."
base64FileContent=$(echo -n "$fileContent" | base64)

# Get the latest commit SHA for the branch (expectedHeadOid)
expectedHeadOid=$(curl -s -X POST \
-H "Authorization: bearer $GITHUB_TOKEN" \
-H "Content-Type: application/json" \
-d '{"query": "query { repository(name: \"house-of-fun\", owner: \"ep-93\") { ref(qualifiedName: \"refs/heads/'$branch'\") { target { ... on Commit { oid } } } } }" }' \
https://api.github.com/graphql | jq -r '.data.repository.ref.target.oid')

# Create the payload for the mutation
payload=$(jq -n \
--arg mutation "$mutation" \
--arg branch "$branch" \
--arg message_headline "$message_headline" \
--arg message_body "$message_body" \
--arg filePath "$filePath" \
--arg base64FileContent "$base64FileContent" \
--arg repositoryNameWithOwner "$repositoryNameWithOwner" \
--arg expectedHeadOid "$expectedHeadOid" \
'{
"query": $mutation,
"variables": {
"input": {
"branch": {
"repositoryNameWithOwner": $repositoryNameWithOwner,
"branchName": $branch
},
"message": {
"headline": $message_headline,
"body": $message_body
},
"fileChanges": {
"additions": [{
"path": $filePath,
"contents": $base64FileContent
}]
},
"expectedHeadOid": $expectedHeadOid
}
}
}'
)

# Make the API call
curl -X POST \
-H "Authorization: bearer $GITHUB_TOKEN" \
-H "Content-Type: application/json" \
-d "$payload" \
https://api.github.com/graphql

Empty file added code/test1.txt
Empty file.
2 changes: 2 additions & 0 deletions test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Another change
Another change

0 comments on commit efa7a9d

Please sign in to comment.