-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
116 additions
and
100 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,123 +2,139 @@ name: build | |
|
||
on: | ||
push: | ||
branches: ['*'] | ||
branches: ["*"] | ||
pull_request: | ||
branches: ['*'] | ||
branches: ["*"] | ||
workflow_dispatch: | ||
|
||
permissions: | ||
contents: write | ||
pull-requests: write | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
env: | ||
LSI: 'true' | ||
LSI: "true" | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: '3.0' | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: "3.0" | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
|
||
- name: Cache Ruby gems | ||
uses: actions/cache@v4 | ||
env: | ||
CACHE_ID: 1 | ||
with: | ||
path: | | ||
Gemfile.lock | ||
vendor/bundle | ||
key: ${{ runner.os }}-bundler-${{ env.CACHE_ID }}-${{ hashFiles('Gemfile') }} | ||
restore-keys: | | ||
${{ runner.os }}-bundler-${{ env.CACHE_ID }}- | ||
- name: Cache Node modules | ||
uses: actions/cache@v4 | ||
env: | ||
CACHE_ID: 1 | ||
with: | ||
path: ~/.npm | ||
key: ${{ runner.os }}-npm-${{ env.CACHE_ID }}-${{ hashFiles('**/package-lock.json') }} | ||
restore-keys: | | ||
${{ runner.os }}-npm-${{ env.CACHE_ID }}- | ||
- name: Cache Ruby gems | ||
uses: actions/cache@v4 | ||
env: | ||
CACHE_ID: 1 | ||
with: | ||
path: | | ||
Gemfile.lock | ||
vendor/bundle | ||
key: ${{ runner.os }}-bundler-${{ env.CACHE_ID }}-${{ hashFiles('Gemfile') }} | ||
restore-keys: | | ||
${{ runner.os }}-bundler-${{ env.CACHE_ID }}- | ||
- name: Cache Node modules | ||
uses: actions/cache@v4 | ||
env: | ||
CACHE_ID: 1 | ||
with: | ||
path: ~/.npm | ||
key: ${{ runner.os }}-npm-${{ env.CACHE_ID }}-${{ hashFiles('**/package-lock.json') }} | ||
restore-keys: | | ||
${{ runner.os }}-npm-${{ env.CACHE_ID }}- | ||
- name: Install dependencies | ||
run: | | ||
bundle config set --local path vendor/bundle | ||
bundle config set without 'development' | ||
bundle install --jobs=4 --retry=3 | ||
bundle clean | ||
npm install --include=dev | ||
- name: Install dependencies | ||
run: | | ||
bundle config set --local path vendor/bundle | ||
bundle config set without 'development' | ||
bundle install --jobs=4 --retry=3 | ||
bundle clean | ||
npm install --include=dev | ||
- name: Prettier check | ||
id: prettier | ||
run: npm run check | ||
- name: Prettier fix | ||
if: "failure() && steps.prettier.outcome == 'failure'" | ||
run: npm run fix | ||
- name: Submit PR for prettier fix | ||
if: "failure() && steps.prettier.outcome == 'failure' && github.ref == 'refs/heads/master'" | ||
uses: peter-evans/create-pull-request@v6 | ||
with: | ||
commit-message: 'Prettier auto fix from GitHub Actions run ${{ github.run_number }}' | ||
assignees: '${{ github.actor }}' | ||
branch: prettier-auto-fix | ||
delete-branch: true | ||
title: 'Fix Prettier formatting from GitHub Actions run ${{ github.run_number }}' | ||
body: | | ||
Attempt to automatically fix Prettier formatting issues in ${{ github.sha }}. | ||
- name: "Linting: autocorrect" | ||
continue-on-error: true | ||
run: | | ||
curl -fsSL https://raw.githubusercontent.com/huacnlee/autocorrect/main/install | sh | ||
autocorrect --fix | ||
This PR is generated by GitHub Actions [run ${{ github.run_number }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}). Please choose **Squash and Merge** for this PR. | ||
- name: Prettier fix | ||
continue-on-error: true | ||
run: npm run fix | ||
|
||
- name: Prepare build | ||
if: github.ref == 'refs/heads/master' | ||
run: | | ||
git clone --depth=1 --branch=gh-pages --single-branch --no-checkout \ | ||
"https://${GITHUB_ACTOR}:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git" \ | ||
_site | ||
- name: Run Jekyll Doctor | ||
run: | | ||
bundle exec jekyll doctor --trace --profile | ||
env: | ||
JEKYLL_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Determine if a PR should be submitted | ||
if: github.ref == 'refs/heads/master' | ||
id: file_changes | ||
run: | | ||
git add -A | ||
if git diff-index --quiet --cached HEAD --; then | ||
echo "should_submit=false" >> "$GITHUB_OUTPUT" | ||
else | ||
echo "should_submit=true" >> "$GITHUB_OUTPUT" | ||
fi | ||
- name: Build site | ||
run: | | ||
bundle exec jekyll build --trace --profile | ||
: > _site/.nojekyll | ||
env: | ||
JEKYLL_ENV: production | ||
JEKYLL_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Submit PR from linting | ||
if: steps.file_changes.outputs.should_submit == 'true' && github.ref == 'refs/heads/master' | ||
uses: peter-evans/create-pull-request@v6 | ||
with: | ||
commit-message: "Auto fix formatting from GitHub Actions run ${{ github.run_number }}" | ||
assignees: "${{ github.actor }}" | ||
branch: auto-fix-actions-${{ github.run_number }} | ||
delete-branch: true | ||
title: "Fix formatting from GitHub Actions run ${{ github.run_number }}" | ||
body: | | ||
Attempt to automatically fix formatting issues in ${{ github.sha }}. | ||
- name: Deploy to GitHub Pages | ||
if: github.ref == 'refs/heads/master' | ||
run: | | ||
CINFO="$(git log -1 --pretty="%an: [%h] %s")" | ||
pushd _site/ &>/dev/null | ||
echo -n lug.ustc.edu.cn > CNAME | ||
git add -A | ||
git -c user.name=GitHub -c [email protected] commit \ | ||
-m "Auto deploy from GitHub Actions build ${GITHUB_RUN_NUMBER}" \ | ||
-m "$CINFO" | ||
git push | ||
popd &>/dev/null | ||
This PR is generated by GitHub Actions [run ${{ github.run_number }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}). Please choose **Squash and Merge** for this PR. | ||
- name: Update Algolia index | ||
if: github.ref == 'refs/heads/master' | ||
run: bundle exec jekyll algolia push | ||
env: | ||
ALGOLIA_API_KEY: ${{ secrets.ALGOLIA_API_KEY }} | ||
JEKYLL_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
continue-on-error: true | ||
- name: Prepare build | ||
if: github.ref == 'refs/heads/master' | ||
run: | | ||
git clone --depth=1 --branch=gh-pages --single-branch --no-checkout \ | ||
"https://${GITHUB_ACTOR}:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git" \ | ||
_site | ||
- name: Run Jekyll Doctor | ||
run: | | ||
bundle exec jekyll doctor --trace --profile | ||
env: | ||
JEKYLL_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Call webhook | ||
if: "github.repository == 'ustclug/website' && github.ref == 'refs/heads/master'" | ||
continue-on-error: true | ||
env: | ||
WEBHOOK_SECRET: ${{ secrets.WEBHOOK_SECRET }} | ||
run: ruby _scripts/webhook.rb | ||
- name: Build site | ||
run: | | ||
bundle exec jekyll build --trace --profile | ||
: > _site/.nojekyll | ||
env: | ||
JEKYLL_ENV: production | ||
JEKYLL_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Deploy to GitHub Pages | ||
if: github.ref == 'refs/heads/master' | ||
run: | | ||
CINFO="$(git log -1 --pretty="%an: [%h] %s")" | ||
pushd _site/ &>/dev/null | ||
echo -n lug.ustc.edu.cn > CNAME | ||
git add -A | ||
git -c user.name=GitHub -c [email protected] commit \ | ||
-m "Auto deploy from GitHub Actions build ${GITHUB_RUN_NUMBER}" \ | ||
-m "$CINFO" | ||
git push | ||
popd &>/dev/null | ||
- name: Update Algolia index | ||
if: github.ref == 'refs/heads/master' | ||
run: bundle exec jekyll algolia push | ||
env: | ||
ALGOLIA_API_KEY: ${{ secrets.ALGOLIA_API_KEY }} | ||
JEKYLL_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
continue-on-error: true | ||
|
||
- name: Call webhook | ||
if: "github.repository == 'ustclug/website' && github.ref == 'refs/heads/master'" | ||
continue-on-error: true | ||
env: | ||
WEBHOOK_SECRET: ${{ secrets.WEBHOOK_SECRET }} | ||
run: ruby _scripts/webhook.rb |