|
| 1 | +name: Publish NPM packages |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - 'UE*' |
| 8 | + paths: |
| 9 | + - '**/package.json' |
| 10 | + |
| 11 | +concurrency: ${{ github.workflow }}-${{ github.ref }} |
| 12 | + |
| 13 | +jobs: |
| 14 | + # gets all publishable npm packages. |
| 15 | + fetch-package-info: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + outputs: |
| 18 | + matrix: ${{ steps.query-packages.outputs.matrix }} |
| 19 | + steps: |
| 20 | + - name: Checkout Repo |
| 21 | + uses: actions/checkout@v3 |
| 22 | + |
| 23 | + - name: Get package info |
| 24 | + id: query-packages |
| 25 | + run: | |
| 26 | + # get all publishable npm packages |
| 27 | + public_packages=$(jq -r '.workspaces[]' package.json | xargs -I {} jq -c --arg path "{}" ' select(.private != true) | { path: $path, name: .name, version: .version }' {}/package.json) |
| 28 | + to_publish=() |
| 29 | + # filter out packages with older or matching versions to the published version |
| 30 | + for row in $public_packages; do |
| 31 | + package_name=$(echo $row | jq -r '.name') |
| 32 | + package_short_name=${package_name#@epicgames-ps/} |
| 33 | + package_version=$(echo $row | jq -r '.version') |
| 34 | + package_published=$(npm show "$package_name" version 2>/dev/null || echo "0.0.0") |
| 35 | + if [ "$(printf "%s\n%s" "$package_published" "$package_version" | sort -V | tail -n1)" = "$package_version" ] && [ "$package_version" != "$package_published" ]; then |
| 36 | + to_publish+=($(echo $row | jq -c ". + { \"tag\": \"${package_short_name}\" }")) |
| 37 | + fi |
| 38 | + done |
| 39 | + # change the list into a json list |
| 40 | + publish_json_list=[$(IFS=,; echo "${to_publish[*]}")] |
| 41 | + echo "matrix=$publish_json_list" >> $GITHUB_OUTPUT |
| 42 | +
|
| 43 | +
|
| 44 | + # actually publishes the npm package. |
| 45 | + publish: |
| 46 | + runs-on: ubuntu-latest |
| 47 | + needs: fetch-package-info |
| 48 | + permissions: |
| 49 | + contents: write |
| 50 | + strategy: |
| 51 | + max-parallel: 1 |
| 52 | + matrix: |
| 53 | + package: ${{ fromJson(needs.fetch-package-info.outputs.matrix) }} |
| 54 | + steps: |
| 55 | + - name: Checkout Repo |
| 56 | + uses: actions/checkout@v3 |
| 57 | + |
| 58 | + - name: Get node version |
| 59 | + id: get_node_version |
| 60 | + run: echo "node_version=$(cat NODE_VERSION)" >> $GITHUB_OUTPUT |
| 61 | + |
| 62 | + - name: Setup node |
| 63 | + uses: actions/setup-node@v4 |
| 64 | + with: |
| 65 | + node-version: "${{ steps.get_node_version.outputs.node_version }}" |
| 66 | + registry-url: 'https://registry.npmjs.org' |
| 67 | + |
| 68 | + - name: Publish ${{ matrix.package.name }} |
| 69 | + working-directory: ${{ matrix.package.path }} |
| 70 | + env: |
| 71 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 72 | + run: | |
| 73 | + npm install |
| 74 | + npm build |
| 75 | + npm publish --access public |
| 76 | +
|
| 77 | + - name: Build the version label |
| 78 | + id: build-label |
| 79 | + run: echo "label=${{ matrix.package.tag }}-${{ matrix.package.version }}" >> $GITHUB_OUTPUT |
| 80 | + |
| 81 | + - name: Create release tag |
| 82 | + uses: actions/github-script@v5 |
| 83 | + with: |
| 84 | + script: | |
| 85 | + github.rest.git.createRef({ |
| 86 | + owner: context.repo.owner, |
| 87 | + repo: context.repo.repo, |
| 88 | + ref: 'refs/tags/${{ steps.build-label.outputs.label }}', |
| 89 | + sha: context.sha |
| 90 | + }) |
| 91 | +
|
| 92 | + - name: Split up the archive paths so the path in the archives is nice. |
| 93 | + id: split-paths |
| 94 | + run: | |
| 95 | + echo "basename=$(basename ${{ matrix.package.path }})" >> $GITHUB_OUTPUT |
| 96 | + echo "dirname=$(dirname ${{ matrix.package.path }})" >> $GITHUB_OUTPUT |
| 97 | +
|
| 98 | + - name: Archive Release tar.gz |
| 99 | + uses: thedoctor0/zip-release@0.7.1 |
| 100 | + with: |
| 101 | + directory: ${{ steps.split-paths.outputs.dirname }} |
| 102 | + path: ${{ steps.split-paths.outputs.basename }} |
| 103 | + type: 'tar' |
| 104 | + filename: '${{ steps.build-label.outputs.label }}.tar.gz' |
| 105 | + exclusions: >- |
| 106 | + node_modules |
| 107 | +
|
| 108 | + - name: Archive Release zip |
| 109 | + uses: thedoctor0/zip-release@0.7.1 |
| 110 | + with: |
| 111 | + directory: ${{ steps.split-paths.outputs.dirname }} |
| 112 | + path: ${{ steps.split-paths.outputs.basename }} |
| 113 | + type: 'zip' |
| 114 | + filename: '${{ steps.build-label.outputs.label }}.zip' |
| 115 | + exclusions: >- |
| 116 | + /${{ steps.split-paths.outputs.basename }}/node_modules/* |
| 117 | +
|
| 118 | + - name: Make the release |
| 119 | + uses: ncipollo/release-action@v1 |
| 120 | + with: |
| 121 | + tag: "${{ steps.build-label.outputs.label }}" |
| 122 | + artifacts: > |
| 123 | + ${{ steps.split-paths.outputs.dirname }}/${{ steps.build-label.outputs.label }}.zip, |
| 124 | + ${{ steps.split-paths.outputs.dirname }}/${{ steps.build-label.outputs.label }}.tar.gz |
| 125 | + bodyFile: ${{ matrix.package.path }}/CHANGELOG.md |
| 126 | + |
0 commit comments