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

Slack secrets #77

Closed
wants to merge 16 commits into from
Closed
6 changes: 6 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ jobs:
name: Build, lint, and test
uses: ./.github/workflows/build-lint-test.yml

module-lint:
name: Module Lint
uses: ./.github/workflows/module-lint.yml
secrets:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

all-jobs-completed:
name: All jobs completed
runs-on: ubuntu-latest
Expand Down
88 changes: 88 additions & 0 deletions .github/workflows/module-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Module Lint

on:
workflow_call:
secrets:
icon-url:
description: 'Url to the avatar used for the bot in Slack'
required: false
default: 'https://raw.githubusercontent.com/MetaMask/action-npm-publish/main/robo.png'
username:
description: 'The name of the bot as it appears on Slack'
required: false
default: 'MetaMask bot'
subteam:
description: 'Use this if you want to ping a subteam of individuals on Slack using @'
required: false
channel:
description: 'The Slack channel to post in'
required: false
default: 'temp-test-module-lint'
jobs:
prepare:
name: Prepare
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'yarn'
- name: Install Yarn dependencies
run: yarn --immutable

module-lint:
name: Module Lint
runs-on: ubuntu-latest
needs:
- prepare
strategy:
matrix:
node-version: [16.x, 18.x, 20.x]
projects:
['auto-changelog', 'create-release-branch', 'module-lint', 'utils']
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
- run: yarn --immutable --immutable-cache
- run: yarn run-tool ${{ matrix.projects }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Require clean working directory
shell: bash
run: |
if ! git diff --exit-code; then
echo "Working tree dirty at end of job"
exit 1
fi
- id: final-text
shell: bash
if: secrets.SLACK_WEBHOOK_URL != ''
run: |
DEFAULT_TEXT="<https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/|→ Click here to review>"
SUBTEAM_TEXT="${{ secrets.subteam }}"
FINAL_TEXT="$DEFAULT_TEXT"
if [[ ! "$SUBTEAM_TEXT" == "" ]]; then
FINAL_TEXT="<!subteam^$SUBTEAM_TEXT> $DEFAULT_TEXT"
fi
echo "FINAL_TEXT=$FINAL_TEXT" >> "$GITHUB_OUTPUT"
- name: Post to a Slack channel
id: slack
if: secrets.SLACK_WEBHOOK_URL != ''
uses: slackapi/slack-github-action@007b2c3c751a190b6f0f040e47ed024deaa72844
with:
payload: |
{
"text": "${{ steps.final-text.outputs.FINAL_TEXT }}",
"icon_url": "${{ secrets.icon-url }}",
"username": "${{ secrets.username }}",
"channel": "#${{ secrets.channel }}"
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

[Unreleased]: https://github.com/MetaMask/module-lint/
[Unreleased]: https://github.com/MetaMask/module-lint-fork/
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "@metamask/module-lint",
"name": "@metamask/module-lint-fork",
"version": "0.0.0",
"description": "Analyzes one or more repos for divergence from a template repo",
"homepage": "https://github.com/MetaMask/module-lint#readme",
"homepage": "https://github.com/MetaMask/module-lint-fork#readme",
"bugs": {
"url": "https://github.com/MetaMask/module-lint/issues"
"url": "https://github.com/MetaMask/module-lint-fork/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/MetaMask/module-lint.git"
"url": "https://github.com/MetaMask/module-lint-fork.git"
},
"sideEffects": false,
"exports": {
Expand Down
15 changes: 13 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,18 @@ export async function main({
outputLogger,
});

await lintProjects({
const isAllPassed = await lintProjects({
projectReferences,
template,
workingDirectoryPath,
cachedRepositoriesDirectoryPath,
outputLogger,
});

if (!isAllPassed) {
// eslint-disable-next-line require-atomic-updates
process.exitCode = 1;
}
}

/**
Expand Down Expand Up @@ -226,18 +231,22 @@ async function lintProjects({
projectLintResultPromiseOutcomes.filter(isPromiseRejectedResult);

outputLogger.logToStdout('');
let isAllPassed = true;
fulfilledProjectLintResultPromiseOutcomes
.sort((a, b) => {
return a.value.projectName.localeCompare(b.value.projectName);
})
.forEach((fulfilledProjectLintResultPromiseOutcome, index) => {
reportProjectLintResult({
const { numberOfFailing } = reportProjectLintResult({
projectLintResult: fulfilledProjectLintResultPromiseOutcome.value,
outputLogger,
});
if (index < fulfilledProjectLintResultPromiseOutcomes.length - 1) {
outputLogger.logToStdout('\n');
}
if (numberOfFailing > 0) {
isAllPassed = false;
}
});
outputLogger.logToStdout('');

Expand All @@ -246,4 +255,6 @@ async function lintProjects({
outputLogger.logToStderr(rejectedProjectLintResultPromiseOutcome.reason);
},
);

return isAllPassed && rejectedProjectLintResultPromiseOutcomes.length === 0;
}
3 changes: 3 additions & 0 deletions src/report-project-lint-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const log = createModuleLogger(projectLogger, 'fetch-or-populate-file-cache');
* @param args - The arguments to this function.
* @param args.projectLintResult - The data collected from the lint execution.
* @param args.outputLogger - Writable streams for output messages.
* @returns Passing and Failing numbers.
*/
export function reportProjectLintResult({
projectLintResult,
Expand Down Expand Up @@ -62,6 +63,8 @@ export function reportProjectLintResult({
chalk.bold('Elapsed time:'),
projectLintResult.elapsedTimeIncludingLinting,
);

return { numberOfPassing, numberOfFailing };
}

/**
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -985,9 +985,9 @@ __metadata:
languageName: node
linkType: hard

"@metamask/module-lint@workspace:.":
"@metamask/module-lint-fork@workspace:.":
version: 0.0.0-use.local
resolution: "@metamask/module-lint@workspace:."
resolution: "@metamask/module-lint-fork@workspace:."
dependencies:
"@lavamoat/allow-scripts": ^2.3.1
"@lavamoat/preinstall-always-fail": ^1.0.0
Expand Down Expand Up @@ -1032,7 +1032,7 @@ __metadata:
typescript: ~4.8.4
yargs: ^17.7.2
bin:
module-lint: ./dist/cli.js
module-lint-fork: ./dist/cli.js
languageName: unknown
linkType: soft

Expand Down