Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert the implementation of the action to Dart #77

Merged
merged 11 commits into from
Mar 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/** -diff linguist-generated=true
11 changes: 8 additions & 3 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
version: 2

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, why no package-ecosystem: pub?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran into some issues when eval'ing it when it was in beta (dependabot/dependabot-core#4979), and was generally waiting for them to be addressed before using the functionality more widely.

updates:
- package-ecosystem: "github-actions"
directory: "/"
- package-ecosystem: github-actions
directory: /
schedule:
interval: "weekly"
interval: monthly

- package-ecosystem: npm
directory: /
schedule:
interval: monthly
18 changes: 18 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Validate that the compiled artifacts are up-to-date.

name: Build

on:
pull_request:
branches: [main]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./
with:
sdk: beta
- run: dart pub get
- run: dart tool/sig.dart --verify
4 changes: 3 additions & 1 deletion .github/workflows/dart.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Tests for general `setup-dart` configurations.

name: Dart

on:
Expand All @@ -6,7 +8,7 @@ on:
pull_request:
branches: [main]
schedule:
- cron: "0 0 * * 0" # Run every Sunday at 00:00.
- cron: "0 0 * * 0" # Run every Sunday at 00:00.

jobs:

Expand Down
16 changes: 13 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
example/.packages
example/pubspec.lock
example/.dart_tool/
# Dart files
.dart_tool/
pubspec.lock

# node modules
node_modules/

# intermediary compilation artifacts
lib/main.js
lib/main.js.deps
lib/main.js.map

lib/sig.txt
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## v1.5.0-dev

* Re-wrote the implementation of the action into Dart.
* Auto-detect the platform architecture (`x64`, `ia32`, `arm`, `arm64`).
* Improved the caching and download resilience of the sdk.
* Added a new action output: `dart-version` - the installed version of the sdk.

## v1.4.0

* Automatically create OIDC token for pub.dev.
Expand Down
50 changes: 46 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
## How to Contribute
# How to Contribute

Prior to sending patches and contributions to this project, please file
an issue in the issue tracker to ensure there is alignment with the overall
goals of this project. Thanks!
We'd love to accept your patches and contributions to this project. There are
just a few small guidelines you need to follow.

## Contributor License Agreement

Expand All @@ -17,3 +16,46 @@ You generally only need to submit a CLA once, so if you've already submitted one
(even if it was for a different project), you probably don't need to do it
again.

## Start with an issue

Prior to sending patches and contributions to this project, please file an issue
in the issue tracker to ensure there is alignment with the overall goals of this
project. Thanks!

## Code Reviews

All submissions, including submissions by project members, require review. We
use GitHub pull requests for this purpose. Consult
[GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
information on using pull requests.

## Coding style

The Dart source code in this repo follows the:

* [Dart style guide](https://dart.dev/guides/language/effective-dart/style)

You should familiarize yourself with those guidelines.

## File headers

All files in the Dart project must start with the following header; if you add a
new file please also add this. The year should be a single number stating the
year the file was created (don't use a range like "2011-2012"). Additionally, if
you edit an existing file, you shouldn't update the year.

// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

## Building and testing

See the [DEVELOPING.md](DEVELOPING.md) file.

## Community Guidelines

This project follows
[Google's Open Source Community Guidelines](https://opensource.google/conduct/).

We pledge to maintain an open and welcoming environment. For details, see our
[code of conduct](https://dart.dev/code-of-conduct).
37 changes: 37 additions & 0 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[![Build](https://github.com/dart-lang/setup-dart/actions/workflows/build.yml/badge.svg)](https://github.com/dart-lang/setup-dart/actions/workflows/build.yml)
[![Dart](https://github.com/dart-lang/setup-dart/actions/workflows/dart.yml/badge.svg)](https://github.com/dart-lang/setup-dart/actions/workflows/dart.yml)

## Setting up

1. Install node
1. Install additional node tooling (`npm i -g @vercel/ncc`)
1. Install the node package dependencies (`npm install`)

## Development

tldr: edit Dart source files; run `npm run all` to re-compile the action

### Working on the action

Generally, to work on the action, edit the Dart source code in `lib/` and
re-compile the JavaScript code via `npm run all`. This will:

- compile the Dart source (via dart2js) to `lib/main.js`; copy that file to
`dist/main.cjs`
- package and minify the `lib/main.mjs` entrypoint point and referencd node
modules to `dist/index.mjs`

### Files

`lib/main.dart` - the Dart entry-point to the action.

`lib/main.mjs` - the JavaScript wrapper; this sets up some important JS interop
globals and bootstraps into `lib/main.dart`.

`dist/index.mjs` - the execution entry-point of the action.

## Releasing

See our
[publishing](https://github.com/dart-lang/setup-dart/wiki/Publishing-procedure)
wiki page.
70 changes: 31 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
# setup-dart

[![Dart](https://github.com/dart-lang/setup-dart/workflows/Dart/badge.svg)](https://github.com/dart-lang/setup-dart/actions?query=workflow%3A%22Dart%22+branch%3Amain)
[setup-dart](https://github.com/dart-lang/setup-dart) installs and sets up a
Dart SDK for use in GitHub Actions; it:

This [GitHub Action](https://github.com/dart-lang/setup-dart) installs
and sets up of a Dart SDK for use in actions by:

* Downloading the Dart SDK
* Adding the [`dart`](https://dart.dev/tools/dart-tool) command
and [`pub` cache](https://dart.dev/tools/pub/cmd/pub-get#the-system-package-cache)
to the system path
* downloads the Dart SDK
* adds the [`dart`](https://dart.dev/tools/dart-tool) tool to the system path

## Usage

Install the latest stable SDK and run 'Hello World':
To install the latest stable Dart SDK and run typical checks:

```yml
steps:
- uses: actions/checkout@v3
- uses: dart-lang/setup-dart@v1
- run: dart pub get
- run: dart run bin/hello_world.dart
name: Dart

on:
pull_request:
branches: [main]
push:
branches: [main]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dart-lang/setup-dart@v1

- run: dart pub get
- run: dart format --output=none --set-exit-if-changed .
- run: dart analyze
- run: dart test
```

## Inputs
Expand All @@ -36,8 +46,9 @@ The action takes the following inputs:
* The available build flavors are `release` and `raw`.
* The `release` flavor contains published builds.
* The `raw` flavor contains unpublished builds; these can be used by
developers to test against SDK versions before a release. Note that the
`main` release channel only supports `raw` build flavor.
developers to test against SDK versions before a signed release is
available. Note that the `main` release channel only supports the `raw`
build flavor.

* `architecture`: The CPU architecture to setup support for.
* Valid options are `x64`, `ia32`, `arm`, and `arm64`.
Expand All @@ -46,30 +57,11 @@ The action takes the following inputs:
[Dart system requirements](https://dart.dev/get-dart#system-requirements)
for valid combinations.

## Check static analysis, formatting, and run tests
## Outputs

Various static checks:
The action produces the following output:

1) Check static analysis with the Dart analyzer
2) Check code follows Dart idiomatic formatting
3) Check that unit tests pass

```yml
...
steps:

- name: Install dependencies
run: dart pub get

- name: Verify formatting
run: dart format --output=none --set-exit-if-changed .

- name: Analyze project source
run: dart analyze

- name: Run tests
run: dart test
```
* `dart-version`: The version of the Dart SDK that was installed.

## Matrix testing example

Expand Down Expand Up @@ -171,4 +163,4 @@ Contributions are welcome! Please see [CONTRIBUTING.md.md](CONTRIBUTING.md.md).

## Version history

Please see out [CHANGELOG.md](CHANGELOG.md) file.
Please see our [CHANGELOG.md](CHANGELOG.md) file.
16 changes: 8 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
name: "Setup Dart SDK"
description: "Setup the Dart SDK, and add it to the PATH"
description: "Download and setup the Dart SDK."
branding:
icon: check-circle
color: blue
inputs:
sdk:
description: >-
The channel, or a specific version from a channel to install ('stable',
'beta', 'dev', '2.7.2', '2.12.0-1.4.beta'). Using one of the three
'beta', 'dev', '2.7.2', '2.12.0-1.4.beta'). Using one of the named
channels instead of a version will give you the latest version published
to that channel.
required: false
default: "stable"
architecture:
description: "The CPU architecture ('x64', 'ia32', 'arm', or 'arm64')."
required: false
default: "x64"
flavor:
description: "The build flavor ('raw' or 'release')."
description: "The build flavor ('release' or 'raw')."
required: false
outputs:
dart-version:
description: 'The installed Dart version.'
runs:
using: "composite"
steps:
- run: $GITHUB_ACTION_PATH/setup.sh ${{ inputs.sdk }} ${{ runner.os }} ${{ inputs.architecture }} ${{ inputs.flavor }}
shell: bash
using: "node16"
main: "dist/index.mjs"
5 changes: 5 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include: package:lints/recommended.yaml

linter:
rules:
- unawaited_futures