I created a workflow file and the workflow is not showing up in the GitHub actions tab
name: AZ Deploy Workflow
on:
workflow_dispatch:
inputs:
deploy-environment:
description: 'Environment to deploy to'
required: true
default: 'dev'
image-tag:
description: 'Docker tag to deploy'
required: true
default: 'latest'
any ideas what's the issue.
Earlier I have added other workflow into the .github directory that shows in actions with no issue even if a put a empty file it does but not this one
Make sure your workflow is located in the default branch.
To run a workflow manually, the workflow must be configured to run on the workflow_dispatch event. To trigger the workflow_dispatch event, your workflow must be in the default branch. For more information about configuring the workflow_dispatch event, see "Events that trigger workflows".
For more details, see the Manually running a workflow and about the default branch.
UPD:
Testing it from a branch other than from the main branch can be done using the GitHub REST API:
curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/OWNER/REPO/actions/workflows/WORKFLOW_ID/dispatches \
-d '{"ref":"test-branch","inputs":{"deploy-environment":"dev","image-tag":"latest"}}'
You can replace WORKFLOW_ID with the workflow file name. For example, you could use main.yaml.
ref - your branch name.
For more details visit the official docs: Create a workflow dispatch event.
Related
In Github Actions is the following scenario possible
WORKFLOW1 workflow1.yaml ---> output x --> WORKFLOW2 workflow2.yaml
WORKFLOW1 Calculates a value x WORKFLOW2 Uses the calculated value x e.g (a +x) = total
which is output from previous WORKFLOW1
P.S The first run workflow1 should not be called again as the value of x may change.
Any tips would be highly appreciated
Thanks
I have tried reusable workflows but it seems to run the workflow which calculates a new value of x and runs the entire workflow 1 again which we don't want we just need the output of wf1 to be used in wf2
Thanks
An option could be to call the workflow 2 from the workflow 1 using a dispatch event.
The workflow 2 trigger implementation would look like this:
on:
workflow_dispatch:
inputs:
input_name:
description: "description"
required: true
You could send a dispatch event from the workflow 1 by using the Github API:
On the official Github Documentation, there is a service to create a workflow dispatch event
Here is a curl example:
- run: |
curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>"\ # if needed
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/OWNER/REPO/actions/workflows/WORKFLOW_ID/dispatches \
-d '{"ref":"main","inputs":{"input_name":"input_value"}}'
You can also find more references about this in this article.
I am creating a tag in a github action like so:
- name: create tag
uses: actions/github-script#v6.1.0
with:
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/tag_${{ env.tagname }}',
sha: context.sha
})
Once the tag is created, I can view it in the list of tags for the repo, and associated to it, there are two 'assets', namely both a zip and tar of the source code. I'd like to know if can also add a meta data text file to the assets. For example, I'd like to include in this meta data file, the name of the person who ran the workflow via workflow_dispatch that created the tag.
Thanks to #rethab for suggesting this API:
https://docs.github.com/en/rest/releases/assets#upload-a-release-asset
From it I have taken this code:
curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: token <TOKEN>" \
https://uploads.github.com/repos/OWNER/REPO/releases/RELEASE_ID/assets
However there is no place in the post request for me to put the file I am trying to upload. Where should I put this?
I have a workflow that is triggered when the pull request is labeled (via pull_request_target).
I would to automatically remove the label that triggered the analysis as the last step of that workflow.
How can I do that?
On Github: every pull request is an issue (but not every issue is a pull request).
You can find more informations about this on this stackoverflow answer.
Therefore, you could use the Github API to remove a (specific) label from an issue (or an action doing the same thing) as the last step of your workflow, using the PR number.
Here is the API on Github to remove label from issue (Official Documentation)
If you want to call it directly from the shell in your workflow with curl, it will looks like this:
curl \
-X DELETE \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/<owner>/<repo>/issues/<pr_number>/labels/<label_name>
GuiFalourd does indeed have the correct answer, but I did have to improve on it a bit.
If you want to use the workflow on a private repo, you do need to add an authorization token. Here's an example that uses GitHub context to populate everything besides the label name you want to delete:
curl --silent --fail-with-body \
-X DELETE \
-H 'Accept: application/vnd.github.v3+json' \
-H 'Authorization: token ${{ github.token }}' \
'https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.number }}/labels/YOUR-LABEL'
Also if your label has spaces, use %20 for the whitespace.
I want to pass some dynamic parameters and invoke my GitHub Actions workflow manually (ideally via some API). Is this possible?
With the workflow_dispatch event trigger, you can do the manual triggers easily.
Flow:
on:
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'warning'
tags:
description: 'Test scenario tags'
Manual trigger screenshot:
Blog post announcement reference, https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/
I think the correct answer to this is using a repository_dispatch NOT a workflow_dispatch.
Only repository dispatch allows you to trigger a workflow from an API call.
Docs
Hand Holding example
Summary:
URL Endpoint:
https://api.github.com/repos/{owner}/{repo}/dispatches
Example cURL call:
curl -X POST -H "Accept: application/vnd.github.v3+json" -H "authorization: Bearer <token>" https://api.github.com/repos/{owner}/{repo}/dispatches -d '{"event_type": "type1","client_payload": {"key1": "Hello from CRUD"}}'
To trigger a workflow_dispatch via API, the documentation can be found at https://docs.github.com/en/free-pro-team#latest/rest/reference/actions#create-a-workflow-dispatch-event
POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches
where {workflow_id} can also be the filename of the workflow (which makes things a lot easier).
An example curl from the documentation:
curl \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/actions/workflows/42/dispatches \
-d '{"ref":"ref"}'
I'm working on project, where I have two Git Repos:
Repo1 - DevRepo, Rep02- TestRepo
My Scenario is:
Whenever a commit or a PR happens on the Repo1:
Step1: Immediately Repo2 should be triggered
Step2: Once Step1 is success, Repo1 should be triggered.
Basically Repo1 should build only if Repo2 is run and it turns success.
Could someone please help me how I can set this up, much appreciated:
which .travis.yml file should I configure to meet my scenario.
exact configuration steps that I can write in my .travis.yml file
Answer: I got this working:
Trigger your dependent build: Repo2 by using the travis api:
Create a trigger_build.sh file and add this code:
`
body='{
"request": {
"branch":"master"
}}'
curl -s -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Travis-API-Version: 3" \
-H "Authorization: token ..git_hub_login_token.." \
-d "$body" \
https://api.travis-ci.org/repo/xxxx%2Fyyyy/requests
#The 15s sleep is to allow Travis to trigger the dependent build:
sleep 15`
Create a new or a separate get_build_status.sh file. Poll for the status of the dependent build. Based on the status of the Repo2 build, we will either continue building Repo1 or stop building Repo1:
# Polling for the Repo2 build status
# Setting a maximum time for the Repo2 build to run, however once we get the status to passed/failed, we will return to the Repo1 build run
`i=1
max=300
while [ $i -lt $max ]
do
echo "--------------------------------------------"
echo "Polling for the tests run build status..."`
curl -i -H "Accept: application/vnd.travis-ci.2+json" "https://api.travis-ci.org/repos/xxxx/yyyy/builds" > test.json
LATEST_STATE=$(grep -o '"state":.[a-z\"]*' test.json | head -1)
#LATEST_ID=$(grep -o '"id":.[0-9]*' test.json | head -1 | grep ':.[0-9]*')
get_state_value=${LATEST_STATE#*:}
STATE="${get_state_value//\"}"
if [ $STATE == "passed" ]
then
echo "TESTS RUN... $STATE :-) "
break #As soon as the Repo2 run pass, we break and return back to the Repo1 build run
elif [ $STATE == "failed" ]
then
echo "TESTS RUN... $STATE :-("
echo "Stop building elements"
exit 1 #As soon as the Repo2 run fail, we stop building Repo1
fi
true $(( i++ ))
sleep 1 #This 1s is required to poll the build status for every second
done
Your .travis.yml configuration:
script:
- chmod 777 ./trigger_build.sh
- chmod 777 ./get_build_status.sh
- ./trigger_build.sh
- ./get_build_status.sh
I've now built a CI service for this purpose. It lives here: https://github.com/cesium-ml/dependent_build_server
The above code basically does the following:
Wait for GitHub to let it know when a PR has changed
Use the Travis-CI API to trigger a build of the project, and insert two environment variables to describe which version of the code to build.
Listen for Travis-CI to report back, via webhook, the result of the build.
Use the GitHub API to report the new status to the PR.
Note: You have to verify the payloads that come from GitHub and Travis-CI. This is trivial for GitHub, but slightly harder for Travis-CI which uses proper key signing.
GitHub:
import hmac
def verify_signature(payload, signature, secret):
expected = 'sha1=' + hmac.new(secret.encode('ascii'),
payload, 'sha1').hexdigest()
return hmac.compare_digest(signature, expected)
Travis-CI:
from OpenSSL import crypto
def verify_signature(payload, signature):
# Get this by querying the Travis-CI config API
public_key = crypto.load_publickey(crypto.FILETYPE_PEM, pubkey)
certificate = crypto.X509()
certificate.set_pubkey(public_key)
try:
crypto.verify(certificate, signature, payload, 'sha1')
return True
except crypto.Error:
return False