| 
19 | 19 |             - name: Build TS  | 
20 | 20 |               run: npm run build  | 
21 | 21 | 
 
  | 
 | 22 | +            - name: Create tar with compilation results  | 
 | 23 | +              run: |  | 
 | 24 | +                  shopt -s globstar  | 
 | 25 | +                  tar cvzf compilation-results.tar.gz --exclude "node_modules" **/*.js **/*.js.map **/*.d.ts **/*.d.ts.map **/*.tsbuildinfo **/*.ttf  | 
 | 26 | +
  | 
 | 27 | +            - name: Upload compilation results  | 
 | 28 | +              uses: actions/upload-artifact@v2  | 
 | 29 | +              with:  | 
 | 30 | +                name: compilation-results  | 
 | 31 | +                path: compilation-results.tar.gz  | 
 | 32 | + | 
22 | 33 |     tests:  | 
23 | 34 |         runs-on: ubuntu-latest  | 
24 | 35 |         steps:  | 
 | 
35 | 46 | 
 
  | 
36 | 47 |             - name: Run tests  | 
37 | 48 |               run: npm run coverage -- --verbose  | 
 | 49 | + | 
 | 50 | +    publish:  | 
 | 51 | +        runs-on: ubuntu-latest  | 
 | 52 | +        name: Publish compilation results  | 
 | 53 | +        # Don't run this in forks. This pushes to our separate repository that external contributors don't have access to.  | 
 | 54 | +        # We also only want to publish if we have pushed a branch, not on a pull request. Otherwise we would publish everything twice.  | 
 | 55 | +        if: startsWith(github.repository, 'codeoverflow-org') && github.actor != 'dependabot[bot]' && github.event_name != 'pull_request'  | 
 | 56 | +        # Only publish anything if we're sure this version compiles (obviously) and all tests pass.  | 
 | 57 | +        needs:  | 
 | 58 | +        - build  | 
 | 59 | +        - tests  | 
 | 60 | +        steps:  | 
 | 61 | +            - uses: actions/checkout@v2  | 
 | 62 | +            - uses: actions/setup-node@v2  | 
 | 63 | +              with:  | 
 | 64 | +                node-version: "16"  | 
 | 65 | + | 
 | 66 | +            - name: Download compilation results # From the build step  | 
 | 67 | +              uses: actions/download-artifact@v2  | 
 | 68 | +              with:  | 
 | 69 | +                name: compilation-results  | 
 | 70 | + | 
 | 71 | +            - name: Extract compilation results  | 
 | 72 | +              run: tar xvf compilation-results.tar.gz  | 
 | 73 | + | 
 | 74 | +            - name: Create npm tarballs  | 
 | 75 | +              run: npm pack --workspaces  | 
 | 76 | + | 
 | 77 | +            - name: Clone publish repository  | 
 | 78 | +              uses: actions/checkout@v2  | 
 | 79 | +              with:  | 
 | 80 | +                  repository: codeoverflow-org/nodecg-io-publish  | 
 | 81 | +                  ssh-key: ${{ secrets.PUBLISH_SSH_KEY }}  | 
 | 82 | +                  path: publish  | 
 | 83 | + | 
 | 84 | +            - name: Checkout branch in publish repository  | 
 | 85 | +              working-directory: publish  | 
 | 86 | +              # Create a local branch with the same name as in the nodecg-io repository  | 
 | 87 | +              # If the branch already exists on the remote we set the upstream to it,  | 
 | 88 | +              # if not we push the branch and set the upstream to it as well.  | 
 | 89 | +              run: |  | 
 | 90 | +                  git fetch  | 
 | 91 | +                  git switch -c ${GITHUB_REF##refs/heads/}  | 
 | 92 | +                  (git branch -u origin/${GITHUB_REF##refs/heads/} && git pull) || git push -u origin ${GITHUB_REF##refs/heads/}  | 
 | 93 | +
  | 
 | 94 | +            - name: Clear publish directory  | 
 | 95 | +              run: rm -rf publish/*  | 
 | 96 | + | 
 | 97 | +            - name: Copy tarballs into publish directory  | 
 | 98 | +              run: cp *.tgz publish  | 
 | 99 | + | 
 | 100 | +            - name: Extract tarballs  | 
 | 101 | +              working-directory: publish  | 
 | 102 | +              run: |  | 
 | 103 | +                  for tarPath in $(ls *.tgz); do  | 
 | 104 | +                      tar xf $tarPath package;  | 
 | 105 | +                      dirname=$(echo "$tarPath" | sed "s/-[0-9]\+\.[0-9]\+\.[0-9]\+\.tgz//"); # Strip away tgz extension and version  | 
 | 106 | +                      mv package $dirname;  | 
 | 107 | +                  done;  | 
 | 108 | +
  | 
 | 109 | +            - name: Publish  | 
 | 110 | +              uses: stefanzweifel/git-auto-commit-action@v4  | 
 | 111 | +              with:  | 
 | 112 | +                  commit_message: Publish codeoverflow-org/nodecg-io@${{ github.sha }}  | 
 | 113 | +                  commit_user_name: codeoverflow-org  | 
 | 114 | +                  commit_user_email: ""  | 
 | 115 | +                  commit_author: codeoverflow-org <>  | 
 | 116 | +                  repository: publish  | 
0 commit comments