In the process of business development, date formatting, URL parameter to object, browser type judgment, throttling function and other common functions are often used. In order to avoid the trouble of copying and pasting different projects many times, I closed the tool library github.com/CatsAndMice… . If you have common code, please submit pr for this project.
preface
Outside of work, I have been expanding github.com/CatsAndMice… Tool library. The repository is deployed on Github, and the documentation uses Gitee Page, but every time you push code or update a document, you need to manually synchronize Github code to Gitee, and you need to manually redeploy Gitee Page by clicking the update button, which is kind of silly. Github Actions can help me automate this. This article documents my process of configuring Github Actions to help readers with similar needs.
Configuration making Actions
Github Actions: Ruanyifeng.com Github Actions: Ruanyifeng.com
Create a Github workspace
Under the project folder, create the.github\workflows folder and create a.yml file, which I’ll call Giee-rebs-mirror.
togitee-repos-mirror.yml
File Adding Configuration
Write the following configuration in gadee-pos-mirror. yml:
name: Sync To Gitee The name can be customized
on: page_build Page_build: Triggered after the Github Page is deployed
jobs:
sync:
runs-on: ubuntu-latest
steps:
- uses: wearerequired/git-mirror-action@master # Open Source Actions package
env:
SSH_PRIVATE_KEY: The ${{ secrets.GITEE_PRIVATE_KEY }}
with:
source-repo: "[email protected]:CatsAndMice/medash.git" # github repository address
destination-repo: "[email protected]:JsHai/tool.git" Gitee warehouse address
Copy the code
Wearerequired /git-mirror-action@master is Github open source repository github.com/wearerequir… .
Source-repo and destination-repo fields use SSH addresses, so you need to set SSH keys on Github.
Configure the private key and public key
You need to install Git and open git Bash Here.
After opening it, type ssh-keygen and press Enter.
Note :.ssh is used to hide files, so you need to enable file display.
SSH generates three files. Id_rsa is the private key and id_rsa.pub is the public key.
SSH keys are configured on Github
Open the id_rsa.pub file, copy the entire contents, then go to Github and do as shown below:
The SSH Key is configured on Github.
Gitee Configure the SSH Key
The SSH Key is also required on Gitee. The operation is similar to that on Github.
Github repository configurationsecrests
Open the ID_RSA file, copy everything, go to Github repository, and switch to Settings.
Add a secret named GITEE_PRIVATE_KEY and paste the private key.
Now that the Github repository is synchronized to Gitee, you need to configure actions to update the Gitee Page.
Actions automatically updates the Gitee Page
For quick access, the Gitee Page is a priority when deploying the document, but the disadvantage is that the document update needs to be manually clicked, which is not as intelligent as the Github Page. So we need actions to help us do that.
togitee-repos-mirror.yml
File add document update configuration
name: Sync To Gitee on: page_build jobs: sync: runs-on: ubuntu-latest steps: - uses: wearerequired/git-mirror-action@master env: SSH_PRIVATE_KEY: ${{ secrets.GITEE_PRIVATE_KEY }} with: source-repo: "[email protected]:CatsAndMice/medash.git" destination-repo: "[email protected]:JsHai/tool.git" - name: Build Gitee Pages uses: yanglbme/gitee-pages-action@main with: # 130****3806 # pay attention to Settings->Secrets GITEE_PASSWORD gitee-password: ${{secretsecrets.GITEE_PASSWORD}} ${{secretsecrets. Branch: master JsHai/tool # Branch: masterCopy the code
Yanglbme /gitee-pages-action@main for Gihub Open Source Wheels: github.com/wearerequir…
Note: Gitee-repo represents the repository name, preferably using information from the URL. Since I have changed the name of my warehouse, I will get an error if I use JsHai/medash.
configurationGITEE_PASSWORD
GITEE_PASSWORD is the password for logging in to Gitee, which is the same as the previous operations for configuring ****secrests in the Github repository.
Submit to the Github repository
Push the created files to the Github repository. Each time a new code is pushed To the Master branch, Pages Build and Deployment first performs the Github Page update, and when the Github Page update is complete, Sync To Gitee is triggered To synchronize and update the Gitee Page.
After the document is updated, you can access jshai.gize. IO /tool, but not. This is because I put the document in the docs folder, just add /docs after the link to access jshai.gize. IO /tool/docs
A simple GIF demo, details can be viewed at github.com/CatsAndMice…
conclusion
This article summarizes the configuration of Github Actions, through Actions for us to complete the simple and repeated operations in daily life. There are many more interesting Actions that you can explore.