blob: 04bca123a3e8eb83b3575720d36ee41c86d32e7a [file] [edit]
# A CI configuration to auto-publish pub packages.
name: Publish
# Callers of this workflow should use it as follows:
#
# name: Publish
# on:
# pull_request:
# branches: [ main ]
# types: [opened, synchronize, reopened, labeled, unlabeled]
# push:
# tags: [ 'v[0-9]+.[0-9]+.[0-9]+*' ]
# jobs:
# publish:
# uses: dart-lang/ecosystem/.github/workflows/publish.yaml@main
# Callers may optionally specify the version of the SDK to use when publishing a
# package. This can be useful if your package has a very recent minimum SDK
# constraint. This is done via the `sdk` input parameter. Note that this
# parameter is not required; it defaults to `stable` - using the most recent
# stable release of the Dart SDK. To pass this value:
#
# jobs:
# publish:
# uses: dart-lang/ecosystem/.github/workflows/publish.yaml@main
# with:
# sdk: beta
# When using this package to publish Flutter packages, the `use-flutter`
# parameter should be set. The `sdk` parameter is then used to specify
# the Flutter SDK.
#
# jobs:
# publish:
# uses: dart-lang/ecosystem/.github/workflows/publish.yaml@main
# with:
# use-flutter: true
# When using a post_summaries.yaml workflow to post the comments, set
# the write-comments parameter to false.
#
# jobs:
# publish:
# uses: dart-lang/ecosystem/.github/workflows/publish.yaml@main
# with:
# write-comments: false
# It is also possible to ignore certain packages in the repository
# via a glob.
#
# jobs:
# publish:
# uses: dart-lang/ecosystem/.github/workflows/publish.yaml@main
# with:
# ignore-packages: pkgs/non-published-package
on:
workflow_call:
inputs:
environment:
description: >-
If specified, publishes will be performed from this environment,
which will require additional approvals. See
https://dart.dev/tools/pub/automated-publishing for more
information.
required: false
type: string
sdk:
description: >-
The channel, or a specific version from a channel, to install
('2.19.0','stable', 'beta', 'dev'). Using one of the three channels
will give you the latest version published to that channel.
default: "stable"
required: false
type: string
use-flutter:
description: >-
Whether to setup Flutter in this workflow.
default: false
required: false
type: boolean
write-comments:
description: >-
Whether to write a comment in this workflow.
default: true
required: false
type: boolean
checkout_submodules:
description: >-
Whether to checkout submodules of git repositories.
default: false
required: false
type: boolean
ignore-packages:
description: >-
A comma-separated list of package paths or glob patterns to ignore.
default: ''
required: false
type: string
tag-prefix:
description: >-
The prefix to expect and generate for release git tags (e.g. 'v' or '').
default: "v"
required: false
type: string
local_debug:
description: Whether to use a local copy of package:firehose - only for debug
default: false
type: boolean
required: false
jobs:
# Note that this job does not require the specified environment.
validate:
if: ${{ github.event_name == 'pull_request' }}
# These permissions are required for authentication using OIDC and to enable
# us to create comments on PRs.
permissions:
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
with:
submodules: ${{ inputs.checkout_submodules }}
- uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9
with:
path: ~/.pub-cache
key: ${{ runner.os }}-pub-cache-${{ hashFiles('**/pubspec.lock') }}
restore-keys: |
${{ runner.os }}-pub-cache-
- uses: subosito/flutter-action@1a449444c387b1966244ae4d4f8c696479add0b2
if: ${{ inputs.use-flutter }}
with:
channel: ${{ inputs.sdk }}
cache: true
- uses: dart-lang/setup-dart@6afc89df92d6eb3834022f73cd65adc8cdfcb92d
if: ${{ !inputs.use-flutter }}
with:
sdk: ${{ inputs.sdk }}
- name: Install firehose (internal)
if: ${{ !inputs.local_debug && github.repository == 'dart-lang/ecosystem' }}
env:
GIT_URL: ${{ github.event.pull_request.head.repo.clone_url || 'https://github.com/dart-lang/ecosystem' }}
GIT_REF: ${{ github.head_ref || github.ref_name }}
run: dart pub global activate --source git "$GIT_URL" --git-path pkgs/firehose/ --git-ref "$GIT_REF"
- name: Install firehose (external)
if: ${{ !inputs.local_debug && github.repository != 'dart-lang/ecosystem' }}
run: dart pub global activate --source git https://github.com/dart-lang/ecosystem --git-path pkgs/firehose/
- name: Install local firehose
run: dart pub global activate --source path pkgs/firehose/
if: ${{ inputs.local_debug }}
- name: Fetch labels
id: fetch-labels
run: |
labels=$(gh api repos/$OWNER/$REPO_NAME/pulls/$PULL_REQUEST_NUMBER --jq '.labels | map(.name) | join(",")')
echo "Found labels: $labels"
echo "labels=$labels" >> "$GITHUB_OUTPUT"
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OWNER: ${{ github.repository_owner }}
REPO_NAME: ${{ github.event.repository.name }}
PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }}
- name: Validate packages
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ISSUE_NUMBER: ${{ github.event.number }}
PR_LABELS: ${{ steps.fetch-labels.outputs.labels }}
INPUTS_IGNORE_PACKAGES: ${{ inputs.ignore-packages }}
INPUTS_TAG_PREFIX: ${{ inputs.tag-prefix }}
USE_FLUTTER: ${{ inputs.use-flutter }}
run: |
if [ "$USE_FLUTTER" = "true" ]; then
FLUTTER_FLAG="--use-flutter"
else
FLUTTER_FLAG="--no-use-flutter"
fi
dart pub global run firehose \
--validate \
"$FLUTTER_FLAG" \
--ignore-packages "$INPUTS_IGNORE_PACKAGES" \
--tag-prefix "$INPUTS_TAG_PREFIX"
- name: Get comment id
id: comment-id
if: ${{ (hashFiles('output/comment.md') != '') && inputs.write-comments }}
run: |
touch -a output/commentId
COMMENT_ID=$(cat output/commentId)
echo "comment=$COMMENT_ID" >> "$GITHUB_OUTPUT"
- name: Create comment
if: ${{ (hashFiles('output/comment.md') != '') && inputs.write-comments && (steps.comment-id.outputs.comment == '') }}
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ISSUE_NUMBER: ${{ github.event.number }}
run: dart pub global run firehose:comment create-or-update --issue "$ISSUE_NUMBER" --body-path output/comment.md
- name: Update comment
if: ${{ (hashFiles('output/comment.md') != '') && inputs.write-comments && (steps.comment-id.outputs.comment != '') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMENT_ID: ${{ steps.comment-id.outputs.comment }}
run: dart pub global run firehose:comment create-or-update --comment-id "$COMMENT_ID" --body-path output/comment.md
- name: Save PR number
if: ${{ !inputs.write-comments }}
env:
ISSUE_NUMBER: ${{ github.event.number }}
run: |
mkdir -p output/ && echo "$ISSUE_NUMBER" > output/issueNumber
- name: Upload folder with number and markdown
if: ${{ !inputs.write-comments }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
with:
name: output
path: output/
publish:
if: ${{ github.event_name == 'push' }}
# Require the github deployment environment if supplied.
environment: ${{ inputs.environment }}
# This permission is required for authentication using OIDC.
permissions:
id-token: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
with:
submodules: ${{ inputs.checkout_submodules }}
- uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9
with:
path: ~/.pub-cache
key: ${{ runner.os }}-pub-cache-${{ hashFiles('**/pubspec.lock') }}
restore-keys: |
${{ runner.os }}-pub-cache-
- uses: subosito/flutter-action@1a449444c387b1966244ae4d4f8c696479add0b2
if: ${{ inputs.use-flutter }}
with:
channel: ${{ inputs.sdk }}
cache: true
- uses: dart-lang/setup-dart@6afc89df92d6eb3834022f73cd65adc8cdfcb92d
if: ${{ !inputs.use-flutter }}
with:
sdk: ${{ inputs.sdk }}
- name: Install firehose (internal)
if: ${{ !inputs.local_debug && github.repository == 'dart-lang/ecosystem' }}
env:
GIT_URL: ${{ github.event.pull_request.head.repo.clone_url || 'https://github.com/dart-lang/ecosystem' }}
GIT_REF: ${{ github.head_ref || github.ref_name }}
run: dart pub global activate --source git "$GIT_URL" --git-path pkgs/firehose/ --git-ref "$GIT_REF"
- name: Install firehose (external)
if: ${{ !inputs.local_debug && github.repository != 'dart-lang/ecosystem' }}
run: dart pub global activate --source git https://github.com/dart-lang/ecosystem --git-path pkgs/firehose/
- name: Install local firehose
run: dart pub global activate --source path pkgs/firehose/
if: ${{ inputs.local_debug }}
- name: Publish packages
env:
INPUTS_TAG_PREFIX: ${{ inputs.tag-prefix }}
USE_FLUTTER: ${{ inputs.use-flutter }}
run: |
if [ "$USE_FLUTTER" = "true" ]; then
FLUTTER_FLAG="--use-flutter"
else
FLUTTER_FLAG="--no-use-flutter"
fi
dart pub global run firehose \
--publish \
"$FLUTTER_FLAG" \
--tag-prefix "$INPUTS_TAG_PREFIX"