|
4 | 4 | push: |
5 | 5 | branches: [ master, release ] |
6 | 6 |
|
7 | | -jobs: |
8 | | - check_version: |
| 7 | +jobs: |
| 8 | + check_version: |
9 | 9 | name: "Check Version Tag" |
10 | 10 | runs-on: ubuntu-20.04 |
11 | | - steps: |
12 | | - - uses: actions/checkout@v3 |
13 | | - - |
14 | | - continue-on-error: true |
15 | | - env: |
16 | | - GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" |
| 11 | + steps: |
| 12 | + - name: Checkout Repository |
| 13 | + uses: actions/checkout@v3 |
| 14 | + |
| 15 | + - name: Get Latest Version Tag |
17 | 16 | id: previoustag |
18 | | - name: "Get Latest Version" |
19 | 17 | uses: WyriHaximus/github-action-get-previous-tag@master |
20 | | - - |
21 | | - name: "Print Latest Version" |
22 | | - run: "echo ${{ steps.previoustag.outputs.tag }}" |
23 | | - - |
| 18 | + |
| 19 | + - name: Print Latest Version |
| 20 | + run: echo "Latest tag: ${{ steps.previoustag.outputs.tag }}" |
| 21 | + |
| 22 | + - name: Get Version from pubspec.yaml |
24 | 23 | id: config |
25 | | - name: "Get New Version" |
26 | 24 | uses: CumulusDS/get-yaml-paths-action@v0.1.0 |
27 | | - with: |
| 25 | + with: |
28 | 26 | file: pubspec.yaml |
29 | 27 | version_name: version |
30 | | - - |
31 | | - name: "Print New Version" |
32 | | - run: "echo ${{ steps.config.outputs.version_name }}" |
33 | | - - |
34 | | - if: "steps.config.outputs.version_name == steps.previoustag.outputs.tag" |
35 | | - name: "Compare Version" |
| 28 | + |
| 29 | + - name: Print New Version |
| 30 | + run: echo "New version from pubspec.yaml: ${{ steps.config.outputs.version_name }}" |
| 31 | + |
| 32 | + - name: Compare Version |
| 33 | + if: steps.config.outputs.version_name == steps.previoustag.outputs.tag |
36 | 34 | run: | |
37 | | - echo 'The version from your pubspec.yaml is the same as Release, Please update the version' |
38 | | - exit 1 |
39 | | - - |
40 | | - run: "echo ${{ steps.config.outputs.version_name }} > version.txt" |
41 | | - shell: bash |
42 | | - - |
43 | | - name: "Upload New Version" |
| 35 | + echo 'The version from pubspec.yaml is the same as the latest release tag. Please update the version.' |
| 36 | + exit 1 |
| 37 | +
|
| 38 | + - name: Save New Version |
| 39 | + run: echo "${{ steps.config.outputs.version_name }}" > version.txt |
| 40 | + |
| 41 | + - name: Upload New Version Artifact |
44 | 42 | uses: actions/upload-artifact@v4 |
45 | | - with: |
46 | | - name: home |
| 43 | + with: |
| 44 | + name: version |
47 | 45 | path: version.txt |
48 | 46 |
|
49 | | - publish: |
50 | | - needs: |
51 | | - - check_version |
| 47 | + publish: |
| 48 | + needs: check_version |
52 | 49 | runs-on: ubuntu-20.04 |
53 | | - steps: |
54 | | - - name: Checkout |
| 50 | + steps: |
| 51 | + - name: Checkout Repository |
55 | 52 | uses: actions/checkout@v3 |
56 | | - - name: Create Pub Credentials Folder |
57 | | - run: mkdir -p ~/.pub-cache |
58 | | - - name: Create Pub Credentials File |
| 53 | + |
| 54 | + - name: Set up Flutter |
| 55 | + uses: subosito/flutter-action@v2 |
| 56 | + with: |
| 57 | + flutter-version: stable |
| 58 | + |
| 59 | + - name: Set Pub Credentials |
59 | 60 | run: echo "${{ secrets.CREDENTIAL_JSON }}" > ~/.pub-cache/credentials.json |
60 | | - - name: "Publish Package" |
61 | | - uses: Omega365/actions-flutter-pub-publisher@master |
62 | | - with: |
63 | | - dry_run: false |
64 | | - flutter_package: true |
65 | | - skip_test: true |
66 | | - |
67 | | - tag: |
| 61 | + |
| 62 | + - name: Verify Pub Credentials File |
| 63 | + run: | |
| 64 | + if [ -f ~/.pub-cache/credentials.json ]; then |
| 65 | + echo "Credentials file exists." |
| 66 | + else |
| 67 | + echo "Credentials file not found!" && exit 1 |
| 68 | + fi |
| 69 | +
|
| 70 | + - name: Publish Package to Pub |
| 71 | + run: flutter pub publish --force |
| 72 | + |
| 73 | + tag: |
68 | 74 | name: "Tag Version" |
69 | | - needs: |
70 | | - - publish |
| 75 | + needs: publish |
71 | 76 | runs-on: ubuntu-20.04 |
72 | | - steps: |
73 | | - - |
74 | | - name: "Download New Version" |
| 77 | + steps: |
| 78 | + - name: Download New Version |
75 | 79 | uses: actions/download-artifact@v4 |
76 | | - with: |
77 | | - name: home |
78 | | - - |
79 | | - env: |
80 | | - ACTIONS_ALLOW_UNSECURE_COMMANDS: "true" |
81 | | - name: "Set and Tag the new version" |
82 | | - run: "echo \"::set-env name=RELEASE_VERSION::$(cat home/version.txt)\"" |
83 | | - shell: bash |
84 | | - - |
85 | | - uses: tvdias/github-tagger@v0.0.2 |
86 | | - with: |
87 | | - repo-token: "${{ secrets.GITHUB_TOKEN }}" |
88 | | - tag: "${{env.RELEASE_VERSION}}" |
| 80 | + with: |
| 81 | + name: version |
| 82 | + |
| 83 | + - name: Read and Tag New Version |
| 84 | + env: |
| 85 | + NEW_VERSION: ${{ steps.download-artifact.outputs.path }} |
| 86 | + run: | |
| 87 | + NEW_VERSION=$(cat version/version.txt) |
| 88 | + echo "Tagging version: $NEW_VERSION" |
| 89 | + git tag $NEW_VERSION |
| 90 | + git push origin $NEW_VERSION |
0 commit comments