-
-
Notifications
You must be signed in to change notification settings - Fork 0
99 lines (97 loc) · 2.98 KB
/
publish.yml
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
name: Publish package
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+*' # tag pattern on pub.dev: 'v'
defaults:
run:
shell: bash
env:
PUB_ENVIRONMENT: bot.github
permissions: read-all
jobs:
test:
uses: ./.github/workflows/test.yml
publish:
needs: test
name: "Publish"
permissions:
id-token: write
runs-on: ubuntu-latest
environment: pub.dev
steps:
- uses: dart-lang/setup-dart@v1
with:
sdk: stable
- id: checkout
uses: actions/checkout@v4
- name: Compare version with ref/tag
id: compare_version_with_tag
run: |
set -e
VERSION=$(awk '/^version: / {print $2}' pubspec.yaml)
TAG=${GITHUB_REF_NAME#v}
if [[ "$VERSION" != "$TAG" ]]; then
echo "Version in pubspec.yaml ($VERSION) does not match tag ($TAG)"
exit 1
fi
- name: Check CHANGELOG.md
id: check_changelog
run: |
set -e
if ! grep -q "## $VERSION" CHANGELOG.md; then
echo "CHANGELOG.md does not contain a section for $VERSION"
exit 1
fi
- name: Validate pub.dev topics
id: validate_pub_dev_topics
run: |
set -e
pattern="^[a-z][a-z0-9-]*[a-z0-9]$"
for topic in $(yq -r '.topics[]' pubspec.yaml); do
if [[ ! $topic =~ $pattern ]]; then
echo "Invalid topic: $topic"
exit 1
fi
done
- name: Install dependencies
run: dart pub get
- name: Publish
id: publish
run: dart pub publish --force
release:
needs: [ test, publish ]
name: "Release"
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Get version from pubspec.yaml
id: get_version_and_name
run: |
set -e
VERSION=$(awk '/^version: / {print $2}' pubspec.yaml)
NAME=$(awk '/^name: / {print $2}' pubspec.yaml)
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "NAME=$NAME" >> $GITHUB_ENV
- name: Create tag-specific CHANGELOG
id: create_changelog
run: |
set -e
CHANGELOG_PATH=$RUNNER_TEMP/CHANGELOG.md
awk '/^##[[:space:]].*/ { if (count == 1) exit; count++; print } count == 1 && !/^##[[:space:]].*/ { print }' CHANGELOG.md | sed -e :a -e '/^\n*$/{$d;N;ba' -e '}' > $CHANGELOG_PATH
echo -en "\n[https://pub.dev/packages/$NAME/versions/$VERSION](https://pub.dev/packages/$NAME/versions/$VERSION)" >> $CHANGELOG_PATH
echo "CHANGELOG_PATH=$CHANGELOG_PATH" >> $GITHUB_ENV
- name: Create release
id: create_release
uses: softprops/action-gh-release@v2
with:
name: ${{ env.VERSION }}
tag_name: v${{ env.VERSION }}
body_path: ${{ env.CHANGELOG_PATH }}
- name: Clean up
id: clean_up
if: ${{ always() }}
run: |
rm -rf $CHANGELOG_PATH