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

build: github actions check added #31

Merged
merged 3 commits into from
Sep 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
64 changes: 64 additions & 0 deletions .github/workflows/check_version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Check Version

on:
pull_request:
branches:
- main

jobs:
check-version:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Get version
id: yq
uses: mikefarah/yq@master

with:
cmd: yq -r '.version' 'pubspec.yaml'

- name: Print version
run: echo ${{ steps.yq.outputs.result }}

- name: Get Latest Tag
id: get_tag
run: |
REPO_NAME=${{ github.repository }}
LATEST_TAG=$(curl -s "https://api.github.com/repos/$REPO_NAME/releases" | jq -r '.[0].tag_name')
echo "latest=${LATEST_TAG}">> $GITHUB_OUTPUT

- name: Print version
run: echo "provided_version=${{ steps.yq.outputs.result }} and latest_tag=${{ steps.get_tag.outputs.latest }}"

- name: Check Version
id: check_version
run: |
latest_tag=${{ steps.get_tag.outputs.latest }}
provided_tag=${{ steps.yq.outputs.result }}

# Extract numerical version parts from the tags
latest_version=$(echo "$latest_tag" | sed 's/v\?\([0-9.]*\)[-a-zA-Z]*$/\1/')
provided_version=$(echo "$provided_tag" | sed 's/v\?\([0-9.]*\)[-a-zA-Z]*$/\1/')

echo "latest_version=${latest_version} and provided_version=${provided_version}"
echo "$provided_version" == "$latest_version"

if [[ "$provided_version" == "$latest_version" ]]; then
echo "Provided version is equal to latest version"
echo "trigger_next_action=false">> $GITHUB_OUTPUT
exit 1
elif [[ "$provided_version" < "$latest_version" ]]; then
echo "Provided version is less than latest version"
echo "trigger_next_action=false">> $GITHUB_OUTPUT
exit 1
else
echo "trigger_next_action=true">> $GITHUB_OUTPUT
fi

- name: Trigger Next Action
run: echo "Trigger Next Action ${{ steps.check_version.outputs.trigger_next_action }}"
env:
TRIGGER_NEXT_ACTION: ${{ steps.check_version.outputs.trigger_next_action }}
47 changes: 47 additions & 0 deletions .github/workflows/commit_push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Commit Push

on:
pull_request:
push:
branches:
- '*'

env:
flutter_version: "3.13.0"
java_version: "12.x"

permissions:
contents: read
issues: write
pull-requests: write
discussions: write

jobs:

check-branch:
runs-on: ubuntu-latest
name: Check branch
steps:
- uses: actions/checkout@v3
- name: Cache Flutter SDK
uses: actions/cache@v3
with:
path: /opt/hostedtoolcache/flutter
key: ${{ runner.OS }}-flutter-install-cache-${{ env.flutter_version }}
- uses: subosito/flutter-action@v2
with:
flutter-version: ${{ env.flutter_version }}
- run: flutter --version

- name: Install dependencies
run: dart pub get

- name: Analyze project source
run: dart analyze

- name: Run tests
run: dart test

- name: Run dart publish (dry run)
if: ${{ github.event.pull_request.base.ref == 'main' }}
run: dart pub publish --dry-run
39 changes: 27 additions & 12 deletions .github/workflows/create_tag.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,37 @@
name: Build Release
name: Create Tag and Publish to pub.dev

on:
pull_request:
types: [ closed ]
branches: [ main ]
workflow_run:
workflows: ["Trigger Create Tag and Publish Workflow on PR Merge", "Check Version"]
types:
- completed

jobs:
create-tag:
if: github.event.pull_request.merged == true
placeholder-job:
runs-on: ubuntu-latest

steps:
- name: Placeholder Step
run: echo "This is a placeholder job"

create-tag-and-publish:
permissions:
repository-projects: write
packages: write
contents: read
pull-requests: write

runs-on: ubuntu-latest
needs: [placeholder-job, trigger_next_action, trigger_create_tag_and_publish]

if: env.TRIGGER_NEXT_ACTION == 'true' && env.TRIGGER_CREATE_TAG_AND_PUBLISH == 'true'

steps:
- uses: actions/checkout@v3

- name: Get version
id: yq
uses: mikefarah/yq@master

with:
cmd: yq -r '.version' 'pubspec.yaml'

Expand All @@ -30,7 +40,7 @@ jobs:

- name: Create tag
uses: actions/github-script@v3
id: "tag_create"
id: tagCreate
env:
TAG: 'v${{ steps.yq.outputs.result }}'
with:
Expand All @@ -43,14 +53,19 @@ jobs:
sha: context.sha
})
- name: Print tag update
run: echo ${{ steps.tag_create.outputs.result }}
run: echo ${{ steps.tagCreate.outputs.result }}

- name: Publish
if: steps.tag_create.outputs.result != null
uses: subosito/flutter-action@v2
with:
channel: 'stable'

- name: Flutter Version
run: flutter --version

- name: Publish to Dart Package
uses: k-paxian/dart-package-publisher@v1.5.1
with:
credentialJson: ${{ secrets.CREDENTIAL_JSON }}
flutter: true
skipTests: true


30 changes: 1 addition & 29 deletions .github/workflows/pull_request_opened.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Pull Request (Opened)
name: Pull Request

on:
pull_request:
Expand All @@ -11,18 +11,8 @@ permissions:
discussions: write

jobs:
# security_hardening:
# name: Check security hardening
# runs-on: ubuntu-latest
# steps:
# - name: Clone the repository
# uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f
# - name: Ensure SHA pinned actions
# uses: zgosalvez/github-actions-ensure-sha-pinned-actions@8877889a5717dad0b139f1d2925689aa68f88a43

assign_author:
name: Assign Author to the Pull Request
# needs: security_hardening
permissions:
contents: read
pull-requests: write
Expand All @@ -44,21 +34,3 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

check-branch:
runs-on: ubuntu-latest
name: Check branch
steps:
- uses: actions/checkout@v3
- uses: subosito/flutter-action@v2
with:
channel: 'stable'
- run: flutter --version

- name: Install dependencies
run: dart pub get

- name: Analyze project source
run: dart analyze

- name: Run tests
run: dart test
26 changes: 26 additions & 0 deletions .github/workflows/trigger_on_pr_merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Trigger Create Tag and Publish Workflow on PR Merge

on:
pull_request:
types:
- closed

jobs:
trigger-create-tag-and-publish:
runs-on: ubuntu-latest

steps:
- name: Check if PR is merged into main
id: check_merged
run: |
if [ "${{ github.event.pull_request.merged }}" = "true" ] && [ "${{ github.event.pull_request.base.ref }}" = "main" ]; then
echo "true"
else
echo "false"
fi

- name: Set trigger_create_tag_and_publish output
id: set_output
env:
TRIGGER_CREATE_TAG_AND_PUBLISH: ${{ steps.check_merged.outputs.outputs.result}}
run: echo "set-env:TRIGGER_CREATE_TAG_AND_PUBLISH=${{ steps.check_merged.outputs.outputs.result}}" >> $GITHUB_ENV
31 changes: 0 additions & 31 deletions .github/workflows/verify_push.yml

This file was deleted.

12 changes: 8 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
### 0.1.0 (2023-08-05)
#### Added
- Added 'pubm' executable, can be activated by `dart pub global activate pubm`.

### 0.0.3-alpha (2023-07-11)
#### Added
- Added support for Addition/Others params in pubspec.yaml file. (like msix_config, flutter_launcher_icons)
- Added warning message if the name in pubspec.yaml file got changed with the one provided in pubspec_<flavor>.yaml file.
- Added warning message if the name in pubspec.yaml file got changed with the one provided in `pubspec_<flavor>.yaml` file.
- Unit test cases for the added features.

#### Fixed
- Fixed the issue when name was not provided in pubspec_<flavor>.yaml and the name in pubspec.yaml file was changed to empty string.
- Fixed the issue when name was not provided in `pubspec_<flavor>.yaml` and the name in pubspec.yaml file was changed to empty string.
- Fixed the issue with the git dependencies without ref

### 0.0.2-alpha (2023-07-10)
Expand All @@ -18,5 +22,5 @@
##### Added
- New feature to automatically sort dependencies alphabetically and also as per the type of the dependency.
- Feature to automatically add the new dependency to the correct section of the pubspec.yaml file.
- Feature to update dependencies to the desired version (as mentioned in the respective pubspec_$flavor.yaml file).
- Feature to change the name, version, description and also assets and fonts in pubspec.yaml file as per the pubspec_$flavor.yaml.
- Feature to update dependencies to the desired version (as mentioned in the respective `pubspec_<flavor>.yaml` file).
- Feature to change the name, version, description and also assets and fonts in pubspec.yaml file as per the `pubspec_<flavor>.yaml`.
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,31 @@ For Flutter projects, use:
PS c:\src\flutter_project> flutter pub add --dev pubm
```

###### 🎯 Activate from https://pub.dev
to use the executable, run the following command in your terminal:

```console
dart pub global activate pubm
```

## 📋 Usage

To manage different versions of pubspec.yaml files, create a new file for each flavor with the name `pubspec_<flavor>.yaml`. When the following command is executed, the pubspec.yaml file is updated with the contents of the `pubspec_<flavor>.yaml` file. This can be used to update, change, or add dependencies and their respective versions, as well as Flutter fonts.

```console
PS c:\src\flutter_project> dart run pubm:manage -f <flavor>
# if activated from https://pub.dev
pubm -f <flavor>

# else
dart run pubm:manage -f <flavor>
```
Use the -v flag to print detailed logs (verbose logs) in the console.console.
```console
PS c:\src\flutter_project> dart run pubm:manage -f <flavor> -v
# if activated from https://pub.dev
pubm -f <flavor> -v

# else
dart run pubm:manage -f <flavor> -v
```
### 📋 Example: pubpsec_dev.yaml
Here's an example of a flavor-specific pubspec.yaml file for a 'dev' flavor:
Expand Down Expand Up @@ -106,6 +121,10 @@ flutter:
After running the below command, the output pubspec.yaml file will be as follows:
##### Command:
```console
# if activated from https://pub.dev
pubm -f dev

# else
dart run pubm:manage -f dev
```
##### Output
Expand Down
Loading