yakshaveinc / linux

software engineering for Linux projects
The Unlicense
1 stars 3 forks source link

GitHub Actions test code to detect tags #44

Closed abitrolly closed 3 years ago

abitrolly commented 3 years ago

TL;DR: There are no tags in PRs, not possible.

For pushing commits to this PR.

ref: refs/heads/abitrolly-patch-1
event: Object
event_name: push
event,action: 

EDIT 20220711: Pull requests do not contain tags - https://stackoverflow.com/questions/12278660/adding-tags-to-a-pull-request/12279290#12279290

abitrolly commented 3 years ago

push --tags

ref: refs/tags/2103-actionstag
event: Object
event_name: push
event.action: 
abitrolly commented 3 years ago

Pushing tagged commit generates two push events.

image

No name of current branch though.

abitrolly commented 3 years ago

Output from git branch --contains ${{ github.sha }} --format "%(refname)" for non-tag commit.

refs/heads/abitrolly-patch-1

Now need to test this with PR from master on different repo.

abitrolly commented 3 years ago

Force pushing tag fails to find anything related to it.

>>> git branch --contains ...
(HEAD detached at 2103-actionstag)
>>> git reflog ...
Error: Process completed with exit code 1.
abitrolly commented 3 years ago

For non-tag push events.

>>> git branch --contains 526e80730a7484b612e2b83acc19dc453ab22f51 --format "%(refname)"
refs/heads/abitrolly-patch-1
>>> git reflog show --all | grep 526e807
526e807 refs/heads/abitrolly-patch-1@{0}: branch: Created from refs/remotes/origin/abitrolly-patch-1
526e807 refs/remotes/origin/abitrolly-patch-1@{0}: fetch --prune --progress --no-recurse-submodules origin +refs/heads/*:refs/remotes/origin/* +refs/tags/*:refs/tags/*: storing head
526e807 HEAD@{0}: checkout: moving from master to abitrolly-patch-1
abitrolly commented 3 years ago

For tag push event.

>>> git branch --contains 526e80730a7484b612e2b83acc19dc453ab22f51 --format "%(refname)"
(HEAD detached at 2103-actionstag)
>>> git reflog show --all | grep 526e807
526e807 refs/remotes/origin/abitrolly-patch-1@{0}: fetch --prune --progress --no-recurse-submodules origin +refs/heads/*:refs/remotes/origin/* +refs/tags/*:refs/tags/*: storing head
526e807 HEAD@{0}: checkout: moving from master to refs/tags/2103-actionstag
abitrolly commented 3 years ago

Opened a support ticket https://support.github.com/ticket/personal/0/1095257

abitrolly commented 3 years ago

Following support advise, dumping all github context (which can be insecure as it can expose token), the tag branch is present in event.base_ref only when the tag is pushed.

--- github.context_edit_online.json 2021-04-10 07:32:03.314827475 +0300
+++ github.context_push_tags.json   2021-04-10 07:37:48.152907387 +0300
@@ -1,13 +1,13 @@
 {
   "token": "***",
   "job": "name_or-jobid-no_spaces",
-  "ref": "refs/heads/abitrolly-patch-1",
+  "ref": "refs/tags/2104-actionstag",
   "sha": "1919fcf7f71e66259604ce017e3628a4b73e99ec",
   "repository": "yakshaveinc/linux",
   "repository_owner": "yakshaveinc",
   "repositoryUrl": "git://github.com/yakshaveinc/linux.git",
-  "run_id": "733487201",
-  "run_number": "44",
+  "run_id": "735159567",
+  "run_number": "45",
   "retention_days": "90",
   "actor": "abitrolly",
   "workflow": ".github/workflows/01hello.yaml",
@@ -16,30 +16,11 @@
   "event_name": "push",
   "event": {
     "after": "1919fcf7f71e66259604ce017e3628a4b73e99ec",
-    "base_ref": null,
-    "before": "b91b0b98daadfac199a14edbb1d17c993ccd07ab",
-    "commits": [
-      {
-        "author": {
-          "email": "anatoli@rainforce.org",
-          "name": "Anatoli Babenia",
-          "username": "abitrolly"
-        },
-        "committer": {
-          "email": "noreply@github.com",
-          "name": "GitHub",
-          "username": "web-flow"
-        },
-        "distinct": true,
-        "id": "1919fcf7f71e66259604ce017e3628a4b73e99ec",
-        "message": "Dump github.context",
-        "timestamp": "2021-04-09T18:18:31+03:00",
-        "tree_id": "b5b7c0a52571f8e1727567a01d25d31eb94c18e4",
-        "url": "https://github.com/yakshaveinc/linux/commit/1919fcf7f71e66259604ce017e3628a4b73e99ec"
-      }
-    ],
-    "compare": "https://github.com/yakshaveinc/linux/compare/b91b0b98daad...1919fcf7f71e",
-    "created": false,
+    "base_ref": "refs/heads/abitrolly-patch-1",
+    "before": "0000000000000000000000000000000000000000",
+    "commits": [],
+    "compare": "https://github.com/yakshaveinc/linux/compare/2104-actionstag",
+    "created": true,
     "deleted": false,
     "forced": false,
     "head_commit": {
@@ -78,7 +59,7 @@
       "email": "anatoli@rainforce.org",
       "name": "abitrolly"
     },
-    "ref": "refs/heads/abitrolly-patch-1",
+    "ref": "refs/tags/2104-actionstag",
     "repository": {
       "archive_url": "https://api.github.com/repos/yakshaveinc/linux/{archive_format}{/ref}",
       "archived": false,
@@ -165,9 +146,9 @@
       },
       "private": false,
       "pulls_url": "https://api.github.com/repos/yakshaveinc/linux/pulls{/number}",
-      "pushed_at": 1617981511,
+      "pushed_at": 1618029305,
       "releases_url": "https://api.github.com/repos/yakshaveinc/linux/releases{/id}",
-      "size": 170,
+      "size": 171,
       "ssh_url": "git@github.com:yakshaveinc/linux.git",
       "stargazers": 0,
       "stargazers_count": 0,
@@ -213,6 +194,7 @@
   "event_path": "/home/runner/work/_temp/_github_workflow/event.json",
   "action_repository": "",
   "action_ref": "",
-  "path": "/home/runner/work/_temp/_runner_file_commands/add_path_a3141d73-ffb8-4b21-9d06-2f83f2a2f5ff",
-  "env": "/home/runner/work/_temp/_runner_file_commands/set_env_a3141d73-ffb8-4b21-9d06-2f83f2a2f5ff"
+  "path": "/home/runner/work/_temp/_runner_file_commands/add_path_54180bdd-f171-4ae9-9b6d-fb44e0d02046",
+  "env": "/home/runner/work/_temp/_runner_file_commands/set_env_54180bdd-f171-4ae9-9b6d-fb44e0d02046"
 }
+
abitrolly commented 3 years ago

To detect if tag is processed - ${{ startsWith(github.ref, 'refs/tags/') }}.

abitrolly commented 3 years ago

The condition to run something only when a tag is pushed to master.

if: ${{ startsWith(github.ref, 'refs/tags/') && github.event.base_ref == 'ref/heads/master' }}
abitrolly commented 3 years ago

github.event.base_ref is non-empty only when releases are enabled.