Skip to content

Commit ce16661

Browse files
authored
Merge pull request #3 from codex-team/ci2
Extract publish job into reusable workflow
2 parents 5a73919 + bda0630 commit ce16661

2 files changed

Lines changed: 85 additions & 43 deletions

File tree

.github/workflows/main.yml

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -29,46 +29,3 @@ jobs:
2929

3030
- name: Build
3131
run: yarn build
32-
33-
publish:
34-
needs: check-lint-test-build
35-
if: github.ref == 'refs/heads/main'
36-
runs-on: ubuntu-22.04
37-
steps:
38-
- name: Checkout repository
39-
uses: actions/checkout@v4
40-
41-
- name: Setup Node.js
42-
uses: actions/setup-node@v4
43-
with:
44-
node-version-file: .nvmrc
45-
registry-url: 'https://registry.npmjs.org'
46-
scope: '@hawk.so'
47-
48-
- name: Enable Corepack and install dependencies
49-
run: |
50-
corepack enable
51-
corepack prepare yarn@4.5.1 --activate
52-
yarn install
53-
54-
- name: Build
55-
run: yarn build
56-
57-
- name: Publish
58-
run: |
59-
yarn workspace @hawk.so/utils exec npm publish --access public
60-
yarn workspace @hawk.so/github-sdk exec npm publish --access public
61-
env:
62-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
63-
64-
- name: Get package info
65-
id: package
66-
uses: codex-team/action-nodejs-package-info@v1
67-
68-
- name: Send a message
69-
uses: codex-team/action-codexbot-notify@v1
70-
with:
71-
webhook: ${{ secrets.CODEX_BOT_WEBHOOK_HAWK }}
72-
message: '📦 [${{ steps.package.outputs.name }}](${{ steps.package.outputs.npmjs-link }}) ${{ steps.package.outputs.version }} was published'
73-
parse_mode: 'markdown'
74-
disable_web_page_preview: true

.github/workflows/publish.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Publish
2+
3+
on:
4+
workflow_run:
5+
workflows: [CI]
6+
types: [completed]
7+
branches: [main]
8+
9+
jobs:
10+
publish:
11+
if: github.event.workflow_run.conclusion == 'success'
12+
runs-on: ubuntu-22.04
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v6
16+
with:
17+
ref: ${{ github.event.workflow_run.head_sha }}
18+
fetch-depth: 0
19+
20+
- name: Detect changed packages
21+
id: changes
22+
uses: dorny/paths-filter@v3
23+
with:
24+
base: HEAD^
25+
filters: |
26+
utils:
27+
- 'packages/utils/**'
28+
github:
29+
- 'packages/github/**'
30+
31+
- name: Setup Node.js
32+
uses: actions/setup-node@v6
33+
with:
34+
node-version-file: .nvmrc
35+
registry-url: 'https://registry.npmjs.org'
36+
scope: '@hawk.so'
37+
38+
- name: Enable Corepack and install dependencies
39+
run: |
40+
corepack enable
41+
corepack prepare yarn@4.5.1 --activate
42+
yarn install
43+
44+
- name: Build
45+
run: yarn build
46+
47+
- name: Publish
48+
run: |
49+
if [ "${{ steps.changes.outputs.utils }}" == "true" ]; then
50+
yarn workspace @hawk.so/utils exec npm publish --access public
51+
fi
52+
if [ "${{ steps.changes.outputs.github }}" == "true" ]; then
53+
yarn workspace @hawk.so/github-sdk exec npm publish --access public
54+
fi
55+
env:
56+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
57+
58+
- name: Get published package versions
59+
if: steps.changes.outputs.utils == 'true' || steps.changes.outputs.github == 'true'
60+
id: versions
61+
run: |
62+
if [ "${{ steps.changes.outputs.utils }}" == "true" ]; then
63+
echo "utils_version=$(node -p "require('./packages/utils/package.json').version")" >> $GITHUB_OUTPUT
64+
fi
65+
if [ "${{ steps.changes.outputs.github }}" == "true" ]; then
66+
echo "github_version=$(node -p "require('./packages/github/package.json').version")" >> $GITHUB_OUTPUT
67+
fi
68+
69+
- name: Notify @hawk.so/utils published
70+
if: steps.changes.outputs.utils == 'true'
71+
uses: codex-team/action-codexbot-notify@v1
72+
with:
73+
webhook: ${{ secrets.CODEX_BOT_WEBHOOK_HAWK }}
74+
message: '📦 [@hawk.so/utils](https://www.npmjs.com/package/@hawk.so/utils) ${{ steps.versions.outputs.utils_version }} was published'
75+
parse_mode: 'markdown'
76+
disable_web_page_preview: true
77+
78+
- name: Notify @hawk.so/github-sdk published
79+
if: steps.changes.outputs.github == 'true'
80+
uses: codex-team/action-codexbot-notify@v1
81+
with:
82+
webhook: ${{ secrets.CODEX_BOT_WEBHOOK_HAWK }}
83+
message: '📦 [@hawk.so/github-sdk](https://www.npmjs.com/package/@hawk.so/github-sdk) ${{ steps.versions.outputs.github_version }} was published'
84+
parse_mode: 'markdown'
85+
disable_web_page_preview: true

0 commit comments

Comments
 (0)