fix(ci): Author identity unknown when cloning into 'database' #158
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Docker Image CI | |
on: | |
push: | |
branches: [ main, ui/* ] | |
env: | |
IMAGE: ${{ secrets.DOCKERHUB_USERNAME }}/os-checker:latest | |
IMAGE_TAR: /tmp/os-checker.tar | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
# Create and boot a builder using by default the docker-container driver. | |
# This is not required but recommended using it to be able to build multi-platform images, export cache, etc. | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Build and push | |
uses: docker/build-push-action@v6 | |
with: | |
push: true | |
tags: ${{ env.IMAGE }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
outputs: type=docker,dest=${{ env.IMAGE_TAR }} | |
- name: Load and Run Docker image | |
run: | | |
docker load --input ${{ env.IMAGE_TAR }} | |
docker image ls -a | |
# DEBUG means compiling os-checker from source | |
docker run -e DEBUG=1 -v /check:/check ${{ env.IMAGE }} | |
# - name: Display the result of os-checker | |
# run: cat /check/summary.txt >> $GITHUB_STEP_SUMMARY | |
- name: Upload pages artifacts | |
uses: actions/upload-pages-artifact@v3 | |
with: | |
path: /check/dist/ | |
- name: Commit and push test.json | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
# 本仓库的 json 数据路径 | |
TEST_JSON: os-checks/public/test.json | |
TEST_RAW_REPORTS_JSON: os-checks/public/test_raw_reports.json | |
run: | | |
# author zjp-CN, and commiter bot | |
git config --global user.name "zjp-CN" | |
git config --global user.email "[email protected]" | |
git config --global committer.name "zjp-CN[bot]" | |
git config --global committer.email "zjp-CN[bot]@users.noreply.github.com" | |
git pull --rebase # 防止二次运行 CI 时落后于远程分支 | |
cp /check/test.json ${{ env.TEST_JSON }} | |
cp /check/test_raw_reports.json ${{ env.TEST_RAW_REPORTS_JSON }} | |
# 注意:如果检查结果和上次一样,那么无法提交(也不应该提交) | |
# 检查是否有未暂存的更改 | |
git_status_output=$(git status --porcelain) | |
if echo "$git_status_output" | grep -q "${{ env.TEST_JSON }}"; then | |
echo "${{ env.TEST_JSON }} 被添加到暂存" | |
git add ${{ env.TEST_JSON }} | |
fi | |
if echo "$git_status_output" | grep -q "${{ env.TEST_RAW_REPORTS_JSON }}"; then | |
echo "${{ env.TEST_RAW_REPORTS_JSON }} 被添加到暂存" | |
git add ${{ env.TEST_RAW_REPORTS_JSON }} | |
fi | |
git_diff_output=$(git diff --cached --name-only | tr '\n' ' ' | sed -e 's/ *$//') | |
if [ -n "$git_diff_output" ]; then | |
echo "正在提交 $git_diff_output" | |
git commit -m "[bot] update $git_diff_output" | |
git push | |
echo "已推送 $git_diff_output" | |
else | |
echo "工作目录干净,无需提交 ${{ env.TEST_JSON }} 和 ${{ env.TEST_RAW_REPORTS_JSON }}" | |
fi | |
echo "正在 clone os-checker/database" | |
git clone https://x-access-token:${{ secrets.ACCESS_TOKEN }}@github.com/os-checker/database.git | |
echo "成功 clone os-checker/database" | |
cd database | |
cp /check/test_raw_reports.json test_raw_reports.json | |
git add test_raw_reports.json | |
echo "正在 提交 test_raw_reports.json" | |
git commit -m "[bot] update test_raw_reports.json from WebUI repo" | |
echo "成功 提交 test_raw_reports.json" | |
git push | |
# Deploy job | |
deploy: | |
# Add a dependency to the build job | |
needs: build | |
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment | |
permissions: | |
pages: write # to deploy to Pages | |
id-token: write # to verify the deployment originates from an appropriate source | |
# Deploy to the github-pages environment | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
# Specify runner + deployment step | |
runs-on: ubuntu-latest | |
steps: | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v4 # or specific "vX.X.X" version tag for this action |