-
-
Notifications
You must be signed in to change notification settings - Fork 81
149 lines (124 loc) · 4.85 KB
/
Copy pathrelease.yml
File metadata and controls
149 lines (124 loc) · 4.85 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
name: Publish to npm
# When releasing for the first time, you first need to publish manually a 0.0.0
#
# npm login
# npm publish
#
# Add "repository": "posva/npm-posva", to package.json
# Go to the settings page on npm: https://www.npmjs.com/package/@pinia/colada/access
# Set the Trusted Published, add an environment if added on GitHub repository settings / Environments
# Disallow tokens
#
# Update this file:
# - use environment if set
# - Adapt the if condition that prevents running on forks
# - update PACKAGE_PATH="." if package is not at root
# - Update the MAP variable to match your packages
on:
push:
tags:
- '**' # we filter manually otherwise it doesn't work well
jobs:
release:
runs-on: ubuntu-latest
# prevent runing on forks and with other tags
if: |
(startsWith(github.ref_name, 'v') ||
contains(github.ref_name, '@')) &&
github.repository == 'posva/pinia-colada'
environment: release
permissions:
contents: write # for the GitHub Changelog
id-token: write # required for npm trusted publishing
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0 # needed for changelogithub
- name: Resolve tag info
id: resolve
run: |
echo "Resolving tag info…"
TAG="${GITHUB_REF#refs/tags/}"
echo "Current tag: $TAG"
echo "TAG=$TAG" >> $GITHUB_OUTPUT
# ========= Determine package type =========
if [[ "$TAG" =~ ^v[0-9] ]]; then
# Main package
PKG_NAME="<main>"
PACKAGE_PATH="."
GIT_DESCRIBE_MATCH="v*"
else
# Scoped package: extract prefix before last @
PKG_NAME="${TAG%@*}"
GIT_DESCRIBE_MATCH="${PKG_NAME}@*"
# Package folder mapping
declare -A MAP=(
["@pinia/colada-devtools"]="devtools"
["@pinia/colada-nuxt"]="nuxt"
["@pinia/colada-plugin-retry"]="plugins/retry"
["@pinia/colada-plugin-delay"]="plugins/delay"
["@pinia/colada-plugin-debug"]="plugins/debug"
["@pinia/colada-plugin-cache-persister"]="plugins/cache-persister"
["@pinia/colada-plugin-auto-refetch"]="plugins/auto-refetch"
["@pinia/colada-plugin-tanstack-compat"]="plugins/tanstack-compat"
)
if [[ -z "${MAP[$PKG_NAME]}" ]]; then
echo "❌ Unknown package name '$PKG_NAME'" >&2
exit 1
fi
PACKAGE_PATH="${MAP[$PKG_NAME]}"
fi
echo "PKG_NAME=$PKG_NAME" >> $GITHUB_OUTPUT
echo "PACKAGE_PATH=$PACKAGE_PATH" >> $GITHUB_OUTPUT
echo "GIT_DESCRIBE_MATCH=$GIT_DESCRIBE_MATCH" >> $GITHUB_OUTPUT
# ========= Compute previous tag (skip current tag) =========
echo "Finding previous tag using: git describe --match '$GIT_DESCRIBE_MATCH'"
set +e
PREVIOUS_TAG=$(git describe --tags --abbrev=0 --match "$GIT_DESCRIBE_MATCH" "${TAG}^" 2>/dev/null)
STATUS=$?
set -e
if [[ $STATUS -eq 0 ]]; then
echo "Found previous tag: $PREVIOUS_TAG"
else
echo "No previous tag found. Using first commit."
PREVIOUS_TAG=$(git rev-list --max-parents=0 HEAD)
fi
echo "PREVIOUS_TAG=$PREVIOUS_TAG" >> $GITHUB_OUTPUT
echo "Resolved:"
echo " TAG=$TAG"
echo " PKG_NAME=$PKG_NAME"
echo " PACKAGE_PATH=$PACKAGE_PATH"
echo " PREVIOUS_TAG=$PREVIOUS_TAG"
- name: Install pnpm
uses: pnpm/action-setup@v4
- name: Setup node
uses: actions/setup-node@v6
with:
node-version: lts/*
cache: pnpm
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
shell: bash
run: pnpm install --frozen-lockfile
- name: Copy root README for main package
if: ${{ steps.resolve.outputs.PKG_NAME == '<main>' && steps.resolve.outputs.PACKAGE_PATH != '.' }}
run: |
echo "Copying README.md to ${{ steps.resolve.outputs.PACKAGE_PATH }}"
cp README.md "${{ steps.resolve.outputs.PACKAGE_PATH }}/README.md"
- name: Build
# handle nuxt prebuild
run: |
pnpm run --if-present dev:prepare
pnpm build
working-directory: ${{ steps.resolve.outputs.PACKAGE_PATH }}
- name: Publish to NPM
run: pnpm publish --access public --no-git-checks
working-directory: ${{ steps.resolve.outputs.PACKAGE_PATH }}
- name: Generate GitHub Changelog
run: pnpx changelogithub --from "$FROM_TAG" --to "$TAG"
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ steps.resolve.outputs.TAG }}
FROM_TAG: ${{ steps.resolve.PREVIOUS_TAG }}