-
Notifications
You must be signed in to change notification settings - Fork 2
133 lines (129 loc) · 4.86 KB
/
release.yml
File metadata and controls
133 lines (129 loc) · 4.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
name: Release
on:
workflow_run:
workflows: ["Check"]
branches: [main]
types: [completed]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
permissions: {}
jobs:
release:
name: Release
runs-on: ubuntu-latest
timeout-minutes: 10
if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push' && github.event.workflow_run.head_branch == 'main'
permissions:
contents: write
id-token: write
pull-requests: write
packages: write
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
ref: ${{ github.event.workflow_run.head_sha }}
- name: Install dependencies
uses: ./.github/actions/setup
- name: Auto changeset (patch if no changeset exists)
id: auto_changeset
if: github.actor != 'github-actions[bot]'
shell: bash
run: |
set -euo pipefail
if ls .changeset/*.md >/dev/null 2>&1; then
echo "has_changeset=true" >> "$GITHUB_OUTPUT"
exit 0
fi
CHANGESET_FILE=".changeset/auto-${{ github.sha }}.md"
printf '%s\n' \
'---' \
'"@prover-coder-ai/context-doc": patch' \
'---' \
'' \
'chore: automated version bump' \
> "$CHANGESET_FILE"
echo "has_changeset=true" >> "$GITHUB_OUTPUT"
- name: Detect npm token
id: npm_token
if: steps.auto_changeset.outputs.has_changeset == 'true' && github.actor != 'github-actions[bot]'
shell: bash
run: |
set -euo pipefail
if [ -n "${NPM_TOKEN:-}" ]; then
echo "available=true" >> "$GITHUB_OUTPUT"
else
echo "available=false" >> "$GITHUB_OUTPUT"
fi
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Version packages
if: steps.auto_changeset.outputs.has_changeset == 'true' && github.actor != 'github-actions[bot]'
run: pnpm changeset version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Read version
id: release_version
if: steps.auto_changeset.outputs.has_changeset == 'true' && github.actor != 'github-actions[bot]'
shell: bash
run: |
set -euo pipefail
VERSION="$(node -p "require('./packages/app/package.json').version")"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Commit version changes
if: steps.auto_changeset.outputs.has_changeset == 'true' && github.actor != 'github-actions[bot]'
shell: bash
run: |
set -euo pipefail
if git diff --quiet; then
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add -A
git commit -m "chore(release): version packages"
BRANCH="${{ github.event.workflow_run.head_branch }}"
if [ -z "${BRANCH}" ]; then
BRANCH="main"
fi
git push origin "HEAD:${BRANCH}"
- name: Tag release
if: steps.auto_changeset.outputs.has_changeset == 'true' && github.actor != 'github-actions[bot]'
shell: bash
run: |
set -euo pipefail
VERSION="${{ steps.release_version.outputs.version }}"
TAG="v${VERSION}"
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "Tag $TAG already exists"
exit 0
fi
git tag -a "$TAG" -m "$TAG"
git push origin "$TAG"
- name: Configure npm auth
if: steps.auto_changeset.outputs.has_changeset == 'true' && github.actor != 'github-actions[bot]' && steps.npm_token.outputs.available == 'true'
shell: bash
run: |
set -euo pipefail
printf '%s\n' "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > "$HOME/.npmrc"
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish
if: steps.auto_changeset.outputs.has_changeset == 'true' && github.actor != 'github-actions[bot]' && steps.npm_token.outputs.available == 'true'
shell: bash
run: |
set -euo pipefail
VERSION="$(node -p "require('./packages/app/package.json').version")"
if npm view @prover-coder-ai/context-doc@"${VERSION}" version >/dev/null 2>&1; then
echo "Version ${VERSION} already published; skipping npm publish."
exit 0
fi
pnpm changeset-publish
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Create GitHub Release
if: steps.auto_changeset.outputs.has_changeset == 'true' && github.actor != 'github-actions[bot]'
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ steps.release_version.outputs.version }}
generate_release_notes: true