moodlehq / moodle-plugin-release

Template for GitHub Actions YAML file allowing to automatically release tagged version in the Moodle Plugins directory
GNU General Public License v3.0
15 stars 4 forks source link

What is the aim of TAGNAME? #1

Closed scara closed 3 years ago

scara commented 3 years ago

Hi @mudrd8mz, thanks for releasing such a great opportunity with both this GH workflow and the new Plugins directory API! šŸš€ šŸ‘

I do not try it yet, just looked at the code of the workflow. What is the aim of TAGNAME? It looks like being never used. And why defining a default value for ZIPURL? It will be always evaluated regardless being previously defined.

Besides GITHUB_REF is the "long" branch (or tag) ref e.g. refs/heads/feature-branch-1 which is available even via the context github.ref.

Guessing that if there's no tag name - e.g. some wrong changes in the current triggering schema - , no release should happen into the Moodle Plugin Registry. From my understanding the current setup will be triggered:

  1. automatically, when pushing a tag starting with v
  2. manually, when the user run the workflow providing the tag by her/himself - available in GHA via github.event.inputs.tag

The workflow looks like working properly on just the second triggering event. I'm thinking to propose something like the diff below:

$ git diff
diff --git a/moodle-release.yml b/moodle-release.yml
index 3f4b2bb..c93c0b6 100644
--- a/moodle-release.yml
+++ b/moodle-release.yml
@@ -51,10 +51,14 @@ jobs:
         run: |
           if [[ ! -z "${{ github.event.inputs.tag }}" ]]; then
             TAGNAME="${{ github.event.inputs.tag }}"
-          else
-            ZIPURL="${GITHUB_REF}"
+          elif [[ $GITHUB_REF = refs/tags/* ]]; then
+            TAGNAME="${GITHUB_REF##*/}"
           fi
-          ZIPURL="https://api.github.com/repos/${{ github.repository }}/zipball/${{ github.event.inputs.tag }}"
+          if [[ -z "${TAGNAME}" ]]; then
+            echo "No tag name has been provided!"
+            exit 1
+          fi
+          ZIPURL="https://api.github.com/repos/${{ github.repository }}/zipball/${TAGNAME}"
           RESPONSE=$(${CURL} ${ENDPOINT_REST} --data "wstoken=${TOKEN}&wsfunction=${FUNCTION}&moodlewsrestformat=json&frankenstyle=${PLUGIN}&zipurl=${ZIPURL}")
           echo "::set-output name=response::${RESPONSE}"

What do you think?

TIA, Matteo

mudrd8mz commented 3 years ago

Yup, it seems I did screw it a bit while debugging. I am surprised though that it worked for both cases for me ... Let me check it tomorrow with fresh head. Thanks!

mudrd8mz commented 3 years ago

OK. Now I can see what mistake I did and why it still worked (or seemed to work).

My original intention was to populate the value of TAGNAME as either coming from the user input (when the workflow is triggered manually) or from GITHUB_REF (when the workflow is triggered by pushing a new tag). Then use this value to populate the ZIPURL and use it as a parameter.

My current script has three bugs actually:

tl;dr: Exactly what @scara correctly reports here :-)

The reason why it still seemed to work was that when you use the URL https://api.github.com/repos/USERNAME/REPONAME/zipball/ without the optional trailing REF part, it uses the head of the default branch - which by co-incidence was the meant tag in my case (https://docs.github.com/en/rest/reference/repos#download-a-repository-archive-zip)

Looking at the submitted pull request now.