development
yml 129 lines 3.91 KB
Raw
1 name: pub.dev Release
2
3 on:
4 workflow_dispatch:
5 inputs:
6 tag:
7 description: "Release tag (e.g. v0.4.0)"
8 required: true
9
10 permissions:
11 contents: read
12
13 env:
14 CARGO_TERM_COLOR: always
15 PUB_PACKAGE_NAME: onde_cli
16
17 jobs:
18 verify-package:
19 name: Verify Dart package
20 runs-on: ubuntu-latest
21 steps:
22 - name: Checkout
23 uses: actions/checkout@v6
24 with:
25 ref: ${{ github.event.inputs.tag || github.ref }}
26
27 - name: Set the release version
28 shell: bash
29 run: |
30 if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
31 release_version="${GITHUB_REF_NAME#v}"
32 else
33 release_version="${{ github.event.inputs.tag }}"
34 release_version="${release_version#v}"
35 fi
36 echo "RELEASE_VERSION=${release_version}" >> "$GITHUB_ENV"
37
38 - name: Setup Dart SDK
39 uses: dart-lang/setup-dart@v1
40
41 - name: Sync package version
42 shell: bash
43 run: |
44 python3 - <<'PY'
45 from pathlib import Path
46 import os
47 release_version = os.environ['RELEASE_VERSION']
48 pubspec = Path('pub/onde_cli/pubspec.yaml')
49 lines = pubspec.read_text().splitlines()
50 for index, line in enumerate(lines):
51 if line.startswith('version: '):
52 lines[index] = f'version: {release_version}'
53 pubspec.write_text('\n'.join(lines) + '\n')
54 PY
55
56 - name: Get package dependencies
57 working-directory: pub/onde_cli
58 run: dart pub get
59
60 - name: Analyze Dart package
61 working-directory: pub/onde_cli
62 run: dart analyze
63
64 - name: Dry-run publish
65 working-directory: pub/onde_cli
66 run: dart pub publish --dry-run
67
68 publish-pub:
69 name: Publish to pub.dev
70 runs-on: ubuntu-latest
71 needs: verify-package
72 steps:
73 - name: Checkout
74 uses: actions/checkout@v6
75 with:
76 ref: ${{ github.event.inputs.tag || github.ref }}
77
78 - name: Set the release version
79 shell: bash
80 run: |
81 if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
82 release_version="${GITHUB_REF_NAME#v}"
83 else
84 release_version="${{ github.event.inputs.tag }}"
85 release_version="${release_version#v}"
86 fi
87 echo "RELEASE_VERSION=${release_version}" >> "$GITHUB_ENV"
88
89 - name: Setup Dart SDK
90 uses: dart-lang/setup-dart@v1
91
92 - name: Sync package version
93 shell: bash
94 run: |
95 python3 - <<'PY'
96 from pathlib import Path
97 import os
98 release_version = os.environ['RELEASE_VERSION']
99 pubspec = Path('pub/onde_cli/pubspec.yaml')
100 lines = pubspec.read_text().splitlines()
101 for index, line in enumerate(lines):
102 if line.startswith('version: '):
103 lines[index] = f'version: {release_version}'
104 pubspec.write_text('\n'.join(lines) + '\n')
105 PY
106
107 - name: Check whether release already exists on pub.dev
108 id: pub-check
109 shell: bash
110 run: |
111 package_url="https://pub.dev/api/packages/${PUB_PACKAGE_NAME}"
112 if curl -fsS "${package_url}" | grep -F '"version":"'"${RELEASE_VERSION}"'"' >/dev/null; then
113 echo "${PUB_PACKAGE_NAME} ${RELEASE_VERSION} already exists on pub.dev, skipping publish"
114 echo "exists=true" >> "$GITHUB_OUTPUT"
115 else
116 echo "exists=false" >> "$GITHUB_OUTPUT"
117 fi
118
119 - name: Set up pub.dev credentials
120 if: steps.pub-check.outputs.exists != 'true'
121 shell: bash
122 run: |
123 mkdir -p "${XDG_CONFIG_HOME:-$HOME/.config}/dart"
124 echo '${{ secrets.PUB_CREDENTIALS }}' > "${XDG_CONFIG_HOME:-$HOME/.config}/dart/pub-credentials.json"
125
126 - name: Publish package
127 if: steps.pub-check.outputs.exists != 'true'
128 working-directory: pub/onde_cli
129 run: dart pub publish --force