Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Github Actions Pull Request #40

Merged
merged 24 commits into from
Feb 16, 2024
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
6 changes: 3 additions & 3 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"terminal.integrated.defaultProfile.linux": "bash",
"terminal.integrated.experimentalRestore": true,
"actionButtons": {
"reloadButton": "♻️" /* Custom reload button text */,
"defaultColor": "#ff0034" /* Can also use string color names */,
"loadNpmCommands": false /* Disables automatic generation of actions for npm commands */,
"reloadButton": "♻️",
"defaultColor": "#ff0034",
"loadNpmCommands": false,
"commands": [
{
"cwd": "${workspaceFolder}",
Expand Down
17 changes: 17 additions & 0 deletions .github/assign.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Set to true to add reviewers to pull requests
addReviewers: true

# Set to true to add assignees to pull requests
addAssignees: false

# A list of reviewers to be added to pull requests (GitHub user name)
reviewers:
- lelouvincx
- thangbuiq
- greyyT
- TuanTran0910
- ubunchuu-admin

# A number of reviewers added to the pull request
# Set 0 to add all the reviewers (default: 0)
numberOfReviewers: 0
30 changes: 30 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# You can refer README of this repo for future mantainances: https://github.com/actions/labeler

source:
- changed-files:
- any-glob-to-any-file:
- 'src/**/*'
- '**/*.js'

content:
- changed-files:
- any-glob-to-any-file:
- blog/**/*
- docs/**/*

documentation:
- changed-files:
- any-glob-to-any-file:
- docs/**/*

blog:
- changed-files:
- any-glob-to-any-file:
- blog/**/*

devops-maintain:
- changed-files:
- any-glob-to-any-file:
- .github/**/*
- .devcontainer/**/*
- Dockerfile
63 changes: 63 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# 🐧 Ubunchuu Contribute Request

<!--
Please do not leave this blank
This PR [adds/removes/fixes/replaces] the [content/feature/bug/etc].
-->

## ❓️ What type of PR is this? (check all applicable)

- [ ] 📝 Content - Documentation Update
- [ ] 📝 Content - Blog Update
- [ ] 🎨 Style (UI/UX)
- [ ] 🍕 Feature
- [ ] 🪲 Bug Fix
- [ ] 🤖 DevOps
- [ ] 🧑‍💻 Code Refactor

## 📝 Description for my changes

> Please clear this section and include a very short summary of the change (3 lines maximum)

<!--
Please also include relevant motivation and context. List any dependencies that are required for this change.
-->

## 📌 Related Issues

> ❗️MANDATORY❗️

> Please clear this section and note that any changes to the codebase should have a related issue to provide context for the changes.

<!--
Please use this format link issue numbers: Fixes #123
https://docs.github.com/en/free-pro-team@latest/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword
-->

## 🖥️ Mobile/Desktop Screenshots (optinal)

<!-- Visual changes require screenshots -->

> If applicable, add screenshots to help explain your changes.

> Please clear this whole section if not applicable.

---

<!-- note: PRs with deleted sections will be marked invalid -->

<!--
For Work In Progress Pull Requests, please use the Draft PR feature,
see https://github.blog/2019-02-14-introducing-draft-pull-requests/ for further details.

For a timely review/response, please avoid force-pushing additional
commits if your PR already received reviews or comments.

Before submitting a Pull Request, please ensure you've done the following:
- 📖 Read the Open Sauced Contributing Guide: https://github.com/open-sauced/.github/blob/main/CONTRIBUTING.md.
- 📖 Read the Open Sauced Code of Conduct: https://github.com/open-sauced/.github/blob/main/CODE_OF_CONDUCT.md.
- 👷‍♀️ Create small PRs. In most cases, this will be possible.
- ✅ Provide tests for your changes.
- 📝 Use descriptive commit messages.
- 📗 Update any related documentation and include any relevant screenshots.
-->
13 changes: 13 additions & 0 deletions .github/workflows/auto_assign.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: 'PR Assigner'
on:
pull_request:
types: [opened, ready_for_review]

jobs:
add-reviews:
name: Auto
runs-on: ubuntu-22.04
steps:
- uses: kentaro-m/auto-assign-action@v2.0.0
with:
configuration-path: '.github/assign.yml'
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Auto approve and merge PRs by dependabot
name: 'Dependabot'
on:
pull_request:
branches: [main]
Expand Down Expand Up @@ -26,14 +26,15 @@ jobs:
USER_EMAIL: 159746302+ubunchuu-admin@users.noreply.github.com
APPROVE_TEXT: Legit to bot ✅

- name: Auto merge
- name: Auto merge for github_actions label
if: contains(github.event.pull_request.labels.*.name, 'github_actions')
run: |
git config --global user.name "${USER_NAME}"
git config --global user.email "${USER_EMAIL}"
curl -X PUT \
-H "Authorization: Bearer ${{ secrets.TOKEN_GITHUB }}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/merge?merge_method=merge"
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/merge?merge_method=squash"
env:
USER_NAME: ubunchuu[bot]
USER_EMAIL: 159746302+ubunchuu-admin@users.noreply.github.com
14 changes: 14 additions & 0 deletions .github/workflows/auto_labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: 'PR Labeler'
on:
pull_request:
types: [opened, ready_for_review, reopened, synchronize]

jobs:
labeler:
name: Auto
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-22.04
steps:
- uses: actions/labeler@v5
32 changes: 28 additions & 4 deletions .github/workflows/codespaces-image.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
name: Create and publish a Docker image
# Path: .github/workflows/codespaces.yml
name: Codespaces Image

on:
pull_request:
branches: ['main']
paths:
- Dockerfile
push:
branches: ['main']
paths:
Expand All @@ -12,8 +17,27 @@ env:
IMAGE_NAME: ubunchuu-truong-us/devcontainer:latest

jobs:
build-test-image:
name: Test
runs-on: ubuntu-22.04
permissions:
contents: read
packages: read
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
push: false
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

build-and-push-image:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
if: github.event_name == 'push'
needs: [build-test-image]
permissions:
contents: read
packages: write
Expand All @@ -22,14 +46,14 @@ jobs:
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ env.USER }}
password: ${{ secrets.TOKEN_GITHUB }}

- name: Build and push Docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
uses: docker/build-push-action@v5.0.0
with:
context: .
push: true
Expand Down
34 changes: 34 additions & 0 deletions .github/workflows/contribute.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Create Contribute Pull Request
on: create
permissions:
contents: write
pull-requests: write
id-token: write

jobs:
create_pull_request:
if: ${{ contains(github.ref, 'refs/heads/content/') }}
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
ref: ${{ github.ref }}

- name: Output Branch Name remove the refs/heads/
run: echo "branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV

- name: Initial commit to branch by bot
run: |
git checkout ${{ env.branch }}
git config --global user.name "ubunchuu[bot]"
git config --global user.email "159746302+ubunchuu-admin@users.noreply.github.com"
git commit --allow-empty -m "ci: initial commit by bot"
git push origin ${{ env.branch }}

- name: Open PR
id: open_pr
run: |
gh pr create --title "[AUTOMATIC] Contribute: ${{ env.branch }}" --body-file .github/pull_request_template.md
env:
GH_TOKEN: ${{ secrets.TOKEN_GITHUB }}
99 changes: 88 additions & 11 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,115 @@
name: Docusaurus Deploy
name: 'Docusaurus CI/CD'

on:
push:
branches:
- main
branches: ['main']
pull_request:
branches: ['main']

permissions:
contents: read
pages: write
id-token: write
pull-requests: write

jobs:
deploy:
build-and-serve:
name: Test
runs-on: ubuntu-22.04
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Setup Node.js Environment
uses: actions/setup-node@v4
with:
node-version: '18'

- name: Install Dependencies
run: |
install_before_time=$(date +%s.%N)
yarn install --frozen-lockfile
install_after_time=$(date +%s.%N)
install_time=$(python -c "print($install_after_time - $install_before_time)")
echo "installTime=$install_time" >> $GITHUB_ENV

- name: Build Website
run: |
before_time=$(date +%s.%N)
yarn build
after_time=$(date +%s.%N)
build_time=$(python -c "print($after_time - $before_time)")
echo "buildTime=$build_time" >> $GITHUB_ENV

- name: Verify Build Output
run: |
if [ -d "build" ]; then
echo "Build successful"
else
echo "Build failed"
exit 1
fi

- name: Test Server Functionality
run: |
yarn serve &
sleep 5
kill %1

- name: Comment on Pull Request
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.TOKEN_GITHUB }}
script: |
const installTime = process.env.installTime;
const buildTime = process.env.buildTime;
const table = `
| Step | Time (seconds) |
|----------------------|----------------|
| Install Dependencies | ${installTime} |
| Build Website | ${buildTime} |
`;
const header = `## Performance Report\n- Run number: ${process.env.GITHUB_RUN_NUMBER} \n - Run ID: ${process.env.GITHUB_RUN_ID} \n - Run URL: ${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}\n - ✅ Test server functionality passed with the following times for each step:\n`;
const commentBody = `${header}\n\n${table}`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});

deploy-docusaurus:
if: github.event_name == 'push'
needs: [build-and-serve]
name: Deploy to GitHub Pages
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Checkout Code (with Submodules)
uses: actions/checkout@v4
with:
submodules: 'recursive'

- uses: actions/setup-node@v4
- name: Setup Node.js Environment
uses: actions/setup-node@v4
with:
node-version: '18'

- name: Install dependencies
- name: Install Dependencies
run: yarn install --frozen-lockfile

- name: Build website
- name: Build Website
run: yarn build

- name: Setup Pages
- name: Configure GitHub Pages
uses: actions/configure-pages@v4

- name: Upload artifact
- name: Upload Website Artifact
uses: actions/upload-pages-artifact@v3
with:
path: './build'
Expand Down
Loading
Loading