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

Add automation scripts for workflow and linter templates #34

Merged
merged 9 commits into from
Aug 31, 2023
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ NOTICE
.github/
.gitignore
.eslintrc
.stylelintrc

docs/
docTemplates/

204 changes: 202 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,203 @@
# Auro Library
# Auro-Library

This repository holds shared scripts, utilities, and workflows utilized acorss repositories along the Auro Design System.
<!-- AURO-GENERATED-CONTENT:START (FILE:src=./../docs/partials/description.md) -->
<!-- The below content is automatically added from ./../docs/partials/description.md -->
This repository holds shared scripts, utilities, and workflows utilized acorss repositories along the Auro Design System.
<!-- AURO-GENERATED-CONTENT:END -->

## Scripts

#### Publish Surge Demo

<!-- AURO-GENERATED-CONTENT:START (FILE:src=./../docs/partials/description.md) -->
<!-- The below content is automatically added from ./../docs/partials/description.md -->
This repository holds shared scripts, utilities, and workflows utilized acorss repositories along the Auro Design System.
<!-- AURO-GENERATED-CONTENT:END -->

#### Surge Demo Teardown

<!-- AURO-GENERATED-CONTENT:START (FILE:src=./../docs/partials/demoTeardown.md) -->
<!-- The below content is automatically added from ./../docs/partials/demoTeardown.md -->

## Dependency Tag Versioming

This workflow works to automatically delete and clear any surge demos that have been active for more than 2+ months. Surge in theory allows us to have an infinite amount of active pages but by clearing unused and stale demos we can keep our Surge account more organized in the future.

> Note: This workflow exectutes on a monthly cronjob on the first of each month.

In order to clear all our surge projects we rely on [this GitHub Action](https://github.com/marketplace/actions/surge-sh-teardown) to handle the deletion logic.
<!-- AURO-GENERATED-CONTENT:END -->

#### Dependency Tag Versioning

<!-- AURO-GENERATED-CONTENT:START (FILE:src=./../docs/partials/dependencyTagVersioning.md) -->
<!-- The below content is automatically added from ./../docs/partials/dependencyTagVersioning.md -->

## Dependency Tag Versioming

This is a two part utility for the purpose of generating a custom string for dependency component tag naming. This is important to prevent [version conflicts](https://www.thinktecture.com/en/web-components/web-components-flaws/#elementor-toc__heading-anchor-0) when multiple versions of a given Auro component may be loaded on a single page.

_Note: The example configuration used below in all code samples assumes `auro-dropdown` is the dependency component. Substitute any Auro component in the example code as needed._

### Part 1: The Build

#### Configuration

1. Create a new file `./scripts/version.js` with the following content:

```js
const versionWriter = require("./versionWriter"); // need to update this with the right path when used from node_modules

versionWriter.writeDepVersionFile('@aurodesignsystem/auro-dropdown'); // duplicate this line for each Auro dependency.
```

2. Add the following script to the component `package.json` file:

```json
"build:version": "node scripts/version.js"
```

3. The `build:version` script in `package.json` should be added as the first step of the `build` script.

```json
"build": "npm-run-all build:version ... etc.",
```

#### Execution

Once configuration is complete, execute `npm run build`. This must be done once before `npm run dev` when developing locally. When Auro dependencies are initially installed or updated to new versions then `npm run build:version` or a complete `npm run build` must be executed.

Upon execution of `build:version`, for each Auro dependency defined in the `./scripts/version.js` file, a new JS file will be created that contains the installed version of the dependency.

For example, following these steps:
1. Run `npm i @aurodesignsystem/auro-dropdown@1.0.0`
1. add the following to the `./scripts/version.js` script file:
```js
versionWriter.writeDepVersionFile('@aurodesignsystem/auro-dropdown');
```
1. Run `npm run build`

Will result in:
- A new file created: `./src/dropdownVersion.js`
- File content will export the version of the component installed. In this case:
`export default '1.0.0'`

### Part 2: The Runtime

#### Configuration

In the main component JS file located in the `./src` directory add the following:

```js
import { AuroDependencyVersioning } from "../scripts/dependencyTagVersioning.mjs";
import { AuroDropdown } from '@aurodesignsystem/auro-dropdown/src/auro-dropdown.js';
import dropdownVersion from './dropdownVersion';
```

In the components constructor add the following:

```js
const versioning = new AuroDependencyVersioning();
this.dropdownTag = versioning.generateTag('auro-dropdown', dropdownVersion, AuroDropdown);
```

In the component properties add the following:

```js
/**
* @private
*/
dropdownTag: { type: Object }
```

#### Usage

The new dynamically named version of `auro-dropdown` may now be used in your component template as follows:

```js
render() {
return html`
<div>
<${this.dropdownTag}></${this.dropdownTag}>
</div>
`;
}
```

When the component is rendered during runtime the DOM will now show up as follows:

```html
<div>
<auro-dropdown_1_0_0></auro-dropdown_1_0_0>
</div>
```

_Note: the numbers attached in the tag name will match the version of the dependency that was installed._

#### Accessing the dynamically named element with JS

The dynamic component is accessible using a the following string in a JS query selector: `this.dropdownTag._$litStatic# Auro-Library

<!-- AURO-GENERATED-CONTENT:START (FILE:src=./../docs/partials/description.md) -->
<!-- The below content is automatically added from ./../docs/partials/description.md -->
This repository holds shared scripts, utilities, and workflows utilized acorss repositories along the Auro Design System.
<!-- AURO-GENERATED-CONTENT:END -->

## Scripts

#### Publish Surge Demo

<!-- AURO-GENERATED-CONTENT:START (FILE:src=./../docs/partials/description.md) -->
<!-- The below content is automatically added from ./../docs/partials/description.md -->
This repository holds shared scripts, utilities, and workflows utilized acorss repositories along the Auro Design System.
<!-- AURO-GENERATED-CONTENT:END -->

#### Surge Demo Teardown

<!-- AURO-GENERATED-CONTENT:START (FILE:src=./../docs/partials/demoTeardown.md) -->
<!-- The below content is automatically added from ./../docs/partials/demoTeardown.md -->

## Dependency Tag Versioming

This workflow works to automatically delete and clear any surge demos that have been active for more than 2+ months. Surge in theory allows us to have an infinite amount of active pages but by clearing unused and stale demos we can keep our Surge account more organized in the future.

> Note: This workflow exectutes on a monthly cronjob on the first of each month.

In order to clear all our surge projects we rely on [this GitHub Action](https://github.com/marketplace/actions/surge-sh-teardown) to handle the deletion logic.
<!-- AURO-GENERATED-CONTENT:END -->

#### Dependency Tag Versioning

```js
firstUpdated() {
this.dropdown = this.shadowRoot.querySelector(this.dropdownTag._$litStatic$);
};
```
<!-- AURO-GENERATED-CONTENT:END -->

#### Sync All Templates

<!-- AURO-GENERATED-CONTENT:START (FILE:src=./../docs/partials/syncAllTemplates.md) -->
<!-- The below content is automatically added from ./../docs/partials/syncAllTemplates.md -->

## How to Run the `syncAllTemplates.mjs` Script

To run the `syncAllTemplates.mjs` script, you will need to add a new node script into the linked component and point that to the `syncAllTemplates.mjs` file. You can individually run the workflow configurations by pointing to the `syncAllTemplates.mjs` file and adding a `--github` parameter after the path. The same can be done for the linter configurations by adding a `--linters` parameter.

### Example Calls

```
// Default
"syncTemplates": "./node_modules/@aurodesignsystem/auro-library/scripts/setup/syncAllTemplates.mjs"
```

```
// Only sync github workflow templates
"syncTemplates": "./node_modules/@aurodesignsystem/auro-library/scripts/setup/syncAllTemplates.mjs --github"
```

```
// Only sync linter configuration templates
"syncTemplates": "./node_modules/@aurodesignsystem/auro-library/scripts/setup/syncAllTemplates.mjs --linters"
```
<!-- AURO-GENERATED-CONTENT:END -->
5 changes: 5 additions & 0 deletions componentTemplates/linters/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
blackfalcon marked this conversation as resolved.
Show resolved Hide resolved
"extends": [
"@aurodesignsystem/eslint-config"
]
}
109 changes: 109 additions & 0 deletions componentTemplates/linters/.stylelintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
{
"extends": ["stylelint-config-recommended", "stylelint-config-idiomatic-order", "stylelint-config-standard-scss"],
"plugins": [
"stylelint-scss"
],
"rules": {
"alpha-value-notation": "number",
"at-rule-empty-line-before": [ "always", {
"except": [
"after-same-name",
"blockless-after-same-name-blockless",
"first-nested"
],
"ignore": [
"after-comment",
"blockless-after-blockless"
]
} ],
"at-rule-no-unknown": null,
"color-function-notation": "modern",
"color-named": "never",
"declaration-block-no-duplicate-custom-properties": true,
"declaration-block-no-duplicate-properties": true,
"declaration-block-no-redundant-longhand-properties": true,
"declaration-no-important": true,
"font-family-name-quotes": "always-where-recommended",
"font-weight-notation": "numeric",
"function-url-no-scheme-relative": true,
"function-url-quotes": "always",
"hue-degree-notation": "angle",
"max-nesting-depth": 2,
"named-grid-areas-no-invalid": true,
"no-empty-source": null,
"no-unknown-animations": true,
"no-invalid-position-at-import-rule": null,
"scss/at-else-closing-brace-newline-after": "always-last-in-chain",
"scss/at-else-closing-brace-space-after": "always-intermediate",
"scss/at-else-empty-line-before": "never",
"scss/at-else-if-parentheses-space-before": "always",
"scss/at-function-parentheses-space-before": "never",
"scss/at-if-closing-brace-newline-after": "always-last-in-chain",
"scss/at-if-closing-brace-space-after": "always-intermediate",
"scss/at-if-no-null": true,
"scss/at-import-partial-extension": null,
"scss/at-mixin-parentheses-space-before": "never",
"scss/at-rule-conditional-no-parentheses": true,
"scss/at-rule-no-unknown": true,
"scss/comment-no-empty": true,
"scss/declaration-nested-properties-no-divided-groups": true,
"scss/dollar-variable-colon-newline-after": "always-multi-line",
"scss/dollar-variable-colon-space-after": "always-single-line",
"scss/dollar-variable-colon-space-before": "never",
"scss/dollar-variable-empty-line-before": [
"always",
{
"except": [
"first-nested",
"after-dollar-variable"
],
"ignore": [
"after-comment",
"inside-single-line-block"
]
}
],
"scss/dollar-variable-first-in-block": [
true,
{
"ignore": [
"comments",
"imports"
]
}
],
"scss/dollar-variable-no-missing-interpolation": true,
"scss/double-slash-comment-whitespace-inside": "always",
"scss/map-keys-quotes": "always",
"scss/no-duplicate-dollar-variables": true,
"scss/no-duplicate-mixins": true,
"scss/no-global-function-names": true,
"scss/operator-no-newline-after": true,
"scss/operator-no-newline-before": true,
"scss/operator-no-unspaced": true,
"scss/selector-nest-combinators": "always",
"scss/selector-no-redundant-nesting-selector": true,
"selector-attribute-quotes": "always",
"selector-class-pattern": "^[a-z][a-zA-Z0-9]+$",
"selector-id-pattern": "^[a-z][a-zA-Z0-9]+$",
"selector-max-attribute": 1,
"selector-max-class": 1,
"selector-max-combinators": 1,
"selector-max-compound-selectors": 2,
"selector-max-id": 1,
"selector-max-pseudo-class": 2,
"selector-max-type": 1,
"selector-max-universal": 1,
"selector-no-qualifying-type": true,
"selector-pseudo-element-colon-notation": "single",
"selector-type-no-unknown": [
true,
{
"ignore": [
"custom-elements"
]
}
],
"shorthand-property-no-redundant-values": true
}
}
9 changes: 9 additions & 0 deletions componentTemplates/workflows/autoAssign.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: Issue assignment

on:
issues:
types: [opened]

jobs:
call-auro-assign-workflow:
uses: AlaskaAirlines/auro-library/.github/workflows/autoAssign.yml@main
58 changes: 58 additions & 0 deletions componentTemplates/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: "CodeQL"

on:
push:
branches: [ [branchName] ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ [branchName] ]

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'javascript' ]
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality


# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
# - name: Autobuild
# uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
Loading