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

Publish SDKs with Github Action #842

Merged
merged 8 commits into from
May 20, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/SDK/Language/Dart.php
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,13 @@ public function getFiles(): array
],
[
'scope' => 'default',
'destination' => '.travis.yml',
'template' => 'dart/.travis.yml.twig',
'destination' => '.github/workflows/publish.yml',
'template' => 'dart/.github/workflows/publish.yml.twig',
],
[
'scope' => 'default',
'destination' => '.github/workflows/format.yml',
'template' => 'dart/.github/workflows/format.yml.twig',
],
[
'scope' => 'default',
Expand Down
9 changes: 7 additions & 2 deletions src/SDK/Language/Flutter.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,13 @@ public function getFiles(): array
],
[
'scope' => 'default',
'destination' => '.travis.yml',
'template' => 'flutter/.travis.yml.twig',
'destination' => '.github/workflows/publish.yml',
'template' => 'flutter/.github/workflows/publish.yml.twig',
],
[
'scope' => 'default',
'destination' => '.github/workflows/format.yml',
'template' => 'flutter/.github/workflows/format.yml.twig',
],
[
'scope' => 'enum',
Expand Down
4 changes: 2 additions & 2 deletions src/SDK/Language/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ public function getFiles(): array
],
[
'scope' => 'default',
'destination' => '.travis.yml',
'template' => 'node/.travis.yml.twig',
'destination' => '.github/workflows/publish.yml',
'template' => 'node/.github/workflows/publish.yml.twig',
],
[
'scope' => 'enum',
Expand Down
4 changes: 2 additions & 2 deletions src/SDK/Language/Web.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ public function getFiles(): array
],
[
'scope' => 'default',
'destination' => '.travis.yml',
'template' => 'web/.travis.yml.twig',
'destination' => '.github/workflows/publish.yml',
'template' => 'web/.github/workflows/publish.yml.twig',
],
[
'scope' => 'enum',
Expand Down
33 changes: 33 additions & 0 deletions templates/dart/.github/workflows/format.yml.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Format and push

# Github action will require permission to write to repo
on:
pull_request:
branches:
- main
workflow_dispatch:

jobs:
format:
runs-on: ubuntu-latest
container:
image: dart:stable

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
persist-credentials: true
ref: ${{ '{{'}} github.event.pull_request.head.ref {{ '}}' }}

- name: Format Dart code
run: dart format .

- name: git config
run: git config --global --add safe.directory /__w/sdk-for-dart/sdk-for-dart # required to fix dubious ownership

- name: Add & Commit
uses: EndBug/add-and-commit@v9.1.4
with:
add: lib

14 changes: 14 additions & 0 deletions templates/dart/.github/workflows/publish.yml.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Publish to pub.dev

on:
push:
tags:
- '[0-9]+\.[0-9]+\.[0-9]+.*'

jobs:
publish:
permissions:
id-token: write
uses: dart-lang/setup-dart/.github/workflows/publish.yml@v1
with:
environment: pub.dev
24 changes: 0 additions & 24 deletions templates/dart/.travis.yml.twig

This file was deleted.

33 changes: 33 additions & 0 deletions templates/flutter/.github/workflows/format.yml.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Format and push

# Github action will require permission to write to repo
on:
pull_request:
branches:
- main
workflow_dispatch:

jobs:
format:
runs-on: ubuntu-latest
container:
image: dart:stable

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
persist-credentials: true
ref: ${{ '{{'}} github.event.pull_request.head.ref {{ '}}' }}

- name: Format Dart code
run: dart format .

- name: git config
run: git config --global --add safe.directory /__w/sdk-for-flutter/sdk-for-flutter # required to fix dubious ownership

- name: Add & Commit
uses: EndBug/add-and-commit@v9.1.4
with:
add: lib

14 changes: 14 additions & 0 deletions templates/flutter/.github/workflows/publish.yml.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Publish to pub.dev

on:
push:
tags:
- '[0-9]+\.[0-9]+\.[0-9]+.*'

jobs:
publish:
permissions:
id-token: write
uses: dart-lang/setup-dart/.github/workflows/publish.yml@v1
with:
environment: pub.dev
29 changes: 0 additions & 29 deletions templates/flutter/.travis.yml.twig

This file was deleted.

42 changes: 42 additions & 0 deletions templates/node/.github/workflows/publish.yml.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Publish to NPM

on:
release:
types: [published]
workflow_dispatch:

jobs:
publish:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

# Setup Node.js environment
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'

# Determine release tag based on the tag name
- name: Determine release tag
id: release_tag
run: |
if [[ "${{ '{{' }} github.ref {{ '}}' }}" == *"-rc"* ]] || [[ "${{ '{{' }} github.ref {{ '}}' }}" == *"-RC"* ]]; then
echo "tag=next" >> "$GITHUB_OUTPUT"
else
echo "tag=latest" >> "$GITHUB_OUTPUT"
fi

# Install dependencies (if any) and build your project (if necessary)
- name: Install dependencies and build
run: |
npm install
npm run build

# Publish to NPM with the appropriate tag
- name: Publish
run: npm publish --tag ${{ '{{' }} steps.release_tag.outputs.tag {{ '}}' }}
env:
NODE_AUTH_TOKEN: ${{ '{{' }} secrets.NPM_TOKEN {{ '}}' }}
32 changes: 0 additions & 32 deletions templates/node/.travis.yml.twig

This file was deleted.

42 changes: 42 additions & 0 deletions templates/web/.github/workflows/publish.yml.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Publish to NPM

on:
release:
types: [published]
workflow_dispatch:

jobs:
publish:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

# Setup Node.js environment
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'

# Determine release tag based on the tag name
- name: Determine release tag
id: release_tag
run: |
if [[ "${{ '{{' }} github.ref {{ '}}' }}" == *"-rc"* ]] || [[ "${{ '{{' }} github.ref {{ '}}' }}" == *"-RC"* ]]; then
echo "tag=next" >> "$GITHUB_OUTPUT"
else
echo "tag=latest" >> "$GITHUB_OUTPUT"
fi

# Install dependencies (if any) and build your project (if necessary)
- name: Install dependencies and build
run: |
npm install
npm run build

# Publish to NPM with the appropriate tag
- name: Publish
run: npm publish --tag ${{ '{{' }} steps.release_tag.outputs.tag {{ '}}' }}
env:
NODE_AUTH_TOKEN: ${{ '{{' }} secrets.NPM_TOKEN {{ '}}' }}
32 changes: 0 additions & 32 deletions templates/web/.travis.yml.twig

This file was deleted.