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
39 changes: 39 additions & 0 deletions .github/actions/docs/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
inputs:
github_token:
required: true

runs:
using: composite
steps:
- name: "Install: Rust toolchain"
uses: dsherret/rust-toolchain-file@v1

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

- name: Build docs
run: make doc
shell: bash

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

- name: Deploy
if: github.event_name == 'push'
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ inputs.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: ${{ inputs.github_token }}
publish_dir: ./target/doc
destination_dir: pr-${{ github.event.number }}
19 changes: 11 additions & 8 deletions .github/actions/label/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,20 @@ const checkSkip = async ({ github, core }) => {
ref: REF,
});

if (check_runs.filter((run) => (
(run.name === "build" && run.conclusion !== "skipped")
|| run.name === "build / linux"
|| run.name === "build / macos-x86"
)).length > 0) {
if (
check_runs.filter(
(run) =>
(run.name === "build" && run.conclusion !== "skipped") ||
run.name === "build / linux" ||
run.name === "build / macos-x86"
).length > 0
) {
core.info(
"Build has already been processed, check runs: ",
JSON.stringify(check_runs, null, 2)
);

process.exit(0)
process.exit(0);
}
};

Expand All @@ -59,7 +62,7 @@ const checkSkip = async ({ github, core }) => {
**/
const createChecks = async ({ core, github }) => {
let status = {};
for (check of checks) {
for (const check of checks) {
const { data: res } = await github.rest.checks.create({
owner,
repo,
Expand Down Expand Up @@ -153,7 +156,7 @@ module.exports = async ({ github, core }) => {
const jobs = await listJobs({ github, core, run_id: run.id });
completed = jobs.filter((job) => job.status === "completed").length;

for (job of jobs) {
for (const job of jobs) {
let checkJob = labelChecks[job.name];
if (
checkJob.status !== job.status ||
Expand Down
42 changes: 27 additions & 15 deletions .github/actions/message/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
*/

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 WINDOWS_NATIVE = "E1-forcenatwin";
const MACOS = "E2-forcemacos";
const RELEASE = "E3-forcerelease"
const RELEASE = "E3-forcerelease";
const SKIP_CI = "[skip-ci]";
const [owner, repo] = ["gear-tech", "gear"];

Expand All @@ -27,7 +31,7 @@ const [owner, repo] = ["gear-tech", "gear"];
async function mock(head_sha) {
const token = core.getInput("token");
const octokit = github.getOctokit(token);
for (check of CHECKS) {
for (const check of CHECKS) {
const { data: res } = await octokit.rest.checks.create({
owner,
repo,
Expand All @@ -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,8 +71,10 @@ async function main() {

// Calculate configurations.
const isDepbot = fullName === `${owner}/${repo}` && title.includes(DEPBOT);
const skipCI = [title, message].some(s => s.includes(SKIP_CI));
const build = !skipCI && (isDepbot || BUILD_LABELS.some(label => labels.includes(label)));
const skipCI = [title, message].some((s) => s.includes(SKIP_CI));
const build =
!skipCI &&
(isDepbot || BUILD_LABELS.some((label) => labels.includes(label)));
const win_native = !skipCI && labels.includes(WINDOWS_NATIVE);
const macos = !skipCI && labels.includes(MACOS);
const release = !skipCI && labels.includes(RELEASE);
Expand All @@ -85,7 +97,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);
});
19 changes: 18 additions & 1 deletion .github/workflows/PR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: PR

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

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand All @@ -16,6 +16,13 @@ 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:
Expand All @@ -38,6 +45,16 @@ jobs:
with:
token: ${{ secrets.GITHUB_TOKEN }}

docs:
runs-on: ubuntu-latest
env:
RUSTUP_HOME: /tmp/rustup_home
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/docs
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
StackOverflowExcept1on marked this conversation as resolved.
Show resolved Hide resolved

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