Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

(chore) - Add artifacts to GitHub Actions CI workflow (#1568)

* Add pack script to imitate yarn-pack

* Refactor placement of scripts and commands

* Add artifact uploading for builds

* Move yarn-run to local GitHub Action

authored by

Phil Pluckthun and committed by
GitHub
69847811 76043cb9

+314 -59
+1 -1
.github/CODEOWNERS
··· 1 - /.github/ @kitten @jovidecroock 2 1 /.github/ @kitten @jovidecroock @andyrichardson 3 2 /.changeset/config.json @kitten @jovidecroock 3 + /scripts/actions/* @kitten @jovidecroock 4 4 /scripts/prepare/* @kitten @jovidecroock 5 5 /scripts/rollup/* @kitten @jovidecroock 6 6 /scripts/changesets/* @kitten @jovidecroock
+12
.github/actions/yarn-run/action.js
··· 1 + const run = require('execa')( 2 + 'yarn', 3 + ['run', process.env.INPUT_COMMAND], 4 + { cwd: process.cwd(), } 5 + ); 6 + 7 + run.stdout.pipe(process.stdout); 8 + run.stderr.pipe(process.stderr); 9 + 10 + run 11 + .then(result => process.exit(result.exitCode)) 12 + .catch(error => process.exit(error.exitCode || -1));
+9
.github/actions/yarn-run/action.yml
··· 1 + name: 'Run a Yarn command' 2 + description: 'Locally run a forked Yarn command as an action.' 3 + inputs: 4 + command: 5 + description: 'Command' 6 + default: 'help' 7 + runs: 8 + using: 'node12' 9 + main: 'action.js'
+7 -3
.github/workflows/ci.yml
··· 91 91 strategy: 92 92 matrix: 93 93 node: [0, 1, 2] 94 + env: 95 + NODE_TOTAL: 3 96 + NODE_INDEX: ${{matrix.node}} 94 97 steps: 95 98 - name: Checkout Repo 96 99 uses: actions/checkout@v2 ··· 124 127 run: yarn install --prefer-offline --frozen-lockfile --non-interactive --silent 125 128 - name: Build 126 129 run: yarn run build 127 - env: 128 - NODE_TOTAL: 3 129 - NODE_INDEX: ${{matrix.node}} 130 + - name: Pack 131 + uses: ./.github/actions/yarn-run 132 + with: 133 + command: pack
+9 -7
package.json
··· 8 8 "test": "jest", 9 9 "check": "tsc", 10 10 "lint": "eslint --ext=js,jsx,ts,tsx .", 11 - "build": "node ./scripts/rollup/build.js", 12 - "postinstall": "node ./scripts/prepare/postinstall.js" 11 + "build": "node ./scripts/actions/build-all.js", 12 + "postinstall": "node ./scripts/prepare/postinstall.js", 13 + "pack": "node ./scripts/actions/pack-all.js" 13 14 }, 14 15 "jest": { 15 16 "projects": [ ··· 59 60 "react-is": "^17.0.2" 60 61 }, 61 62 "devDependencies": { 63 + "@actions/artifact": "^0.5.1", 62 64 "@babel/core": "^7.13.16", 63 65 "@babel/plugin-transform-object-assign": "^7.12.13", 64 66 "@babel/plugin-transform-react-jsx": "^7.13.12", ··· 93 95 "jest": "^26.6.3", 94 96 "jest-watch-yarn-workspaces": "^1.1.0", 95 97 "lint-staged": "^10.5.4", 98 + "npm-packlist": "^2.1.5", 96 99 "npm-run-all": "^4.1.5", 97 100 "prettier": "^2.2.1", 98 101 "rimraf": "^3.0.2", ··· 101 104 "rollup-plugin-terser": "^7.0.2", 102 105 "rollup-plugin-typescript2": "^0.30.0", 103 106 "rollup-plugin-visualizer": "^5.4.1", 107 + "react": "^17.0.2", 108 + "react-dom": "^17.0.2", 109 + "react-is": "^17.0.2", 110 + "tar": "^6.1.0", 104 111 "terser": "^5.7.0", 105 112 "ts-jest": "^26.5.5", 106 113 "typescript": "^4.2.4" 107 - }, 108 - "dependencies": { 109 - "react": "^17.0.2", 110 - "react-dom": "^17.0.2", 111 - "react-is": "^17.0.2" 112 114 } 113 115 }
+1
packages/react-urql/package.json
··· 36 36 "check": "tsc --noEmit", 37 37 "lint": "eslint --ext=js,jsx,ts,tsx .", 38 38 "build": "rollup -c ../../scripts/rollup/config.js", 39 + "prepare": "node ../../scripts/prepare/index.js", 39 40 "prepublishOnly": "run-s clean build" 40 41 }, 41 42 "jest": {
+15
scripts/actions/build-all.js
··· 1 + #!/usr/bin/env node 2 + 3 + const { listPackages } = require('./lib/packages'); 4 + const { buildPackage } = require('./lib/commands'); 5 + 6 + (async () => { 7 + try { 8 + const packages = await listPackages(); 9 + const builds = packages.map(buildPackage); 10 + await Promise.all(builds); 11 + } catch (e) { 12 + console.error(e.message); 13 + process.exit(1); 14 + } 15 + })();
+72
scripts/actions/lib/commands.js
··· 1 + const path = require('path'); 2 + const execa = require('execa'); 3 + const fs = require('fs'); 4 + const tar = require('tar'); 5 + const stream = require('stream'); 6 + const packlist = require('npm-packlist'); 7 + 8 + const { workspaceRoot } = require('./constants'); 9 + const { getPackageManifest, getPackageArtifact } = require('./packages'); 10 + 11 + const pipeline = require('util').promisify(stream.pipeline); 12 + 13 + const buildPackage = async (cwd) => { 14 + const manifest = getPackageManifest(cwd); 15 + console.log('> Building', manifest.name); 16 + 17 + try { 18 + await execa( 19 + 'run-s', 20 + ['build'], 21 + { 22 + preferLocal: true, 23 + localDir: workspaceRoot, 24 + cwd, 25 + } 26 + ); 27 + } catch (error) { 28 + console.error('> Build failed', manifest.name); 29 + throw error; 30 + } 31 + }; 32 + 33 + const preparePackage = async (cwd) => { 34 + const manifest = getPackageManifest(cwd); 35 + console.log('> Preparing', manifest.name); 36 + 37 + try { 38 + await execa.node( 39 + require.resolve('../../prepare/index.js'), 40 + { cwd }, 41 + ); 42 + } catch (error) { 43 + console.error('> Preparing failed', manifest.name); 44 + throw error; 45 + } 46 + }; 47 + 48 + const packPackage = async (cwd) => { 49 + const manifest = getPackageManifest(cwd); 50 + const artifact = getPackageArtifact(cwd); 51 + console.log('> Packing', manifest.name); 52 + 53 + try { 54 + await pipeline( 55 + tar.create( 56 + { 57 + cwd, 58 + prefix: 'package/', 59 + portable: true, 60 + gzip: true, 61 + }, 62 + (await packlist({ path: cwd })).map((f) => `./${f}`) 63 + ), 64 + fs.createWriteStream(path.resolve(cwd, artifact)) 65 + ); 66 + } catch (error) { 67 + console.error('> Packing failed', manifest.name); 68 + throw error; 69 + } 70 + }; 71 + 72 + module.exports = { buildPackage, preparePackage, packPackage };
+6
scripts/actions/lib/constants.js
··· 1 + const path = require('path'); 2 + 3 + module.exports = { 4 + workspaceRoot: path.resolve(__dirname, '../../../'), 5 + workspaceManifest: require('../../../package.json'), 6 + };
+27
scripts/actions/lib/github.js
··· 1 + const path = require('path'); 2 + const { getPackageManifest, getPackageArtifact } = require('./packages'); 3 + 4 + let _client; 5 + const client = () => { 6 + return _client || (_client = require('@actions/artifact').create()); 7 + }; 8 + 9 + const uploadArtifact = async (cwd) => { 10 + const manifest = getPackageManifest(cwd); 11 + const artifact = getPackageArtifact(cwd); 12 + console.log('> Uploading', manifest.name); 13 + 14 + try { 15 + await client().uploadArtifact( 16 + artifact, 17 + [path.resolve(cwd, artifact)], 18 + cwd, 19 + { continueOnError: false } 20 + ); 21 + } catch (error) { 22 + console.error('> Uploading failed', manifest.name); 23 + throw error; 24 + } 25 + }; 26 + 27 + module.exports = { uploadArtifact };
+54
scripts/actions/lib/packages.js
··· 1 + const path = require('path'); 2 + const glob = require('util').promisify(require('glob')); 3 + 4 + const { workspaceRoot, workspaceManifest } = require('./constants'); 5 + 6 + const getPackageManifest = (cwd) => 7 + require(path.resolve(cwd, 'package.json')); 8 + 9 + const getPackageArtifact = (cwd) => { 10 + const pkg = getPackageManifest(cwd); 11 + const name = 12 + pkg.name[0] === "@" 13 + ? pkg.name.slice(1).replace(/\//g, '-') 14 + : pkg.name; 15 + return `${name}-v${pkg.version}.tgz`; 16 + }; 17 + 18 + const listPackages = async () => { 19 + let manifests = await Promise.all( 20 + workspaceManifest.workspaces.map(dir => glob(`${dir}/package.json`)) 21 + ); 22 + 23 + manifests = manifests.reduce((acc, manifests) => { 24 + acc.push(...manifests); 25 + return acc; 26 + }, []); 27 + 28 + let packages = manifests 29 + .filter(pkg => !require(path.join(workspaceRoot, pkg)).private) 30 + .map(pkg => path.resolve(pkg, '../')); 31 + 32 + if (process.env.NODE_TOTAL) { 33 + const nodeTotal = parseInt(process.env.NODE_TOTAL, 10) || 1; 34 + const nodeIndex = parseInt(process.env.NODE_INDEX, 10) % nodeTotal; 35 + packages = packages.filter((_, i) => i % nodeTotal === nodeIndex); 36 + console.log(`> Node ${nodeIndex + 1} of ${nodeTotal}.`); 37 + } 38 + 39 + return packages; 40 + }; 41 + 42 + const listArtifacts = async () => { 43 + return (await listPackages()).map(cwd => { 44 + const artifact = getPackageArtifact(cwd); 45 + return path.resolve(cwd, artifact); 46 + }); 47 + }; 48 + 49 + module.exports = { 50 + getPackageManifest, 51 + getPackageArtifact, 52 + listPackages, 53 + listArtifacts, 54 + };
+24
scripts/actions/pack-all.js
··· 1 + #!/usr/bin/env node 2 + 3 + const { listPackages } = require('./lib/packages'); 4 + const { preparePackage, packPackage } = require('./lib/commands'); 5 + const { uploadArtifact } = require('./lib/github'); 6 + 7 + (async () => { 8 + try { 9 + const isPR = process.env.GITHUB_EVENT_NAME === 'pull_request'; 10 + const packages = await listPackages(); 11 + const packs = packages.map(async (cwd) => { 12 + await preparePackage(cwd); 13 + await packPackage(cwd); 14 + if (isPR) { 15 + await uploadArtifact(cwd); 16 + } 17 + }); 18 + 19 + await Promise.all(packs); 20 + } catch (e) { 21 + console.error(e.message); 22 + process.exit(1); 23 + } 24 + })();
-47
scripts/rollup/build.js
··· 1 - #!/usr/bin/env node 2 - 3 - const path = require('path'); 4 - const glob = require('glob').sync; 5 - const execa = require('execa'); 6 - 7 - const workspaceRoot = path.resolve(__dirname, '../../'); 8 - 9 - let packages = glob('{packages,exchanges}/*/package.json') 10 - .filter(pkg => !require(path.join(workspaceRoot, pkg)).private) 11 - .map(pkg => path.resolve(pkg, '../')); 12 - 13 - if (process.env.NODE_TOTAL) { 14 - const nodeTotal = parseInt(process.env.NODE_TOTAL, 10) || 1; 15 - const nodeIndex = parseInt(process.env.NODE_INDEX, 10) % nodeTotal; 16 - packages = packages.filter((_, i) => i % nodeTotal === nodeIndex); 17 - console.log(`> Node ${nodeIndex + 1} of ${nodeTotal}.`); 18 - } 19 - 20 - const builds = packages.map(async package => { 21 - const packageName = path.relative(workspaceRoot, package); 22 - console.log('> Building', packageName); 23 - 24 - try { 25 - await execa( 26 - 'run-s', 27 - ['build'], 28 - { 29 - preferLocal: true, 30 - localDir: workspaceRoot, 31 - cwd: package, 32 - } 33 - ); 34 - } catch (error) { 35 - console.error('> Build failed', packageName); 36 - console.error(error); 37 - throw error; 38 - } 39 - }); 40 - 41 - (async () => { 42 - try { 43 - await Promise.all(builds); 44 - } catch (e) { 45 - process.exit(1); 46 - } 47 - })();
+77 -1
yarn.lock
··· 2 2 # yarn lockfile v1 3 3 4 4 5 + "@actions/artifact@^0.5.1": 6 + version "0.5.1" 7 + resolved "https://registry.yarnpkg.com/@actions/artifact/-/artifact-0.5.1.tgz#1eeea3236fd89e3f39f5a491649cb293c3872340" 8 + integrity sha512-wKXEa4fhvgsw3kPu74F3J6eAi92rqv7BvpjEAmiqmDFeuDj6cyqWDWXx6axWfiBmmln1/LVf1DLWikbciKkoVQ== 9 + dependencies: 10 + "@actions/core" "^1.2.6" 11 + "@actions/http-client" "^1.0.11" 12 + "@types/tmp" "^0.1.0" 13 + tmp "^0.1.0" 14 + tmp-promise "^2.0.2" 15 + 16 + "@actions/core@^1.2.6": 17 + version "1.2.7" 18 + resolved "https://registry.yarnpkg.com/@actions/core/-/core-1.2.7.tgz#594f8c45b213f0146e4be7eda8ae5cf4e198e5ab" 19 + integrity sha512-kzLFD5BgEvq6ubcxdgPbRKGD2Qrgya/5j+wh4LZzqT915I0V3rED+MvjH6NXghbvk1MXknpNNQ3uKjXSEN00Ig== 20 + 21 + "@actions/http-client@^1.0.11": 22 + version "1.0.11" 23 + resolved "https://registry.yarnpkg.com/@actions/http-client/-/http-client-1.0.11.tgz#c58b12e9aa8b159ee39e7dd6cbd0e91d905633c0" 24 + integrity sha512-VRYHGQV1rqnROJqdMvGUbY/Kn8vriQe/F9HR2AlYHzmKuM/p3kjNuXhmdBfcVgsvRWTz5C5XW5xvndZrVBuAYg== 25 + dependencies: 26 + tunnel "0.0.6" 27 + 5 28 "@babel/cli@^7.5.5": 6 29 version "7.13.16" 7 30 resolved "https://registry.yarnpkg.com/@babel/cli/-/cli-7.13.16.tgz#9d372e943ced0cc291f068204a9b010fd9cfadbc" ··· 2735 2758 version "1.0.7" 2736 2759 resolved "https://registry.yarnpkg.com/@types/tapable/-/tapable-1.0.7.tgz#545158342f949e8fd3bfd813224971ecddc3fac4" 2737 2760 integrity sha512-0VBprVqfgFD7Ehb2vd8Lh9TG3jP98gvr8rgehQqzztZNI7o8zS8Ad4jyZneKELphpuE212D8J70LnSNQSyO6bQ== 2761 + 2762 + "@types/tmp@^0.1.0": 2763 + version "0.1.0" 2764 + resolved "https://registry.yarnpkg.com/@types/tmp/-/tmp-0.1.0.tgz#19cf73a7bcf641965485119726397a096f0049bd" 2765 + integrity sha512-6IwZ9HzWbCq6XoQWhxLpDjuADodH/MKXRUIDFudvgjcVdjFknvmR+DNsoUeer4XPrEnrZs04Jj+kfV9pFsrhmA== 2738 2766 2739 2767 "@types/uglify-js@*": 2740 2768 version "3.13.0" ··· 8360 8388 resolved "https://registry.yarnpkg.com/iferr/-/iferr-0.1.5.tgz#c60eed69e6d8fdb6b3104a1fcbca1c192dc5b501" 8361 8389 integrity sha1-xg7taebY/bazEEofy8ocGS3FtQE= 8362 8390 8391 + ignore-walk@^3.0.3: 8392 + version "3.0.3" 8393 + resolved "https://registry.yarnpkg.com/ignore-walk/-/ignore-walk-3.0.3.tgz#017e2447184bfeade7c238e4aefdd1e8f95b1e37" 8394 + integrity sha512-m7o6xuOaT1aqheYHKf8W6J5pYH85ZI9w077erOzLje3JsB1gkafkAhHHY19dqjulgIZHFm32Cp5uNZgcQqdJKw== 8395 + dependencies: 8396 + minimatch "^3.0.4" 8397 + 8363 8398 ignore@^4.0.3, ignore@^4.0.6: 8364 8399 version "4.0.6" 8365 8400 resolved "https://registry.yarnpkg.com/ignore/-/ignore-4.0.6.tgz#750e3db5862087b4737ebac8207ffd1ef27b25fc" ··· 10883 10918 resolved "https://registry.yarnpkg.com/not/-/not-0.1.0.tgz#c9691c1746c55dcfbe54cbd8bd4ff041bc2b519d" 10884 10919 integrity sha1-yWkcF0bFXc++VMvYvU/wQbwrUZ0= 10885 10920 10921 + npm-bundled@^1.1.1: 10922 + version "1.1.2" 10923 + resolved "https://registry.yarnpkg.com/npm-bundled/-/npm-bundled-1.1.2.tgz#944c78789bd739035b70baa2ca5cc32b8d860bc1" 10924 + integrity sha512-x5DHup0SuyQcmL3s7Rx/YQ8sbw/Hzg0rj48eN0dV7hf5cmQq5PXIeioroH3raV1QC1yh3uTYuMThvEQF3iKgGQ== 10925 + dependencies: 10926 + npm-normalize-package-bin "^1.0.1" 10927 + 10886 10928 npm-conf@^1.1.0: 10887 10929 version "1.1.3" 10888 10930 resolved "https://registry.yarnpkg.com/npm-conf/-/npm-conf-1.1.3.tgz#256cc47bd0e218c259c4e9550bf413bc2192aff9" ··· 10890 10932 dependencies: 10891 10933 config-chain "^1.1.11" 10892 10934 pify "^3.0.0" 10935 + 10936 + npm-normalize-package-bin@^1.0.1: 10937 + version "1.0.1" 10938 + resolved "https://registry.yarnpkg.com/npm-normalize-package-bin/-/npm-normalize-package-bin-1.0.1.tgz#6e79a41f23fd235c0623218228da7d9c23b8f6e2" 10939 + integrity sha512-EPfafl6JL5/rU+ot6P3gRSCpPDW5VmIzX959Ob1+ySFUuuYHWHekXpwdUZcKP5C+DS4GEtdJluwBjnsNDl+fSA== 10940 + 10941 + npm-packlist@^2.1.5: 10942 + version "2.1.5" 10943 + resolved "https://registry.yarnpkg.com/npm-packlist/-/npm-packlist-2.1.5.tgz#43ef5bbb9f59b7c0ef91e0905f1dd707b4cfb33c" 10944 + integrity sha512-KCfK3Vi2F+PH1klYauoQzg81GQ8/GGjQRKYY6tRnpQUPKTs/1gBZSRWtTEd7jGdSn1LZL7gpAmJT+BcS55k2XQ== 10945 + dependencies: 10946 + glob "^7.1.6" 10947 + ignore-walk "^3.0.3" 10948 + npm-bundled "^1.1.1" 10949 + npm-normalize-package-bin "^1.0.1" 10893 10950 10894 10951 npm-run-all@^4.1.5: 10895 10952 version "4.1.5" ··· 14799 14856 inherits "^2.0.3" 14800 14857 readable-stream "^3.1.1" 14801 14858 14802 - tar@^6.0.2: 14859 + tar@^6.0.2, tar@^6.1.0: 14803 14860 version "6.1.0" 14804 14861 resolved "https://registry.yarnpkg.com/tar/-/tar-6.1.0.tgz#d1724e9bcc04b977b18d5c573b333a2207229a83" 14805 14862 integrity sha512-DUCttfhsnLCjwoDoFcI+B2iJgYa93vBnDUATYEeRx6sntCTdN01VnqsIuTlALXla/LWooNg0yEGeB+Y8WdFxGA== ··· 14989 15046 version "1.0.3" 14990 15047 resolved "https://registry.yarnpkg.com/tiny-warning/-/tiny-warning-1.0.3.tgz#94a30db453df4c643d0fd566060d60a875d84754" 14991 15048 integrity sha512-lBN9zLN/oAf68o3zNXYrdCt1kP8WsiGW8Oo2ka41b2IM5JL/S1CTyX1rW0mb/zSuJun0ZUrDxx4sqvYS2FWzPA== 15049 + 15050 + tmp-promise@^2.0.2: 15051 + version "2.1.1" 15052 + resolved "https://registry.yarnpkg.com/tmp-promise/-/tmp-promise-2.1.1.tgz#eb97c038995af74efbfe8156f5e07fdd0c935539" 15053 + integrity sha512-Z048AOz/w9b6lCbJUpevIJpRpUztENl8zdv1bmAKVHimfqRFl92ROkmT9rp7TVBnrEw2gtMTol/2Cp2S2kJa4Q== 15054 + dependencies: 15055 + tmp "0.1.0" 15056 + 15057 + tmp@0.1.0, tmp@^0.1.0: 15058 + version "0.1.0" 15059 + resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.1.0.tgz#ee434a4e22543082e294ba6201dcc6eafefa2877" 15060 + integrity sha512-J7Z2K08jbGcdA1kkQpJSqLF6T0tdQqpR2pnSUXsIchbPdTI9v3e85cLW0d6WDhwuAleOV71j2xWs8qMPfK7nKw== 15061 + dependencies: 15062 + rimraf "^2.6.3" 14992 15063 14993 15064 tmp@^0.0.33: 14994 15065 version "0.0.33" ··· 15224 15295 integrity sha1-J6XeoGs2sEoKmWZ3SykIaPD8QP0= 15225 15296 dependencies: 15226 15297 safe-buffer "^5.0.1" 15298 + 15299 + tunnel@0.0.6: 15300 + version "0.0.6" 15301 + resolved "https://registry.yarnpkg.com/tunnel/-/tunnel-0.0.6.tgz#72f1314b34a5b192db012324df2cc587ca47f92c" 15302 + integrity sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg== 15227 15303 15228 15304 tweetnacl@^0.14.3, tweetnacl@~0.14.0: 15229 15305 version "0.14.5"