Skip to content

Commit b2fb37c

Browse files
authored
Merge pull request #889 from primer/release-workflow
Add deprecations test script; run on release branches
2 parents 06ead4c + 27beb57 commit b2fb37c

File tree

3 files changed

+100
-10
lines changed

3 files changed

+100
-10
lines changed

.github/workflows/push.yml renamed to .github/workflows/ci.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
name: "lint, test, publish"
2-
on: [push]
1+
name: CI
2+
on: push
33
jobs:
44
all:
55
runs-on: ubuntu-latest
@@ -16,6 +16,9 @@ jobs:
1616
run: npm --unsafe-perm test
1717
- name: prepublish
1818
run: script/prepublish
19+
- name: test deprecations
20+
if: startsWith(github.ref, 'refs/heads/release-')
21+
run: script/test-deprecations.js
1922
- uses: primer/publish@v1.1.0
2023
env:
2124
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

script/test-deprecations.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/usr/bin/env node
2+
const fetch = require('node-fetch')
3+
const minimist = require('minimist')
4+
const {basename} = require('path')
5+
const {green, red, yellow} = require('colorette')
6+
7+
const {versionDeprecations} = require('../deprecations')
8+
const X = red('𐄂')
9+
const I = yellow('i')
10+
const V = green('✓')
11+
12+
const args = minimist(process.argv.slice(2))
13+
if (args.help) {
14+
console.log(`
15+
script/${basename(__filename)} [options]
16+
17+
--version <version> The published version of @primer/css from which to
18+
fetch CSS selector stats; default: "latest".
19+
--bundle <bundle> The CSS bundle to compare; default: "primer".
20+
21+
Fetches the CSS selectors for the published package and checks that:
22+
23+
1. All selectors listed in deprecations.js for the current local version (in
24+
package.json) have been deleted.
25+
2. All selectors deleted in the current local version have been listed in
26+
deprecations.js.
27+
28+
If either check fails, the process exits with an error status (1).
29+
`)
30+
process.exit(0)
31+
}
32+
33+
checkDeprecations(args)
34+
35+
async function checkDeprecations(options = {}) {
36+
const {bundle = 'primer', version = 'latest'} = options
37+
38+
const currentVersion = require('../package.json').version
39+
const statsPath = `dist/stats/${bundle}.json`
40+
41+
const local = require(`../${statsPath}`)
42+
const remote = await fetch(`https://unpkg.com/@primer/css@${version}/${statsPath}`).then(res => res.json())
43+
44+
const {changed, added, removed} = diffLists(remote.selectors.values, local.selectors.values)
45+
if (changed === 0) {
46+
console.log(`no selectors added or removed in bundle "${bundle}"`)
47+
return
48+
}
49+
50+
const deprecations = versionDeprecations[currentVersion] || []
51+
const deprecatedSelectors = deprecations.reduce((list, deprecation) => list.concat(deprecation.selectors), [])
52+
console.log(`${I} ${removed.length} selectors removed locally (compared with ${version})`)
53+
console.log(`${I} ${deprecatedSelectors.length} selectors deprecated in v${currentVersion}`)
54+
if (added.length) {
55+
console.log(`${I} ${added.length} selectors added`)
56+
}
57+
58+
const errors = []
59+
for (const deprecation of deprecations) {
60+
for (const selector of deprecation.selectors) {
61+
if (!removed.includes(selector)) {
62+
const error = `"${selector}" deprecated, but not removed`
63+
errors.push(error)
64+
console.log(`${X} ${error}`)
65+
} else {
66+
console.log(`${V} "${selector}" is deprecated!`)
67+
}
68+
deprecatedSelectors.push(selector)
69+
}
70+
}
71+
72+
for (const removedSelector of removed) {
73+
if (!deprecatedSelectors.includes(removedSelector)) {
74+
const error = `"${removedSelector}" has been removed, but was not listed in versionDeprecations['${currentVersion}']`
75+
errors.push(error)
76+
console.log(`${X} ${error}`)
77+
} else {
78+
console.log(`${V} "${removedSelector}" removed and deprecated!`)
79+
}
80+
}
81+
82+
if (errors.length) {
83+
process.exitCode = 1
84+
}
85+
}
86+
87+
function diffLists(before, after) {
88+
const added = after.filter(value => !before.includes(value))
89+
const removed = before.filter(value => !after.includes(value))
90+
return {
91+
changed: added.length + removed.length,
92+
added,
93+
removed
94+
}
95+
}

src/utilities/colors.scss

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// stylelint-disable primer/selector-no-utility
33
// stylelint-disable block-opening-brace-space-before, comment-empty-line-before
44

5-
@warn ".text-pending and .bg-pending will be deprecated in 13.0.0. Use .text-yellow and .bg-yellow-dark instead";
6-
75
// background colors
86
/* Set the background to $bg-white */
97
.bg-white { background-color: $bg-white !important; }
@@ -80,12 +78,6 @@
8078
/* Set the text color to inherit */
8179
.text-inherit { color: inherit !important; }
8280

83-
// Pending states
84-
// This will be deprecated in the future, use .text-yellow instead
85-
.text-pending { color: $yellow-800 !important; }
86-
// This will be deprecated in the future, use .bg-yellow-dark instead
87-
.bg-pending { color: $yellow-700 !important; }
88-
8981
// Link colors
9082
// Sets the links color to $text-gray and $text-blue on hover
9183
.link-gray {

0 commit comments

Comments
 (0)