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

ci(PR): gather pull request actions in PR.yml #3769

Merged
merged 13 commits into from
Mar 19, 2024
Merged
35 changes: 35 additions & 0 deletions .github/actions/docs/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
runs:
using: composite
steps:
- uses: actions/checkout@v4
breathx marked this conversation as resolved.
Show resolved Hide resolved

- name: "Install: Rust toolchain"
uses: dsherret/rust-toolchain-file@v1

- name: Cache
uses: Swatinem/rust-cache@v2

- name: Build docs
run: make doc

- name: Copy logo image
run: cp ./images/logo.svg ./target/doc/

- name: Deploy
if: github.event_name == 'push'
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./target/doc
cname: docs.gear.rs
force_orphan: true
user_name: "github-actions[bot]"
user_email: "github-actions[bot]@users.noreply.github.com"

- name: Deploy PR
if: github.event_name == 'pull_request'
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./target/doc
destination_dir: pr-${{ github.event.number }}
2 changes: 2 additions & 0 deletions .github/actions/message/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ outputs:
description: If enable cache.
check:
description: If trigger check.
docs:
clearloop marked this conversation as resolved.
Show resolved Hide resolved
description: If trigger docs.
macos:
description: If enable macos.

Expand Down
47 changes: 31 additions & 16 deletions .github/actions/message/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
*/

const ps = require("child_process");
const core = require('@actions/core');
const github = require('@actions/github');
const core = require("@actions/core");
const github = require("@actions/github");

const BUILD_LABELS = ["A0-pleasereview", 'A4-insubstantial', 'A2-mergeoncegreen'];
const CHECKS = ["check", "build"]
const BUILD_LABELS = [
"A0-pleasereview",
"A4-insubstantial",
"A2-mergeoncegreen",
];
const CHECKS = ["check", "build"];
const DEPBOT = "[depbot]";
const MACOS = "E2-forcemacos";
const SCCACHE_PREFIX = '/mnt/sccache/';
const SCCACHE_PREFIX = "/mnt/sccache/";
const SKIP_CI = "[skip-ci]";
const SKIP_CACHE = "[skip-cache]";
const [owner, repo] = ["gear-tech", "gear"];
Expand Down Expand Up @@ -47,11 +51,17 @@ async function mock(head_sha) {
*/
async function main() {
const {
pull_request: { title, head: { sha, ref: branch }, labels: _labels },
repository: { full_name: fullName }
pull_request: {
title,
head: { sha, ref: branch },
labels: _labels,
},
repository: { full_name: fullName },
} = github.context.payload;
const labels = _labels.map(l => l.name);
const message = ps.execSync(`git log --format=%B -n 1 ${sha}`, { encoding: "utf-8" }).trim();
const labels = _labels.map((l) => l.name);
const message = ps
.execSync(`git log --format=%B -n 1 ${sha}`, { encoding: "utf-8" })
.trim();

console.log("message: ", message);
console.log("head-sha: ", sha);
Expand All @@ -61,19 +71,24 @@ async function main() {

// Calculate configurations.
const isDepbot = fullName === `${owner}/${repo}` && title.includes(DEPBOT);
const skipCache = [title, message].some(s => s.includes(SKIP_CACHE));
const skipCI = [title, message].some(s => s.includes(SKIP_CI));
const build = !skipCI && (isDepbot || BUILD_LABELS.some(label => labels.includes(label)));
const skipCache = [title, message].some((s) => s.includes(SKIP_CACHE));
const skipCI = [title, message].some((s) => s.includes(SKIP_CI));
const build =
!skipCI &&
(isDepbot || BUILD_LABELS.some((label) => labels.includes(label)));
const macos = !skipCI && labels.includes(MACOS);
const docs = !skipCI && !isDepbot;
const cache = SCCACHE_PREFIX + branch.replace("/", "_");

// Set outputs
core.setOutput("docs", docs);
core.setOutput("build", build);
core.setOutput("check", !skipCI);
core.setOutput("macos", macos);
!skipCache && core.setOutput("cache", cache)
!skipCache && core.setOutput("cache", cache);

console.log("---");
console.log("docs: ", docs);
console.log("build: ", build);
console.log("cache: ", skipCache ? "false" : cache);
console.log("check: ", !skipCI);
Expand All @@ -83,7 +98,7 @@ async function main() {
if (skipCI) await mock(sha);
}

main().catch(err => {
main().catch((err) => {
core.error("ERROR: ", err.message);
core.error(err.stack)
})
core.error(err.stack);
});
17 changes: 17 additions & 0 deletions .github/workflows/PR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,20 @@ env:
BINARYEN_VERSION: version_111

jobs:
typos:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: typos-action
uses: crate-ci/typos@master

status:
runs-on: ubuntu-latest
outputs:
build: ${{ steps.config.outputs.build }}
cache: ${{ steps.config.outputs.cache }}
check: ${{ steps.config.outputs.check }}
docs: ${{ steps.config.outputs.docs }}
macos: ${{ steps.config.outputs.macos }}
steps:
- uses: actions/checkout@v4
Expand All @@ -37,6 +45,15 @@ jobs:
with:
token: ${{ secrets.GITHUB_TOKEN }}

docs:
needs: status
if: ${{ needs.status.outputs.docs == 'true' }}
runs-on: ubuntu-lastet
env:
RUSTUP_HOME: /tmp/rustup_home
steps:
- uses: ./.github/actions/docs

check:
needs: status
if: ${{ needs.status.outputs.check == 'true' }}
Expand Down
36 changes: 1 addition & 35 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: Docs

on:
pull_request:
branches: [master]
push:
branches: [master]

Expand All @@ -15,37 +13,5 @@ jobs:
runs-on: ubuntu-latest
env:
RUSTUP_HOME: /tmp/rustup_home
if: ${{ !contains(github.event.pull_request.title, '[skip-ci]') && github.actor != 'dependabot[bot]' }}
steps:
- uses: actions/checkout@v4

- name: "Install: Rust toolchain"
uses: dsherret/rust-toolchain-file@v1

- name: Cache
uses: Swatinem/rust-cache@v2

- name: Build docs
run: make doc

- name: Copy logo image
run: cp ./images/logo.svg ./target/doc/

- name: Deploy
if: github.event_name == 'push'
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./target/doc
cname: docs.gear.rs
force_orphan: true
user_name: "github-actions[bot]"
user_email: "github-actions[bot]@users.noreply.github.com"

- name: Deploy PR
if: github.event_name == 'pull_request'
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./target/doc
destination_dir: pr-${{ github.event.number }}
- uses: ./.github/actions/docs
20 changes: 0 additions & 20 deletions .github/workflows/typos.yml

This file was deleted.

Loading