-
Notifications
You must be signed in to change notification settings - Fork 1
159 lines (128 loc) · 3.99 KB
/
publish.yaml
File metadata and controls
159 lines (128 loc) · 3.99 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
150
151
152
153
154
155
156
157
158
159
name: Publish to pub.dev
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
jobs:
prechecks:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Check tag format
run: |
if [[ ! "${GITHUB_REF}" =~ ^refs/tags/v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Tag ${GITHUB_REF} does not match required format vX.Y.Z"
exit 1
fi
- name: Check main branch
run: |
git fetch origin main
if ! git merge-base --is-ancestor ${GITHUB_SHA} origin/main; then
echo "Tag ${GITHUB_REF} is not based on the latest main branch"
exit 1
fi
deploy-dart:
needs: prechecks
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup Flutter
uses: flutter-actions/setup-flutter@v4
with:
channel: stable
version: 3.38.8
cache: true
cache-sdk: true
cache-key: ${{ runner.os }}-flutter-${{ hashFiles('pubspec.yaml') }}
- name: Install dependencies
run: flutter pub get
- name: Run checks
run: flutter analyze
- name: Dry run
run: flutter pub publish --dry-run
- name: Publish to pub.dev
uses: dart-lang/setup-dart@v1
with:
sdk: stable
- name: Publish to pub.dev
run: flutter pub publish --force
- name: Rename tag when fails
if: failure()
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
TAG_NAME=${GITHUB_REF#refs/tags/}
NEW_TAG="failed-${TAG_NAME}-${TIMESTAMP}"
git tag $NEW_TAG
git push origin $NEW_TAG
git push --delete origin $TAG_NAME
create-release:
runs-on: ubuntu-latest
needs: deploy-dart
if: success()
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Get previous tag
id: previousTag
run: |
name=$(git --no-pager tag --sort=creatordate --merged ${{ github.ref_name }} | tail -2 | head -1)
echo "previousTag=$name" >> $GITHUB_OUTPUT
- name: Generate Changelog
id: changelog
uses: requarks/changelog-action@v1
with:
token: ${{ github.token }}
fromTag: ${{ github.ref_name }}
toTag: ${{ steps.previousTag.outputs.previousTag }}
writeToFile: false
excludeTypes: chore,style
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ github.ref_name }}
name: Release ${{ github.ref_name }}
body: ${{ steps.changelog.outputs.changes }}
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build-site:
runs-on: ubuntu-latest
needs: deploy-dart
permissions:
pages: write
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup Flutter
uses: flutter-actions/setup-flutter@v4
with:
channel: stable
version: 3.38.8
cache: true
cache-sdk: true
cache-key: ${{ runner.os }}-flutter-${{ hashFiles('pubspec.yaml') }}
- name: Setup Pages
id: setup_pages
uses: actions/configure-pages@v5
- name: Build
run: |
cd example
flutter build web --release --base-href=${{ steps.setup_pages.outputs.base_path }}/ --no-tree-shake-icons --wasm
- name: Upload artifact
uses: actions/upload-pages-artifact@v4
with:
path: './example/build/web'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4