-
Notifications
You must be signed in to change notification settings - Fork 39
102 lines (92 loc) · 3.37 KB
/
snapshot.yml
File metadata and controls
102 lines (92 loc) · 3.37 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
name: Snapshot
permissions:
contents: read
on:
workflow_call:
inputs:
snapshot-tag:
description: 'Optional custom snapshot tag. If not provided, uses branch name'
required: false
type: string
outputs:
snapshot-tag:
description: 'The snapshot tag that was published'
value: ${{ jobs.snapshot.outputs.snapshot-tag }}
workflow_dispatch:
inputs:
snapshot-tag:
description: 'Optional custom snapshot tag. If not provided, uses branch name'
required: false
type: string
jobs:
snapshot:
name: Release snapshot version
permissions:
contents: write
id-token: write
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
snapshot-tag: ${{ steps.get-snapshot-tag.outputs.tag }}
steps:
- name: Clone repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup
uses: ./.github/actions/setup
- name: Publish Initial Versions for New Packages
continue-on-error: false
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
YARN_NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
npm config set "//registry.npmjs.org/:_authToken" "$NPM_TOKEN"
node .github/scripts/publish-initial-versions.js
- name: Determine Snapshot Tag
id: determine-tag
run: |
if [ -n "${{ inputs.snapshot-tag }}" ]; then
echo "tag=${{ inputs.snapshot-tag }}" >> $GITHUB_OUTPUT
else
snapshot=$(git branch --show-current | tr -cs '[:alnum:]-' '-' | tr '[:upper:]' '[:lower:]' | sed 's/-$//' | sed 's/^-//')
# Validate it's not empty
if [ -z "$snapshot" ]; then
echo "::error::Invalid branch name for snapshot tag"
exit 1
fi
echo "tag=$snapshot" >> $GITHUB_OUTPUT
fi
- name: Check for Changesets
id: check-changesets
run: |
# Check if any changeset files exist (excluding README.md)
changeset_count=$(find .changeset -name "*.md" ! -name "README.md" | wc -l)
if [ "$changeset_count" -eq 0 ]; then
echo "has_changesets=false" >> $GITHUB_OUTPUT
echo "::warning::No changesets found. Skipping snapshot release."
exit 1
else
echo "has_changesets=true" >> $GITHUB_OUTPUT
echo "Found $changeset_count changeset(s). Proceeding with snapshot release."
fi
- name: Publish Snapshots
if: steps.check-changesets.outputs.has_changesets == 'true'
continue-on-error: false
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
snapshot="${{ steps.determine-tag.outputs.tag }}"
npm config set "//registry.npmjs.org/:_authToken" "$NPM_TOKEN"
yarn run changeset version --no-git-tag --snapshot $snapshot
yarn run changeset:prepublish:ci
yarn run changeset publish --no-git-tag --snapshot $snapshot --tag $snapshot
- name: Get Snapshot Tag
id: get-snapshot-tag
run: |
if [ "${{ steps.check-changesets.outputs.has_changesets }}" == "true" ]; then
echo "tag=${{ steps.determine-tag.outputs.tag }}" >> $GITHUB_OUTPUT
else
echo "tag=" >> $GITHUB_OUTPUT
fi