Repository navigation
119 lines (103 loc) · 3.87 KB
/
Copy pathrelease.yml
File metadata and controls
119 lines (103 loc) · 3.87 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
name: Release
on:
push:
branches: [ main ]
workflow_call:
workflow_dispatch:
permissions:
contents: write
actions: read
jobs:
test-and-lint:
uses: ./.github/workflows/test-and-lint.yml
create-release:
needs: test-and-lint
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get_version.outputs.version }}
version_changed: ${{ steps.check_version.outputs.version_changed }}
tag_exists: ${{ steps.check_tag.outputs.tag_exists }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Get current version
id: get_version
run: |
CURRENT_VERSION=$(grep "^version = " Cargo.toml | cut -d'"' -f2)
echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "tag=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "Current version: $CURRENT_VERSION"
- name: Setup Node.js for version sync
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Check if version changed
id: check_version
run: |
CURRENT_VERSION="${{ steps.get_version.outputs.version }}"
# Get the previous version from the last commit
PREVIOUS_VERSION=$(git show HEAD~1:Cargo.toml | grep "^version = " | cut -d'"' -f2 2>/dev/null || echo "")
echo "Previous version: $PREVIOUS_VERSION"
echo "Current version: $CURRENT_VERSION"
if [ -n "$CURRENT_VERSION" ] && [ -n "$PREVIOUS_VERSION" ] && [ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ]; then
echo "version_changed=true" >> $GITHUB_OUTPUT
echo "Version changed from $PREVIOUS_VERSION to $CURRENT_VERSION"
else
echo "version_changed=false" >> $GITHUB_OUTPUT
echo "Version unchanged: $CURRENT_VERSION"
fi
- name: Check version consistency
if: steps.check_version.outputs.version_changed == 'true'
run: |
node scripts/sync-versions.js check
- name: Check if tag exists
id: check_tag
if: steps.check_version.outputs.version_changed == 'true'
run: |
TAG="${{ steps.get_version.outputs.version }}"
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "tag_exists=true" >> $GITHUB_OUTPUT
echo "Tag $TAG already exists"
else
echo "tag_exists=false" >> $GITHUB_OUTPUT
echo "Tag $TAG does not exist"
fi
- name: Create GitHub Release
if: steps.check_version.outputs.version_changed == 'true' && steps.check_tag.outputs.tag_exists == 'false'
id: create_release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.get_version.outputs.version }}
name: ${{ steps.get_version.outputs.version }}
generate_release_notes: true
draft: true
prerelease: false
make_latest: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish Release
if: steps.check_version.outputs.version_changed == 'true' && steps.check_tag.outputs.tag_exists == 'false'
run: |
TAG="${{ steps.get_version.outputs.version }}"
gh release edit "$TAG" --draft=false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish-to-cratesio:
needs: create-release
if: needs.create-release.outputs.version_changed == 'true' && needs.create-release.outputs.tag_exists == 'false'
uses: ./.github/workflows/publish-to-cratesio.yml
with:
version: ${{ needs.create-release.outputs.version }}
dry_run: false
secrets: inherit
publish-to-npm:
needs: create-release
if: needs.create-release.outputs.version_changed == 'true' && needs.create-release.outputs.tag_exists == 'false'
uses: ./.github/workflows/publish-to-npm.yml
with:
version: ${{ needs.create-release.outputs.version }}
dry_run: false
secrets: inherit