diff --git a/.github/workflows/update-plugin.yml b/.github/workflows/update-plugin.yml new file mode 100644 index 0000000..59a7ee1 --- /dev/null +++ b/.github/workflows/update-plugin.yml @@ -0,0 +1,90 @@ +name: Create Plugin Revision + +on: + workflow_dispatch: + inputs: + repository: + description: 'Plugin Repository Name' + required: true + target-branch: + description: 'Target Branch' + default: master + required: false + url: + description: 'Plugin Binary URL' + required: false + vers: + description: 'Semantic Version Number' + required: false +jobs: + create_revision_pr: + runs-on: ubuntu-latest + name: Create Plugin Revision + + steps: + # Step 1: run a standard checkout action, provided by github + - name: Checkout HEAD + uses: actions/checkout@v2 + with: + ref: ${{ github.event.inputs.target-branch }} + + # Step 2: Echo inputs + - name: Read release information + id: plugin_info + env: + PLUGIN_NAME: ${{ github.event.inputs.repository }} + run: | + + if [ -z ${{ github.event.inputs.url }} ] + then + RELEASE=$(curl -s https://api.github.com/repos/${{ github.repository_owner }}/${PLUGIN_NAME}/releases/latest | grep tag_name | cut -d '"' -f 4) + URL=https://github.com/${{ github.repository_owner }}/${{ github.event.inputs.repository }}/archive/"${RELEASE}".zip + curl -LO -s $URL + CHKSUM=$(shasum -a 256 ${RELEASE}.zip | cut -d ' ' -f 1 ) + rm -f "${RELEASE}".zip + else + URL=${{ github.event.inputs.url }} + BINARY=$(basename $URL) + curl -LO -s $URL + CHKSUM=$(shasum -a 256 ${BINARY} | cut -d ' ' -f 1 ) + rm -f ${BINARY} + fi + if [ -z ${{ github.event.inputs.vers }} ] + then + VERS=$(echo $URL | awk 'match($0,/[0-9]+\.[0-9]+(\.[0-9]+)*/) {print substr($0,RSTART,RLENGTH)}') + else + VERS=${{ github.event.inputs.vers }} + fi + echo "${PLUGIN_NAME}" + JSON=$(cat ${PLUGIN_NAME}.json | jq '.[length -1]') + JSON=$(echo $JSON | jq --arg name "$PLUGIN_NAME" '. | .url|=$name ') + JSON=$(echo $JSON | jq --arg url "$URL" '. | .url|=$url ') + JSON=$(echo $JSON | jq --arg chksum "$CHKSUM" '. | .cksum|=$chksum ') + JSON=$(echo $JSON | jq --arg vers "$VERS" '. | .vers|=$vers ') + echo $JSON > item.json + UPDATED=$(jq '. += [input]' ${PLUGIN_NAME}.json item.json) + echo $UPDATED | jq . > ${PLUGIN_NAME}.json + rm item.json + git --no-pager diff + BRANCH="${PLUGIN_NAME}_${VERS}" + echo "::set-output name=branch::${BRANCH}" + echo "::set-output name=version::${VERS}" + - name: Create Pull Request + id: cpr + uses: peter-evans/create-pull-request@v3 + with: + delete-branch: true + branch-suffix: timestamp + title: Update ${{ github.event.inputs.repository }} to ${{ steps.plugin_info.outputs.version }} + body: | + Updating plugin `${{ github.event.inputs.repository }}` + - Auto-generated by [create-pull-request][1] + + [1]: https://github.com/peter-evans/create-pull-request + labels: | + automated PR + + - name: Check outputs + run: | + echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}" + echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"