|
| 1 | +name: Release package |
| 2 | +on: |
| 3 | + push: |
| 4 | + workflow_dispatch: |
| 5 | + |
| 6 | +env: |
| 7 | + DC_TYPE: plugin |
| 8 | + DC_MIN: 2.32 |
| 9 | + |
| 10 | +# required to set secrets in |
| 11 | +# https://github.com/xxx/xxx/settings/secrets/actions |
| 12 | +# TELEGRAM_ID, TELEGRAM_TOKEN |
| 13 | + |
| 14 | +jobs: |
| 15 | + check_release: |
| 16 | + if: (contains(github.event.head_commit.message, 'release') || (github.event_name != 'push')) |
| 17 | + runs-on: ubuntu-latest |
| 18 | + outputs: |
| 19 | + version: ${{ steps.dotclear.outputs.version }} |
| 20 | + dcmin: ${{ steps.dotclear.outputs.dcmin }} |
| 21 | + exists: ${{ steps.repository.outputs.release-exists }} |
| 22 | + steps: |
| 23 | + - name: Checkout repository master branch |
| 24 | + uses: actions/checkout@master |
| 25 | + |
| 26 | + # Parser from https://github.com/franck-paul |
| 27 | + - name: Run PHP code |
| 28 | + id: dotclear |
| 29 | + shell: php {0} |
| 30 | + run: | |
| 31 | + <?php |
| 32 | + $version = ''; |
| 33 | + $dcmin = '${{ env.DC_MIN }}'; |
| 34 | + $df = file_get_contents('./_define.php'); |
| 35 | + if (preg_match('/registerModule\((.*?),(.*?)[\'\"],(.*?)[\'\"],(.*?)[\'\"](.*?)[\'\"](.*?)(,.*)\)/s',$df,$matches)) { |
| 36 | + if (isset($matches[5])) { |
| 37 | + $version = $matches[5]; |
| 38 | + if (isset($matches[7])) { |
| 39 | + $str = $matches[7]; |
| 40 | + if (preg_match('/\[(.*?)[\'\"]core[\'\"](.*?),(.*?)[\'\"](.*?)[\'\"](.*?)\]/s',$str,$submatches)) { |
| 41 | + $dcmin = $submatches[4]; |
| 42 | + } |
| 43 | + } |
| 44 | + } |
| 45 | + } |
| 46 | + file_put_contents(getenv('GITHUB_OUTPUT'), "version=$version\n", FILE_APPEND); |
| 47 | + file_put_contents(getenv('GITHUB_OUTPUT'), "dcmin=$dcmin\n", FILE_APPEND); |
| 48 | +
|
| 49 | + - name: Check repository releases |
| 50 | + id: repository |
| 51 | + uses: insightsengineering/release-existence-action@v1.0.0 |
| 52 | + with: |
| 53 | + release-tag: 'v${{ steps.dotclear.outputs.version }}' |
| 54 | + |
| 55 | + do_release: |
| 56 | + needs: check_release |
| 57 | + if: needs.check_release.outputs.exists == 'false' |
| 58 | + runs-on: ubuntu-latest |
| 59 | + steps: |
| 60 | + - name: Checkout repository master branch |
| 61 | + uses: actions/checkout@master |
| 62 | + |
| 63 | + - name: Get repository name |
| 64 | + id: repository |
| 65 | + uses: MariachiBear/get-repo-name-action@v1.1.0 |
| 66 | + with: |
| 67 | + with-owner: 'false' |
| 68 | + |
| 69 | + - name: Get download URL |
| 70 | + id: download |
| 71 | + run: | |
| 72 | + fulltag=${{ github.ref_name }} |
| 73 | + echo download-url="https://github.com/${{ github.repository }}/releases/download/v${{ needs.check_release.outputs.version }}/${{ env.DC_TYPE }}-${{ steps.repository.outputs.repository-name }}.zip" >> $GITHUB_OUTPUT |
| 74 | +
|
| 75 | + # Parser from https://github.com/franck-paul |
| 76 | + - name: Read dcstore |
| 77 | + id: readstore |
| 78 | + shell: php {0} |
| 79 | + run: | |
| 80 | + <?php |
| 81 | + if (file_exists('dcstore.xml')) { |
| 82 | + $ds = file_get_contents('dcstore.xml'); |
| 83 | + if ($ds) { |
| 84 | + $ds = preg_replace('/<version>(.*?)<\/version>/s',"<version>${{ needs.check_release.outputs.version }}</version>",$ds); |
| 85 | + $ds = preg_replace('/<file>(.*?)<\/file>/s',"<file>${{ steps.download.outputs.download-url }}</file>",$ds); |
| 86 | + $ds = preg_replace('/<da:dcmin>(.*?)<\/da:dcmin>/s',"<da:dcmin>${{ needs.check_release.outputs.dcmin }}</da:dcmin>",$ds); |
| 87 | + if ($ds) { |
| 88 | + file_put_contents('dcstore.xml',$ds); |
| 89 | + } |
| 90 | + } |
| 91 | + } |
| 92 | +
|
| 93 | + - name: Write dcstore |
| 94 | + id: writestore |
| 95 | + shell: bash |
| 96 | + run: | |
| 97 | + test=$(git diff --name-only -- dcstore.xml) |
| 98 | + if [[ "$test" != "" ]]; then |
| 99 | + echo "dcstore.xml modified, need to be commit" |
| 100 | + git config user.name "${{ github.actor }}" |
| 101 | + git config user.email "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com" |
| 102 | + git add dcstore.xml |
| 103 | + git commit -m "Update dcstore.xml" |
| 104 | + git push |
| 105 | + else |
| 106 | + echo "dcstore.xml not modified" |
| 107 | + fi |
| 108 | +
|
| 109 | + - name: Create archive |
| 110 | + id: writearchive |
| 111 | + uses: thedoctor0/zip-release@0.7.6 |
| 112 | + with: |
| 113 | + type: 'zip' |
| 114 | + directory: .. |
| 115 | + path: '${{ steps.repository.outputs.repository-name }}' |
| 116 | + filename: '${{ env.DC_TYPE }}-${{ steps.repository.outputs.repository-name }}.zip' |
| 117 | + exclusions: '*.git* /*node_modules/* .editorconfig' |
| 118 | + |
| 119 | + - name: Create release with archive |
| 120 | + id: writerelease |
| 121 | + uses: ncipollo/release-action@v1.14.0 |
| 122 | + with: |
| 123 | + artifacts: '../${{ env.DC_TYPE }}-${{ steps.repository.outputs.repository-name }}.zip' |
| 124 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 125 | + commit: master |
| 126 | + draft: false |
| 127 | + prerelease: false |
| 128 | + generateReleaseNotes: true |
| 129 | + name: ${{ steps.repository.outputs.repository-name }} ${{ needs.check_release.outputs.version }} |
| 130 | + tag: 'v${{ needs.check_release.outputs.version }}' |
| 131 | + |
| 132 | + - name: Send Telegram Message Ok |
| 133 | + uses: appleboy/telegram-action@v1.0.0 |
| 134 | + with: |
| 135 | + to: ${{ secrets.TELEGRAM_ID }} |
| 136 | + token: ${{ secrets.TELEGRAM_TOKEN }} |
| 137 | + format: markdown |
| 138 | + message: | |
| 139 | + __Github workflow run__ |
| 140 | + - Trigger: ${{ github.event_name }} |
| 141 | + - Release: ${{ steps.repository.outputs.repository-name }} ${{ needs.check_release.outputs.version }} |
| 142 | + - Download URL: ${{ steps.download.outputs.download-url }} |
0 commit comments