Skip to content

Commit 24862a4

Browse files
committed
chore: version deprecation workflow
1 parent a4f305c commit 24862a4

File tree

8 files changed

+294
-0
lines changed

8 files changed

+294
-0
lines changed

.github/.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v20.15.1
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Deprecate NPM Package
2+
description: Deprecate a specific version for all lerna packages
3+
4+
inputs:
5+
version:
6+
description: 'Version to deprecate'
7+
required: true
8+
message:
9+
description: 'Deprecation message'
10+
required: true
11+
token:
12+
description: 'NPM token'
13+
required: true
14+
15+
runs:
16+
using: "composite"
17+
steps:
18+
- name: Validate version format
19+
shell: bash
20+
run: |
21+
if ! [[ "${{ inputs.version }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?$ ]]; then
22+
echo "🔴 Invalid version format: ${{ inputs.version }}" >> $GITHUB_STEP_SUMMARY
23+
exit 1
24+
fi
25+
26+
echo "### About to deprecate version: ${{ inputs.version }}" >> $GITHUB_STEP_SUMMARY
27+
echo "### Deprecation message: ${{ inputs.message }}" >> $GITHUB_STEP_SUMMARY
28+
29+
- name: Get package names
30+
id: packages
31+
shell: bash
32+
run: |
33+
echo "PACKAGE_NAMES=$(npx lerna ls --json | jq -r '.[].name' | tr '\n' ' ')" >> $GITHUB_OUTPUT
34+
35+
- name: Authenticate with NPM registry
36+
shell: bash
37+
run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc
38+
env:
39+
NPM_TOKEN: ${{ inputs.token }}
40+
41+
- name: "Notify about wait time"
42+
shell: bash
43+
run: |
44+
echo "⚠️ Will deprecate version ${{ inputs.version }} in 10 seconds. Cancel now if this is a mistake..."
45+
46+
47+
- name: Wait before deprecation
48+
uses: actions/github-script@v7
49+
with:
50+
result-encoding: string
51+
script: |
52+
const doWait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
53+
54+
(async () => {
55+
for (let i = 10; i > 0; i--) {
56+
console.log(`${i} seconds remaining...`);
57+
await doWait(1000);
58+
}
59+
60+
console.log("Proceeding with deprecation");
61+
})();
62+
63+
- name: Deprecate packages
64+
shell: bash
65+
run: |
66+
PACKAGES="${{ steps.packages.outputs.PACKAGE_NAMES }}"
67+
VERSION="${{ inputs.version }}"
68+
MESSAGE="${{ inputs.message }}"
69+
70+
echo "### Deprecating the following packages:" >> $GITHUB_STEP_SUMMARY
71+
72+
for pkg in $PACKAGES; do
73+
echo "- Deprecating $pkg@$VERSION" >> $GITHUB_STEP_SUMMARY
74+
75+
done
76+
env:
77+
NPM_TOKEN: ${{ inputs.token }}
78+
79+
80+
#npm deprecate "$pkg@$VERSION" "$MESSAGE"

.github/actions/prepare/action.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ name: "Prepare Node Env"
22
description: "start node env with pnpm"
33

44
inputs:
5+
dir:
6+
description: working directory
7+
default: "."
8+
required: false
59
with-cypress:
610
description: whether to cache cypress bin folder
711
required: false
@@ -22,14 +26,17 @@ runs:
2226
with:
2327
node-version: "20.15.1"
2428
cache: "pnpm"
29+
node-version-file: '${{ inputs.dir }}/.nvmrc'
2530

2631
- name: Install deps
2732
shell: bash
2833
run: pnpm install ${{ inputs.with-frozen == 'true' && '--frozen-lockfile' || '' }}
34+
working-directory: ${{ inputs.dir }}
2935

3036
- name: Set up Cypress binary cache
3137
if: ${{ inputs.with-cypress == 'true' }}
3238
uses: actions/cache@v4
3339
with:
3440
path: ~/.cache/Cypress
3541
key: ${{ runner.os }}-cypress-${{ hashFiles('pnpm-lock.yaml') }}
42+
working-directory: ${{ inputs.dir }}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Save Uploady Versions to Workflow
2+
description: Fetch and save Uploady versions to workflow version input
3+
4+
inputs:
5+
workflow-file:
6+
description: Path to workflow file
7+
required: true
8+
workflow-input:
9+
description: Name of the input to update with version
10+
default: "version"
11+
required: false
12+
13+
runs:
14+
using: "node20"
15+
main: "index.js"
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
const fs = require("fs");
2+
const core = require("@actions/core");
3+
const github = require("@actions/github");
4+
const yaml = require("js-yaml");
5+
6+
// const MAX_VERSIONS_STORED = 20;
7+
8+
const loadFlowYaml = (wfPath) => {
9+
let doc;
10+
11+
console.log(`Loading WF from: ${wfPath}`);
12+
try {
13+
doc = yaml.load(fs.readFileSync(wfPath, "utf8"));
14+
} catch (ex) {
15+
console.error(`Failed to read yaml file: ${wfPath}`, ex);
16+
throw new Error("Unable to load WF YAML");
17+
}
18+
19+
return doc;
20+
};
21+
22+
const saveFlowYaml = (doc, wfPath) => {
23+
console.log(`Saving WF to: ${wfPath}`);
24+
25+
try {
26+
const docStr = yaml.dump(doc, { lineWidth: -1 });
27+
fs.writeFileSync(wfPath, docStr, { encoding: "utf8" });
28+
} catch (ex) {
29+
console.error(`Failed to save updated yaml file: ${wfPath}`, ex);
30+
throw new Error("Unable to save WF YAML");
31+
}
32+
};
33+
34+
const main = () => {
35+
try {
36+
const wfFile = core.getInput("workflow-file");
37+
const wfInputName = core.getInput("workflow-input") || "version";
38+
const nonDeprecatedVersions = JSON.parse(process.env.NON_DEPRECATED_VERSIONS || "[]");
39+
40+
if (nonDeprecatedVersions.length) {
41+
const doc = loadFlowYaml(wfFile);
42+
43+
console.log(`LOADED WF YAML!`, doc.on.workflow_dispatch.inputs[wfInputName]);
44+
45+
const versionInput = doc.on.workflow_dispatch.inputs[wfInputName];
46+
47+
// Ensure first item is always empty
48+
const versions = ["", ...nonDeprecatedVersions];
49+
50+
versionInput.options = versions; //.slice(0, MAX_VERSIONS_STORED);
51+
52+
saveFlowYaml(doc, wfFile);
53+
console.log(`UPDATED WF YAML! Storing ${versionInput.options.length} versions in the options list`);
54+
55+
core.exportVariable("UPDATE_SUCCESS", "true");
56+
} else {
57+
console.warn("No versions provided to update the workflow!");
58+
}
59+
60+
core.setOutput("success", true);
61+
} catch (ex) {
62+
core.setFailed(ex.message);
63+
}
64+
};
65+
66+
main();

.github/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "uploady github workflows",
3+
"version": "1.0.0",
4+
"private": true,
5+
"dependencies": {
6+
"@actions/core": "^1.10.0",
7+
"@actions/github": "^6.0.0",
8+
"js-yaml": "^4.1.0"
9+
}
10+
}

.github/workflows/deprecate.yml

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
name: Deprecate Uploady Version
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'Version to deprecate (e.g. 1.9.0)'
8+
required: false
9+
type: choice
10+
default: ""
11+
options:
12+
- ""
13+
message:
14+
description: 'Deprecation message'
15+
required: false
16+
default: 'This version is deprecated, please upgrade to the latest version'
17+
type: string
18+
19+
permissions:
20+
id-token: write
21+
contents: write
22+
23+
defaults:
24+
run:
25+
shell: bash
26+
27+
jobs:
28+
fetch-versions:
29+
name: Fetch Non-Deprecated Versions
30+
runs-on: ubuntu-latest
31+
if: ${{ inputs.version == '' }}
32+
steps:
33+
- name: Checkout
34+
uses: actions/checkout@v4
35+
with:
36+
fetch-depth: 0
37+
38+
- name: Prepare
39+
uses: ./.github/actions/prepare
40+
with:
41+
with-frozen: false
42+
dir: ./.github
43+
44+
- name: Fetch non-deprecated versions
45+
id: fetch-versions
46+
run: |
47+
# Fetch all versions from npm for @rpldy/uploady
48+
echo "Fetching versions from npm for @rpldy/uploady..."
49+
ALL_VERSIONS=$(npm view @rpldy/uploady versions --json)
50+
51+
# Get non-deprecated versions
52+
NON_DEPRECATED=$(npm view @rpldy/uploady --json | jq -r '
53+
if has("versions") and has("deprecated") then
54+
.versions[] | select(. as $v | .deprecated | has($v) | not)
55+
else
56+
.versions[]
57+
end' | jq -s -c .)
58+
59+
echo "NON_DEPRECATED_VERSIONS=$NON_DEPRECATED" >> $GITHUB_OUTPUT
60+
echo "Found non-deprecated versions: $NON_DEPRECATED"
61+
62+
- name: Update workflow file
63+
uses: ./.github/actions/save-versions-to-wf
64+
with:
65+
workflow-file: ./.github/workflows/deprecate.yml
66+
workflow-input: version
67+
68+
- name: Summary
69+
run: |
70+
echo "### ✅ Successfully updated available versions" >> $GITHUB_STEP_SUMMARY
71+
echo "The workflow has been updated with all non-deprecated versions from npm." >> $GITHUB_STEP_SUMMARY
72+
73+
deprecate:
74+
name: Deprecate Version
75+
runs-on: ubuntu-latest
76+
environment: "Release"
77+
if: ${{ inputs.version != '' }}
78+
steps:
79+
- name: Checkout
80+
uses: actions/checkout@v4
81+
with:
82+
fetch-depth: 0
83+
84+
- name: Prepare
85+
uses: ./.github/actions/prepare
86+
with:
87+
with-frozen: true
88+
89+
- name: Deprecate version
90+
uses: ./.github/actions/npm-deprecate
91+
with:
92+
version: ${{ inputs.version }}
93+
message: ${{ inputs.message }}
94+
token: ${{ secrets.NPM_TOKEN }}
95+
96+
# - name: Fallback to manual deprecation
97+
# if: failure()
98+
# run: |
99+
# echo "Action deprecation failed, falling back to manual method"
100+
# PACKAGES=$(npx lerna ls --json | jq -r '.[].name' | tr '\n' ' ')
101+
# VERSION="${{ inputs.version }}"
102+
# MESSAGE="${{ inputs.message }}"
103+
#
104+
# echo "### Deprecating the following packages:" >> $GITHUB_STEP_SUMMARY
105+
#
106+
# for pkg in $PACKAGES; do
107+
# echo "- Deprecating $pkg@$VERSION" >> $GITHUB_STEP_SUMMARY
108+
# npm deprecate "$pkg@$VERSION" "$MESSAGE"
109+
# done
110+
111+
- name: Summary
112+
run: |
113+
echo "### ✅ Deprecation completed successfully" >> $GITHUB_STEP_SUMMARY
114+
echo "Deprecated version ${{ inputs.version }} with message: ${{ inputs.message }}" >> $GITHUB_STEP_SUMMARY

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v20.15.1

0 commit comments

Comments
 (0)