-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
193 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
name: Publish package (dry run) | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
defaults: | ||
run: | ||
shell: bash | ||
env: | ||
PUB_ENVIRONMENT: bot.github | ||
permissions: read-all | ||
|
||
jobs: | ||
get_base_version: | ||
name: "Get base version" | ||
runs-on: ubuntu-latest | ||
outputs: | ||
BASE_VERSION: ${{ steps.load_base_version.outputs.BASE_VERSION }} | ||
steps: | ||
- uses: actions/cache@v4 | ||
with: | ||
path: "~/.pub-cache/hosted" | ||
key: "os:ubuntu-latest;pub-cache-hosted;sdk:stable;packages:qs_dart;commands:get_base_version" | ||
restore-keys: | | ||
os:ubuntu-latest;pub-cache-hosted;sdk:stable;packages:qs_dart | ||
os:ubuntu-latest;pub-cache-hosted;sdk:stable | ||
os:ubuntu-latest;pub-cache-hosted | ||
os:ubuntu-latest | ||
- uses: dart-lang/setup-dart@v1 | ||
with: | ||
sdk: stable | ||
- id: checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.event.pull_request.base.ref }} | ||
- name: Load base version | ||
id: load_base_version | ||
run: | | ||
set -e | ||
echo "BASE_VERSION=$(awk '/^version: / {print $2}' pubspec.yaml)" >> $GITHUB_OUTPUT | ||
publish_dry_run: | ||
name: "Publish DRY RUN" | ||
needs: get_base_version | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/cache@v4 | ||
with: | ||
path: "~/.pub-cache/hosted" | ||
key: "os:ubuntu-latest;pub-cache-hosted;sdk:stable;packages:qs_dart;commands:get_base_version" | ||
restore-keys: | | ||
os:ubuntu-latest;pub-cache-hosted;sdk:stable;packages:qs_dart | ||
os:ubuntu-latest;pub-cache-hosted;sdk:stable | ||
os:ubuntu-latest;pub-cache-hosted | ||
os:ubuntu-latest | ||
- uses: dart-lang/setup-dart@v1 | ||
with: | ||
sdk: stable | ||
- id: checkout | ||
uses: actions/checkout@v4 | ||
- name: Load this version | ||
id: load_this_version | ||
run: | | ||
set -e | ||
echo "THIS_VERSION=$(awk '/^version: / {print $2}' pubspec.yaml)" >> $GITHUB_ENV | ||
- name: Compare versions | ||
id: compare_versions | ||
env: | ||
BASE_VERSION: ${{ needs.get_base_version.outputs.BASE_VERSION }} | ||
run: | | ||
set -e | ||
pushd scripts || exit | ||
dart pub get | ||
echo "IS_VERSION_GREATER=$(dart run compare_versions.dart $THIS_VERSION $BASE_VERSION)" >> $GITHUB_ENV | ||
popd || exit | ||
- 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: Publish (dry run) | ||
id: publish_dry_run | ||
if: ${{ env.IS_VERSION_GREATER == 1 }} | ||
run: dart pub publish --dry-run | ||
- name: Skip publish (dry run) | ||
id: skip_publish_dry_run | ||
if: ${{ env.IS_VERSION_GREATER == 0 }} | ||
run: echo "Skipping publish (dry run) because the version is not greater than the one on pub.dev" |