From c2d7e3d9bc88aed665f04fae79e05fd104d226c7 Mon Sep 17 00:00:00 2001 From: Chl Date: Thu, 29 Aug 2024 02:14:55 +0200 Subject: [PATCH 01/12] Some minor improvements + starting to use CI/CD on itself --- .../workflows/generate-release-zipfile.yml | 35 +++++++++++++++++++ .github | 1 + README.md | 24 +++++++++++++ action.yml | 8 ++--- 4 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 .forgejo/workflows/generate-release-zipfile.yml create mode 120000 .github diff --git a/.forgejo/workflows/generate-release-zipfile.yml b/.forgejo/workflows/generate-release-zipfile.yml new file mode 100644 index 0000000..ad27c9f --- /dev/null +++ b/.forgejo/workflows/generate-release-zipfile.yml @@ -0,0 +1,35 @@ +on: + push: + +jobs: + GenerateReleaseZipfile: + runs-on: docker + container: + image: entrepot.xlii.si/actions/alpine-wget-git-zip:latest + steps: + - name: Generate some content + run: | + set -ex + mkdir toto + echo tata > toto/tata.txt + echo titi > toto/titi.txt + echo titi titi > "toto/titi titi.txt" + echo tutu > tutu.txt + echo tutu >> tutu.txt + echo tutuuuuu >> tutu2.txt + echo tutuuuuu >> "tutu tutu.txt" + echo ratata >> 'tutu tutu*.txt' + ls -R + + - name: Testing the artifact uploading + id: "uploading" + uses: "https://entrepot.xlii.si/actions/upload-artifact-with-wget@v4" + with: + path: | + toto + tutu* + + - name: Is there any output for the previous step ? + run: | + set -x + printf "steps.uploading.outputs.artifact-id: %s\n" "${{ steps.uploading.outputs.artifact-id }}" diff --git a/.github b/.github new file mode 120000 index 0000000..0db043d --- /dev/null +++ b/.github @@ -0,0 +1 @@ +.forgejo/ \ No newline at end of file diff --git a/README.md b/README.md index 218cf00..76d2950 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,14 @@ the artifact uploading required a full blown NodeJS container. This actions won't copy all the features of the original NodeJS version but please report differences on the main ones. +### Requirements + +This action needs the following executables: + +* zip (unless you zip the artifact yourself) +* wget (the full version : unfortunately, as of 2024-08-26, the busybox variant isn't capable of using the PUT method) + + ### Inputs ```yaml @@ -45,3 +53,19 @@ steps: name: my-artifact path: path/to/artifact/world.txt ``` + +## Miscellaneous + +If you seek a similar alternative for checkout, look at https://github.com/marketplace/actions/checkout-action or use the code below : +```yaml +steps: + - name: Simple checkout + run: | + git init + GITHUB_AUTHENTICATED_URL="$( echo "$GITHUB_SERVER_URL" | sed "s#^\(https\?://\)#\1$GITHUB_TOKEN\@#" )" + git remote add origin "$GITHUB_AUTHENTICATED_URL"/"$GITHUB_REPOSITORY" + # Little and optional speed optimization + git config --local gc.auto 0 + git fetch --no-tags --prune --no-recurse-submodules --depth=1 origin "$GITHUB_SHA" + git reset --hard "$GITHUB_SHA" +``` diff --git a/action.yml b/action.yml index 858b979..d676132 100644 --- a/action.yml +++ b/action.yml @@ -1,11 +1,11 @@ # SPDX-License-Identifier: 0BSD -name: "Upload artifact with wget" -author: "Chl " +name: "Upload an artifact with wget" +author: "Chl" description: | Upload an artifact for a workflow. - This is a far lighter version of upload-artifact, it only need a shell, zip + This is a lighter version of upload-artifact, it only needs a shell, zip and the full version of wget (unfortunately, as of 2024-08-26, the busybox variant isn't capable of using the PUT method). @@ -17,7 +17,7 @@ inputs: description: 'A file, directory or wildcard pattern that describes what to upload' required: true compression: - description: 'Set to false to upload the (already zipped) file directly. (default: true)' + description: 'Set to false to upload the (already zipped by yourself) file directly. (default: true)' default: true compression-level: description: 'The level of compression for Zlib to be applied to the artifact archive (between 0 and 9).' From 705e2d717c2cbf9e724d4ccd251a87c797fe2c56 Mon Sep 17 00:00:00 2001 From: Chl Date: Thu, 29 Aug 2024 02:27:22 +0200 Subject: [PATCH 02/12] Self CI/CD with download of the artifact --- .../workflows/generate-release-zipfile.yml | 31 ++++++++++++++++++- README.md | 4 +-- action.yml | 11 +++++-- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/.forgejo/workflows/generate-release-zipfile.yml b/.forgejo/workflows/generate-release-zipfile.yml index ad27c9f..74a4b2e 100644 --- a/.forgejo/workflows/generate-release-zipfile.yml +++ b/.forgejo/workflows/generate-release-zipfile.yml @@ -23,7 +23,7 @@ jobs: - name: Testing the artifact uploading id: "uploading" - uses: "https://entrepot.xlii.si/actions/upload-artifact-with-wget@v4" + uses: "${{ github.server_url }}/${{ github.repository }}@${{ github.sha }}" with: path: | toto @@ -33,3 +33,32 @@ jobs: run: | set -x printf "steps.uploading.outputs.artifact-id: %s\n" "${{ steps.uploading.outputs.artifact-id }}" + printf "steps.uploading.outputs.artifact-url: %s\n" "${{ steps.uploading.outputs.artifact-url }}" + + - name: Check the content of the uploaded artifact + run: | + # Stop at first error and be verbose + set -ex + + # Create some temporary files/directory + DOWNLOAD_FILE="$( mktemp )" + SHASUM_FILE="$( mktemp )" + TEST_ARTIFACT_DIR="$( mktemp -d )" + + # Get the fingerprint of our test + find . -type f -exec sha256sum \{\} \; > "$SHASUM_FILE" + # Little optional checkup + cat "$SHASUM_FILE" + + cd "$TEST_ARTIFACT_DIR" + # In case the repository becomes private, we add our GITHUB_TOKEN to the artifact-url. + MY_AUTHENTICATED_URL="$( echo "${{ steps.uploading.outputs.artifact-url }}" | sed "s#^\(https\?://\)#\1$GITHUB_TOKEN\@#" )" + wget -O "$DOWNLOAD_FILE" "$MY_AUTHENTICATED_URL" + unzip "$DOWNLOAD_FILE" + sha256sum -c "$SHASUM_FILE" + + # Cleanup + cd - + rm -f "$DOWNLOAD_FILE" + rm -f "$SHASUM_FILE" + rm -rf "$TEST_ARTIFACT_DIR" diff --git a/README.md b/README.md index 76d2950..c4ec43e 100644 --- a/README.md +++ b/README.md @@ -62,8 +62,8 @@ steps: - name: Simple checkout run: | git init - GITHUB_AUTHENTICATED_URL="$( echo "$GITHUB_SERVER_URL" | sed "s#^\(https\?://\)#\1$GITHUB_TOKEN\@#" )" - git remote add origin "$GITHUB_AUTHENTICATED_URL"/"$GITHUB_REPOSITORY" + MY_AUTHENTICATED_URL="$( echo "$GITHUB_SERVER_URL" | sed "s#^\(https\?://\)#\1$GITHUB_TOKEN\@#" )" + git remote add origin "$MY_AUTHENTICATED_URL"/"$GITHUB_REPOSITORY" # Little and optional speed optimization git config --local gc.auto 0 git fetch --no-tags --prune --no-recurse-submodules --depth=1 origin "$GITHUB_SHA" diff --git a/action.yml b/action.yml index d676132..0e76cfa 100644 --- a/action.yml +++ b/action.yml @@ -80,7 +80,7 @@ runs: # (note 2: if it fails here, it probably means you are using the busybox # variant of wget which can't (as of 2024-08-26) use the PUT method. # Install the full one beforehand : apt install wget / pkg add wget / ...) - wget --method PUT --body-file "$MYUPLOAD" "$SIGNED_UPLOAD_URL&comp=block" + wget -O /dev/null --method PUT --body-file "$MYUPLOAD" "$SIGNED_UPLOAD_URL&comp=block" # Finalize the artifact RESPONSE="$( wget -O - \ @@ -91,7 +91,14 @@ runs: )" # Store the outputs - echo artifact-id="$( echo "$RESPONSE" | sed -n 's/.*"artifactId" *: *"\([^"]\+\)".*/\1/p' )" >> $GITHUB_OUTPUT + ARTIFACT_ID="$( echo "$RESPONSE" | sed -n 's/.*"artifactId" *: *"\([^"]\+\)".*/\1/p' )" + echo artifact-id="$ARTIFACT_ID" >> $GITHUB_OUTPUT + if [ "$GITHUB_SERVER_URL" = "https://github.com" ]; then + echo artifact-url="$GITHUB_SERVER_URL"/"$GITHUB_REPOSITORY"/actions/runs/"$GITHUB_RUN_ID"/artifacts/"$ARTIFACT_ID" >> $GITHUB_OUTPUT + else + # Gitea & Forgejo : github.run_number instead of github.run_id and name of the artifact instead of artifact_id + echo artifact-url="$GITHUB_SERVER_URL"/"$GITHUB_REPOSITORY"/actions/runs/"$GITHUB_RUN_NUMBER"/artifacts/"$INPUT_NAME" >> $GITHUB_OUTPUT + fi # Cleanup if [ "${{ inputs.compression }}" == "true" ]; then From 9588309c74a4ee627686e06f11af8c0a0e45a1fb Mon Sep 17 00:00:00 2001 From: Chl Date: Thu, 29 Aug 2024 04:01:56 +0200 Subject: [PATCH 03/12] Update the readme --- .../workflows/generate-release-zipfile.yml | 2 +- README.md | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/.forgejo/workflows/generate-release-zipfile.yml b/.forgejo/workflows/generate-release-zipfile.yml index 74a4b2e..cebcdf9 100644 --- a/.forgejo/workflows/generate-release-zipfile.yml +++ b/.forgejo/workflows/generate-release-zipfile.yml @@ -37,7 +37,7 @@ jobs: - name: Check the content of the uploaded artifact run: | - # Stop at first error and be verbose + # Stop at first error and be verbose set -ex # Create some temporary files/directory diff --git a/README.md b/README.md index c4ec43e..4c7ede0 100644 --- a/README.md +++ b/README.md @@ -9,21 +9,23 @@ the artifact uploading required a full blown NodeJS container. ## Usage -This actions won't copy all the features of the original NodeJS version but +This action won't copy all the features of the original NodeJS version but please report differences on the main ones. ### Requirements This action needs the following executables: -* zip (unless you zip the artifact yourself) -* wget (the full version : unfortunately, as of 2024-08-26, the busybox variant isn't capable of using the PUT method) +* `zip` (unless you zip the artifact yourself) +* `wget` (the full version : unfortunately, as of 2024-08-26, the busybox variant isn't capable of using the PUT method) ### Inputs ```yaml -- uses: actions/upload-artifact@v4 +# If you can, give the full URL : +# - uses: https://entrepot.xlii.si/actions/upload-artifact-with-wget@v4 +- uses: actions/upload-artifact-with-wget@v4 with: # Name of the artifact to upload. # Optional. Default is 'artifact' @@ -32,6 +34,14 @@ This action needs the following executables: # A file, directory or wildcard pattern that describes what to upload # Required. path: + + # If the artifact is already a zipfile, set to false. + # Optional. Default is true. + compression: + + # Set the compression level of the zipfile. + # Optional. Default is '6'. + compression-level: ``` ### Outputs @@ -39,6 +49,7 @@ This action needs the following executables: | Name | Description | Example | | - | - | - | | `artifact-id` | GitHub ID of an Artifact, can be used by the REST API | `1234` | +| `artifact-url` | URL to download an Artifact. | `https://github.com/example-org/example-repo/actions/runs/1/artifacts/1234` or `https://codeberg.org/forgejo/forgejo/actions/runs/1/artifacts/my-artifact` | ## Examples From f430f71f1d7148777fa1c66e9ab686eb1e53f3f1 Mon Sep 17 00:00:00 2001 From: Chl Date: Fri, 30 Aug 2024 01:28:04 +0200 Subject: [PATCH 04/12] Github don't follow symlinks --- .github | 1 - .github/workflows/README.md | 2 + .../workflows/generate-release-zipfile.yml | 64 +++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) delete mode 120000 .github create mode 100644 .github/workflows/README.md create mode 100644 .github/workflows/generate-release-zipfile.yml diff --git a/.github b/.github deleted file mode 120000 index 0db043d..0000000 --- a/.github +++ /dev/null @@ -1 +0,0 @@ -.forgejo/ \ No newline at end of file diff --git a/.github/workflows/README.md b/.github/workflows/README.md new file mode 100644 index 0000000..fa0cc5f --- /dev/null +++ b/.github/workflows/README.md @@ -0,0 +1,2 @@ +As of 2024-08-30, Github actions is not capable of following symlinks :-/ +https://github.com/orgs/community/discussions/109744 diff --git a/.github/workflows/generate-release-zipfile.yml b/.github/workflows/generate-release-zipfile.yml new file mode 100644 index 0000000..74a4b2e --- /dev/null +++ b/.github/workflows/generate-release-zipfile.yml @@ -0,0 +1,64 @@ +on: + push: + +jobs: + GenerateReleaseZipfile: + runs-on: docker + container: + image: entrepot.xlii.si/actions/alpine-wget-git-zip:latest + steps: + - name: Generate some content + run: | + set -ex + mkdir toto + echo tata > toto/tata.txt + echo titi > toto/titi.txt + echo titi titi > "toto/titi titi.txt" + echo tutu > tutu.txt + echo tutu >> tutu.txt + echo tutuuuuu >> tutu2.txt + echo tutuuuuu >> "tutu tutu.txt" + echo ratata >> 'tutu tutu*.txt' + ls -R + + - name: Testing the artifact uploading + id: "uploading" + uses: "${{ github.server_url }}/${{ github.repository }}@${{ github.sha }}" + with: + path: | + toto + tutu* + + - name: Is there any output for the previous step ? + run: | + set -x + printf "steps.uploading.outputs.artifact-id: %s\n" "${{ steps.uploading.outputs.artifact-id }}" + printf "steps.uploading.outputs.artifact-url: %s\n" "${{ steps.uploading.outputs.artifact-url }}" + + - name: Check the content of the uploaded artifact + run: | + # Stop at first error and be verbose + set -ex + + # Create some temporary files/directory + DOWNLOAD_FILE="$( mktemp )" + SHASUM_FILE="$( mktemp )" + TEST_ARTIFACT_DIR="$( mktemp -d )" + + # Get the fingerprint of our test + find . -type f -exec sha256sum \{\} \; > "$SHASUM_FILE" + # Little optional checkup + cat "$SHASUM_FILE" + + cd "$TEST_ARTIFACT_DIR" + # In case the repository becomes private, we add our GITHUB_TOKEN to the artifact-url. + MY_AUTHENTICATED_URL="$( echo "${{ steps.uploading.outputs.artifact-url }}" | sed "s#^\(https\?://\)#\1$GITHUB_TOKEN\@#" )" + wget -O "$DOWNLOAD_FILE" "$MY_AUTHENTICATED_URL" + unzip "$DOWNLOAD_FILE" + sha256sum -c "$SHASUM_FILE" + + # Cleanup + cd - + rm -f "$DOWNLOAD_FILE" + rm -f "$SHASUM_FILE" + rm -rf "$TEST_ARTIFACT_DIR" From dbfd979bf4f44510002de8014fd53af9ec707bde Mon Sep 17 00:00:00 2001 From: Chl Date: Sat, 31 Aug 2024 01:56:44 +0200 Subject: [PATCH 05/12] Trying some compatibility with Github Just for the fun of it (it was kinda interesting but not sure the motivation is enough in the long run...) --- .github/workflows/README.md | 2 - .../workflows/generate-release-zipfile.yml | 52 +++++++++++++++---- action.yml | 48 +++++++++++++---- 3 files changed, 80 insertions(+), 22 deletions(-) delete mode 100644 .github/workflows/README.md diff --git a/.github/workflows/README.md b/.github/workflows/README.md deleted file mode 100644 index fa0cc5f..0000000 --- a/.github/workflows/README.md +++ /dev/null @@ -1,2 +0,0 @@ -As of 2024-08-30, Github actions is not capable of following symlinks :-/ -https://github.com/orgs/community/discussions/109744 diff --git a/.github/workflows/generate-release-zipfile.yml b/.github/workflows/generate-release-zipfile.yml index 74a4b2e..698a6c2 100644 --- a/.github/workflows/generate-release-zipfile.yml +++ b/.github/workflows/generate-release-zipfile.yml @@ -3,9 +3,9 @@ on: jobs: GenerateReleaseZipfile: - runs-on: docker - container: - image: entrepot.xlii.si/actions/alpine-wget-git-zip:latest + runs-on: ubuntu-latest + # Trying to help access to the artifact with the GITHUB_TOKEN at the last step but didn't help. + #permissions: read-all steps: - name: Generate some content run: | @@ -18,18 +18,36 @@ jobs: echo tutu >> tutu.txt echo tutuuuuu >> tutu2.txt echo tutuuuuu >> "tutu tutu.txt" - echo ratata >> 'tutu tutu*.txt' + # Github doesn't like special characters. + #echo ratata >> 'tutu tutu*.txt' ls -R + - name: "Github requires checkout for 'uses: ./' (or we could hard write the repository's URL ?)" + run: | + mkdir myaction && cd myaction + git init + test -z "$GITHUB_TOKEN" && GITHUB_TOKEN="${{ github.token }}" + MY_AUTHENTICATED_URL="$( echo "$GITHUB_SERVER_URL" | sed "s#^\(https\?://\)#\1$GITHUB_TOKEN\@#" )" + git remote add origin "$MY_AUTHENTICATED_URL"/"$GITHUB_REPOSITORY" + # Little and optional speed optimization + git config --local gc.auto 0 + git fetch --no-tags --prune --no-recurse-submodules --depth=1 origin "$GITHUB_SHA" + git reset --hard "$GITHUB_SHA" + - name: Testing the artifact uploading id: "uploading" - uses: "${{ github.server_url }}/${{ github.repository }}@${{ github.sha }}" + uses: ./myaction + # For comparison + #uses: actions/upload-artifact@v4 with: path: | toto tutu* - - name: Is there any output for the previous step ? + - name: "Cleanup Github" + run: rm -rvf myaction + + - name: Is there any output for the uploading step ? run: | set -x printf "steps.uploading.outputs.artifact-id: %s\n" "${{ steps.uploading.outputs.artifact-id }}" @@ -37,7 +55,7 @@ jobs: - name: Check the content of the uploaded artifact run: | - # Stop at first error and be verbose + # Stop at first error and be verbose set -ex # Create some temporary files/directory @@ -52,8 +70,24 @@ jobs: cd "$TEST_ARTIFACT_DIR" # In case the repository becomes private, we add our GITHUB_TOKEN to the artifact-url. - MY_AUTHENTICATED_URL="$( echo "${{ steps.uploading.outputs.artifact-url }}" | sed "s#^\(https\?://\)#\1$GITHUB_TOKEN\@#" )" - wget -O "$DOWNLOAD_FILE" "$MY_AUTHENTICATED_URL" + test -z "$GITHUB_TOKEN" && GITHUB_TOKEN="${{ github.token }}" + # TODO : can't get it to work :-/ + #wget --header "Authorization: Bearer $GITHUB_TOKEN" -O "$DOWNLOAD_FILE" "${{ steps.uploading.outputs.artifact-url }}" + + # Oh boy... We're gone beyond salvation but let's try to explain: + # - the api.github.com accepts the GITHUB_TOKEN in the Authorization + # header (but not the ACTIONS_RUNTIME_TOKEN, nor the GITHUB_TOKEN as + # part of the URL like https://$GITHUB_TOKEN@api.github.com/...) + # - ...but we get redirect to Windows.net/Azure data warehouse which refuses GITHUB_TOKEN... + # -> so, if the api.github.com fails, we try to extract the redirect location and hit it without any header. + # ('beginning to wonder if Github's changing master to main was also a part of a plot to complexify our lives...) + WGET_OUTPUT="$( wget -O "$DOWNLOAD_FILE" \ + --header "Authorization: Bearer $GITHUB_TOKEN" \ + "https://api.github.com/repos/$GITHUB_REPOSITORY/actions/artifacts/${{ steps.uploading.outputs.artifact-id }}/zip" 2>&1 )" \ + || wget -O "$DOWNLOAD_FILE" \ + "$( echo "$WGET_OUTPUT" | sed -n 's/^Location: \(.*\) \[following\]/\1/p' | tail -n 1 )" + + # unzip and check unzip "$DOWNLOAD_FILE" sha256sum -c "$SHASUM_FILE" diff --git a/action.yml b/action.yml index 0e76cfa..8b815d1 100644 --- a/action.yml +++ b/action.yml @@ -25,21 +25,38 @@ inputs: outputs: artifact-id: - description: A unique identifier for the artifact that was just uploaded. Empty if the artifact upload failed. + description: A unique identifier for the artifact that was just uploaded. + value: ${{ steps.uploading.outputs.artifact-id }} + artifact-url: + description: The URL for the uploaded artifact. Access may require authorization. + value: ${{ steps.uploading.outputs.artifact-url }} runs: using: 'composite' steps: + # ACTIONS_RUNTIME_TOKEN is not yet available (2024-08) for composite actions on Github : + # https://github.com/actions/runner/issues/3046 + # Forgejo tries to download this remote action even if it's not needed : + # uncomment if you want to run this action in Github. + #- name: Expose GitHub Runtime + # if: env.ACTIONS_RUNTIME_TOKEN == '' + # uses: "https://github.com/crazy-max/ghaction-github-runtime@v3" + - name: Upload artifact (using v4) shell: sh + # id for reference in the outputs extraction + id: uploading run: | # Some optional help for debugging. set -ex + # Compatibility layer for Github + test -z "$GITHUB_TOKEN" && GITHUB_TOKEN="${{ github.token }}" + # Compress the input paths into a zip archive # (note: busybox' mktemp doesn't have the --suffix option) MYUPLOAD="$( mktemp -u ).zip" - if [ "${{ inputs.compression }}" == "true" ]; then + if [ "${{ inputs.compression }}" = "true" ]; then # inputs.path can be a list of files (with wildcards and spaces) and # the shell's command substitution + field splitting + pathname # expansion gives a behaviour pretty close to the original Github's @@ -64,36 +81,45 @@ runs: $( echo "$ACTIONS_RUNTIME_TOKEN" | sed 's/.*\.\(.*\)\..*/\1/' | base64 -d 2>/dev/null | sed 's/.*Actions.Results:\([^:]\+\):\([^:" ]\+\).*/\1 \2/' ) EOF + # Github compatibility layer: ACTIONS_RESULTS_URL already ends with a '/' + ACTIONS_RESULTS_URL="$( echo "$ACTIONS_RESULTS_URL" | sed 's/\/$//' )" + # Request an upload URL RESPONSE="$( wget -O - \ --header 'Content-Type:application/json' \ - --header "Authorization: Bearer $GITHUB_TOKEN" \ + --header "Authorization: Bearer $ACTIONS_RUNTIME_TOKEN" \ --post-data "$( printf '{"version":4, "name":"%s", "workflow_run_backend_id":"%s", "workflow_job_run_backend_id":"%s"}' "${{ inputs.name }}" "$WORKFLOW_RUN_BACKEND_ID" "$WORKFLOW_JOB_RUN_BACKEND_ID" )" \ - "$GITHUB_SERVER_URL"/twirp/github.actions.results.api.v1.ArtifactService/CreateArtifact + "$ACTIONS_RESULTS_URL"/twirp/github.actions.results.api.v1.ArtifactService/CreateArtifact )" # We get a JSON with an signedUploadUrl similar to : # https://entrepot.xlii.si/twirp/github.actions.results.api.v1.ArtifactService/UploadArtifact?sig=yWWEI8tIIECp8D7E5TVh4_6G2pZxWaVdQcSYaCsx5s0=&expires=2024-08-26+07%3A20%3A49.886890537+%2B0200+CEST&artifactName=mymodule-1.2.3.zip&taskID=63 - SIGNED_UPLOAD_URL="$( echo "$RESPONSE" | sed -n 's/.*"signedUploadUrl" *: *"\([^"]\+\)".*/\1/p' )" + SIGNED_UPLOAD_URL="$( echo "$RESPONSE" | sed -n 's/.*"signed_\?[uU]pload_\?[uU]rl" *: *"\([^"]\+\)".*/\1/p' )" # Upload our file - # (note: adding '&comp=block' at the end of the URL) + # (note: adding '&comp=block' at the end of the URL for Forgejo) # (note 2: if it fails here, it probably means you are using the busybox # variant of wget which can't (as of 2024-08-26) use the PUT method. # Install the full one beforehand : apt install wget / pkg add wget / ...) - wget -O /dev/null --method PUT --body-file "$MYUPLOAD" "$SIGNED_UPLOAD_URL&comp=block" + wget -O /dev/null \ + --method PUT \ + --body-file "$MYUPLOAD" \ + --header "x-ms-blob-content-type: zip" \ + --header "x-ms-blob-type: BlockBlob" \ + "$SIGNED_UPLOAD_URL&comp=block" # Finalize the artifact RESPONSE="$( wget -O - \ --header 'Content-Type:application/json' \ - --header "Authorization: Bearer $GITHUB_TOKEN" \ + --header "Authorization: Bearer $ACTIONS_RUNTIME_TOKEN" \ --post-data "$( printf '{"hash":"sha256:%s", "name":"%s", "size":"%d", "workflow_run_backend_id":"%s", "workflow_job_run_backend_id":"%s"}' "$( sha256sum $MYUPLOAD | sed 's/[[:space:]]\+.*//' )" "${{ inputs.name }}" "$( stat -c %s $MYUPLOAD )" "$WORKFLOW_RUN_BACKEND_ID" "$WORKFLOW_JOB_RUN_BACKEND_ID" )" \ - "$GITHUB_SERVER_URL"/twirp/github.actions.results.api.v1.ArtifactService/FinalizeArtifact + "$ACTIONS_RESULTS_URL"/twirp/github.actions.results.api.v1.ArtifactService/FinalizeArtifact )" # Store the outputs - ARTIFACT_ID="$( echo "$RESPONSE" | sed -n 's/.*"artifactId" *: *"\([^"]\+\)".*/\1/p' )" + ARTIFACT_ID="$( echo "$RESPONSE" | sed -n 's/.*"artifact_\?Id" *: *"\([^"]\+\)".*/\1/ip' )" echo artifact-id="$ARTIFACT_ID" >> $GITHUB_OUTPUT if [ "$GITHUB_SERVER_URL" = "https://github.com" ]; then + # note: as an alternative, there is https://api.github.com/repos/OWNER/REPO/actions/artifacts/ARTIFACT_ID echo artifact-url="$GITHUB_SERVER_URL"/"$GITHUB_REPOSITORY"/actions/runs/"$GITHUB_RUN_ID"/artifacts/"$ARTIFACT_ID" >> $GITHUB_OUTPUT else # Gitea & Forgejo : github.run_number instead of github.run_id and name of the artifact instead of artifact_id @@ -101,6 +127,6 @@ runs: fi # Cleanup - if [ "${{ inputs.compression }}" == "true" ]; then + if [ "${{ inputs.compression }}" = "true" ]; then rm -f "$MYUPLOAD" fi From 9075262e0ed8481e3c957ac472e9440be4af7b5c Mon Sep 17 00:00:00 2001 From: Chl Date: Sat, 31 Aug 2024 02:18:51 +0200 Subject: [PATCH 06/12] Github doesn't like the &comp=block --- action.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 8b815d1..11c39b6 100644 --- a/action.yml +++ b/action.yml @@ -100,12 +100,15 @@ runs: # (note 2: if it fails here, it probably means you are using the busybox # variant of wget which can't (as of 2024-08-26) use the PUT method. # Install the full one beforehand : apt install wget / pkg add wget / ...) + if [ "$GITHUB_SERVER_URL" != "https://github.com" ]; then + SIGNED_UPLOAD_URL="$SIGNED_UPLOAD_URL&comp=block" + fi wget -O /dev/null \ --method PUT \ --body-file "$MYUPLOAD" \ --header "x-ms-blob-content-type: zip" \ --header "x-ms-blob-type: BlockBlob" \ - "$SIGNED_UPLOAD_URL&comp=block" + "$SIGNED_UPLOAD_URL" # Finalize the artifact RESPONSE="$( wget -O - \ From 8730db6b4901545c329f3f980f6029bf05ec1e7d Mon Sep 17 00:00:00 2001 From: Chl Date: Sat, 31 Aug 2024 02:41:33 +0200 Subject: [PATCH 07/12] Only trigger the workflow when pushing a branch --- .forgejo/workflows/generate-release-zipfile.yml | 1 + .github/workflows/generate-release-zipfile.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.forgejo/workflows/generate-release-zipfile.yml b/.forgejo/workflows/generate-release-zipfile.yml index cebcdf9..8aca51f 100644 --- a/.forgejo/workflows/generate-release-zipfile.yml +++ b/.forgejo/workflows/generate-release-zipfile.yml @@ -1,5 +1,6 @@ on: push: + branches: jobs: GenerateReleaseZipfile: diff --git a/.github/workflows/generate-release-zipfile.yml b/.github/workflows/generate-release-zipfile.yml index 698a6c2..dea9fa2 100644 --- a/.github/workflows/generate-release-zipfile.yml +++ b/.github/workflows/generate-release-zipfile.yml @@ -1,5 +1,6 @@ on: push: + branches: jobs: GenerateReleaseZipfile: From e21efb3c3cd0a74d0cc6269993192fe7dfc51590 Mon Sep 17 00:00:00 2001 From: Chl Date: Sat, 31 Aug 2024 02:48:52 +0200 Subject: [PATCH 08/12] readme: compatibility with Github --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 4c7ede0..f056d6f 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,8 @@ steps: - name: Simple checkout run: | git init + # On Github, the token isn't readily available. + test -z "$GITHUB_TOKEN" && GITHUB_TOKEN="${{ github.token }}" MY_AUTHENTICATED_URL="$( echo "$GITHUB_SERVER_URL" | sed "s#^\(https\?://\)#\1$GITHUB_TOKEN\@#" )" git remote add origin "$MY_AUTHENTICATED_URL"/"$GITHUB_REPOSITORY" # Little and optional speed optimization From 61b070edf9da68610d15a8e98ec23f3642db49da Mon Sep 17 00:00:00 2001 From: Chl Date: Sat, 31 Aug 2024 02:35:31 +0200 Subject: [PATCH 09/12] Github's marketplace: Description must be less than 125 characters --- action.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index 11c39b6..0c7f988 100644 --- a/action.yml +++ b/action.yml @@ -3,11 +3,10 @@ name: "Upload an artifact with wget" author: "Chl" description: | - Upload an artifact for a workflow. + Upload an artifact. This is a lighter version of upload-artifact, it only needs a shell, zip - and the full version of wget (unfortunately, as of 2024-08-26, the busybox - variant isn't capable of using the PUT method). + and the full version of wget. inputs: name: From 9c77c2641a3beaa72ab74a150abe030a1a4118bf Mon Sep 17 00:00:00 2001 From: Chl Date: Sat, 31 Aug 2024 02:53:39 +0200 Subject: [PATCH 10/12] Branding for Github's marketplace --- action.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/action.yml b/action.yml index 0c7f988..dc5daea 100644 --- a/action.yml +++ b/action.yml @@ -8,6 +8,10 @@ description: | This is a lighter version of upload-artifact, it only needs a shell, zip and the full version of wget. +branding: + icon: archive + color: gray-dark + inputs: name: description: 'Artifact name' From 67ac8517dbd3727919861c17097159d973305a34 Mon Sep 17 00:00:00 2001 From: Chl Date: Sat, 31 Aug 2024 03:23:58 +0200 Subject: [PATCH 11/12] Fixup workflow trigger on Forgejo --- .forgejo/workflows/generate-release-zipfile.yml | 3 +++ .github/workflows/generate-release-zipfile.yml | 3 +++ 2 files changed, 6 insertions(+) diff --git a/.forgejo/workflows/generate-release-zipfile.yml b/.forgejo/workflows/generate-release-zipfile.yml index 8aca51f..aa310b4 100644 --- a/.forgejo/workflows/generate-release-zipfile.yml +++ b/.forgejo/workflows/generate-release-zipfile.yml @@ -1,6 +1,9 @@ on: push: branches: + # Difference between Github and Forgejo : with the former, an empty + # 'branches' key means "nothing" while the later understands it as "all". + - '*' jobs: GenerateReleaseZipfile: diff --git a/.github/workflows/generate-release-zipfile.yml b/.github/workflows/generate-release-zipfile.yml index dea9fa2..f623648 100644 --- a/.github/workflows/generate-release-zipfile.yml +++ b/.github/workflows/generate-release-zipfile.yml @@ -1,6 +1,9 @@ on: push: branches: + # Difference between Github and Forgejo : with the former, an empty + # 'branches' key means "nothing" while the later understands it as "all". + #- '*' jobs: GenerateReleaseZipfile: From 17f9610281213aad1c77d24e216b42e3143a20b9 Mon Sep 17 00:00:00 2001 From: Chl Date: Sat, 31 Aug 2024 15:24:08 +0200 Subject: [PATCH 12/12] Stopping the mixing -> clear separation Forgejo/Github This action is even less useful in Github than in Forgejo/Gitea so let's stop wasting time and clearly label with a suffix 'v4.x.y-github' for Github. --- .forgejo/workflows/generate-release-zipfile.yml | 6 +++--- .github/workflows/generate-release-zipfile.yml | 4 +--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.forgejo/workflows/generate-release-zipfile.yml b/.forgejo/workflows/generate-release-zipfile.yml index aa310b4..1244e55 100644 --- a/.forgejo/workflows/generate-release-zipfile.yml +++ b/.forgejo/workflows/generate-release-zipfile.yml @@ -1,9 +1,7 @@ on: push: branches: - # Difference between Github and Forgejo : with the former, an empty - # 'branches' key means "nothing" while the later understands it as "all". - - '*' + - 'v4' jobs: GenerateReleaseZipfile: @@ -58,6 +56,8 @@ jobs: # In case the repository becomes private, we add our GITHUB_TOKEN to the artifact-url. MY_AUTHENTICATED_URL="$( echo "${{ steps.uploading.outputs.artifact-url }}" | sed "s#^\(https\?://\)#\1$GITHUB_TOKEN\@#" )" wget -O "$DOWNLOAD_FILE" "$MY_AUTHENTICATED_URL" + + # unzip and check unzip "$DOWNLOAD_FILE" sha256sum -c "$SHASUM_FILE" diff --git a/.github/workflows/generate-release-zipfile.yml b/.github/workflows/generate-release-zipfile.yml index f623648..d5bbfc1 100644 --- a/.github/workflows/generate-release-zipfile.yml +++ b/.github/workflows/generate-release-zipfile.yml @@ -1,9 +1,7 @@ on: push: branches: - # Difference between Github and Forgejo : with the former, an empty - # 'branches' key means "nothing" while the later understands it as "all". - #- '*' + - 'v4-github' jobs: GenerateReleaseZipfile: