Skip to content
This repository was archived by the owner on Apr 13, 2025. It is now read-only.

Commit 5a6e034

Browse files
authored
Publish tarballs and compilation results on push (#328)
* Publish tarballs and compilation results on push * Don't execute publish step if CI was triggered by a PR
1 parent 1d7f18e commit 5a6e034

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

.github/workflows/ci.yml

+79
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ jobs:
1919
- name: Build TS
2020
run: npm run build
2121

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+
2233
tests:
2334
runs-on: ubuntu-latest
2435
steps:
@@ -35,3 +46,71 @@ jobs:
3546

3647
- name: Run tests
3748
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

Comments
 (0)