Skip to content

Commit

Permalink
chore: Github action updated
Browse files Browse the repository at this point in the history
  • Loading branch information
kushalmahapatro committed Sep 4, 2023
1 parent 9331e6a commit 8f9dd75
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 22 deletions.
File renamed without changes.
68 changes: 68 additions & 0 deletions .github/workflows/check_version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
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 }}
JSON_RESPONSE=$(curl -s "https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/releases")
# Extract tag_name using Python
TAG_NAME=$(python -c "import sys, json; print(json.loads(sys.stdin.read())[0]['tag_name'])" <<< "$JSON_RESPONSE")
echo "latest=${TAG_NAME}">> $GITHUB_OUTPUT
# PAT=${{ secrets.GITHUB_TOKEN }}
# REPO_OWNER=${{ github.repository_owner }}
# LATEST_TAG=$(curl -s -H "Authorization: token $PAT" "https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/releases" | jq -r ".tag_name")
# LATEST_TAG=$(curl -s "https://api.github.com/repos/$REPO_OWNER/$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_version=${{ 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_version" | sed 's/v\?\([0-9.]*\)[-a-zA-Z]*$/\1/')
if [[ "$provided_version" == "$latest_version" ]]; then
echo "trigger_next_action=false">> $GITHUB_OUTPUT
exit 1
elif [[ "$provided_version" < "$latest_version" ]]; then
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 }}
30 changes: 21 additions & 9 deletions .github/workflows/create_tag.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,37 @@
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 Down Expand Up @@ -49,11 +59,13 @@ jobs:
uses: subosito/flutter-action@v2
with:
channel: 'stable'
- run: flutter --version

- 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


3 changes: 2 additions & 1 deletion .github/workflows/pull_request_opened.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: Pull Request (Opened)
on:
pull_request:
types: [ opened, edited, reopened ]
branches:
- '*'

permissions:
contents: read
Expand All @@ -11,7 +13,6 @@ permissions:
discussions: write

jobs:

assign_author:
name: Assign Author to the Pull Request
permissions:
Expand Down
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
2 changes: 1 addition & 1 deletion example/.flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"firebase_core","path":"/Users/kushalmahapatro/.pub-cache/hosted/pub.dev/firebase_core-2.14.0/","native_build":true,"dependencies":[]},{"name":"firebase_crashlytics","path":"/Users/kushalmahapatro/.pub-cache/hosted/pub.dev/firebase_crashlytics-3.3.3/","native_build":true,"dependencies":["firebase_core"]}],"android":[{"name":"firebase_core","path":"/Users/kushalmahapatro/.pub-cache/hosted/pub.dev/firebase_core-2.14.0/","native_build":true,"dependencies":[]},{"name":"firebase_crashlytics","path":"/Users/kushalmahapatro/.pub-cache/hosted/pub.dev/firebase_crashlytics-3.3.3/","native_build":true,"dependencies":["firebase_core"]}],"macos":[{"name":"firebase_core","path":"/Users/kushalmahapatro/.pub-cache/hosted/pub.dev/firebase_core-2.14.0/","native_build":true,"dependencies":[]},{"name":"firebase_crashlytics","path":"/Users/kushalmahapatro/.pub-cache/hosted/pub.dev/firebase_crashlytics-3.3.3/","native_build":true,"dependencies":["firebase_core"]}],"linux":[],"windows":[{"name":"firebase_core","path":"/Users/kushalmahapatro/.pub-cache/hosted/pub.dev/firebase_core-2.14.0/","native_build":true,"dependencies":[]}],"web":[{"name":"firebase_core_web","path":"/Users/kushalmahapatro/.pub-cache/hosted/pub.dev/firebase_core_web-2.6.0/","dependencies":[]}]},"dependencyGraph":[{"name":"firebase_core","dependencies":["firebase_core_web"]},{"name":"firebase_core_web","dependencies":[]},{"name":"firebase_crashlytics","dependencies":["firebase_core"]}],"date_created":"2023-07-11 00:30:35.182476","version":"3.10.3"}
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"firebase_core","path":"/Users/kushalmahapatro/.pub-cache/hosted/pub.dev/firebase_core-2.14.0/","native_build":true,"dependencies":[]},{"name":"firebase_crashlytics","path":"/Users/kushalmahapatro/.pub-cache/hosted/pub.dev/firebase_crashlytics-3.3.3/","native_build":true,"dependencies":["firebase_core"]}],"android":[{"name":"firebase_core","path":"/Users/kushalmahapatro/.pub-cache/hosted/pub.dev/firebase_core-2.14.0/","native_build":true,"dependencies":[]},{"name":"firebase_crashlytics","path":"/Users/kushalmahapatro/.pub-cache/hosted/pub.dev/firebase_crashlytics-3.3.3/","native_build":true,"dependencies":["firebase_core"]}],"macos":[{"name":"firebase_core","path":"/Users/kushalmahapatro/.pub-cache/hosted/pub.dev/firebase_core-2.14.0/","native_build":true,"dependencies":[]},{"name":"firebase_crashlytics","path":"/Users/kushalmahapatro/.pub-cache/hosted/pub.dev/firebase_crashlytics-3.3.3/","native_build":true,"dependencies":["firebase_core"]}],"linux":[],"windows":[{"name":"firebase_core","path":"/Users/kushalmahapatro/.pub-cache/hosted/pub.dev/firebase_core-2.14.0/","native_build":true,"dependencies":[]}],"web":[{"name":"firebase_core_web","path":"/Users/kushalmahapatro/.pub-cache/hosted/pub.dev/firebase_core_web-2.6.0/","dependencies":[]}]},"dependencyGraph":[{"name":"firebase_core","dependencies":["firebase_core_web"]},{"name":"firebase_core_web","dependencies":[]},{"name":"firebase_crashlytics","dependencies":["firebase_core"]}],"date_created":"2023-09-04 21:16:07.499517","version":"3.13.0"}
30 changes: 19 additions & 11 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687
url: "https://pub.dev"
source: hosted
version: "1.17.1"
version: "1.17.2"
cupertino_icons:
dependency: "direct main"
description:
Expand Down Expand Up @@ -188,18 +188,18 @@ packages:
dependency: transitive
description:
name: matcher
sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb"
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
url: "https://pub.dev"
source: hosted
version: "0.12.15"
version: "0.12.16"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
url: "https://pub.dev"
source: hosted
version: "0.2.0"
version: "0.5.0"
meta:
dependency: transitive
description:
Expand Down Expand Up @@ -240,10 +240,10 @@ packages:
dependency: transitive
description:
name: source_span
sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250
sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
url: "https://pub.dev"
source: hosted
version: "1.9.1"
version: "1.10.0"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -280,10 +280,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb
sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8"
url: "https://pub.dev"
source: hosted
version: "0.5.1"
version: "0.6.0"
vector_math:
dependency: transitive
description:
Expand All @@ -292,6 +292,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
web:
dependency: transitive
description:
name: web
sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10
url: "https://pub.dev"
source: hosted
version: "0.1.4-beta"
yaml:
dependency: transitive
description:
Expand All @@ -301,5 +309,5 @@ packages:
source: hosted
version: "3.1.2"
sdks:
dart: ">=3.0.0 <4.0.0"
dart: ">=3.1.0-185.0.dev <4.0.0"
flutter: ">=3.3.0"

0 comments on commit 8f9dd75

Please sign in to comment.