github actions workflow workflow_dispatch running a workflow manually - most of the Tags are disabled - continuous-integration

I am using github actions workflow for code deployment. One of the flow is manual using workflow_dispatch. I am able to select main or any feature branch but when i select tags - most of them are disabled and gives you below error message:
"Workflow does not exist or does not have a workflow_dispatch trigger in this tag.
Learn more about manual workflows"
If I create a new git tag, i am able to deploy. Please help me by sharing the logic and reasoning. Thanks,

If workflow didn't exist when the tag was created, it's not available. The same goes for branches.
The way to fix it is to either cherry-pick workflow there and move a tag or re-base the tag on top of the master branch.
Also keep in mind if you modify workflow on your master branch, but you have a different version in branches - it will use the branch / tag version.
If you want to keep 1 version across all tags - you should pass a tag as an input variable and run it on master branch instead of running workflow on this tag. Then you just have to modify your checkout-action to checkout the passed tag, not leaving it with defaults.

Related

Can I use a GitHub Action to patch pull requests before running validating actions?

When a collaborator creates/updates a pull request against my repository's default branch I want two things to happen in a specific order:
Automatic code formatting + commit formatting changes to the PR branch
Run code quality tests and unit tests
If tests complete without errors the default branch's branch protection rules should allow merging.
The problem is that when step 1 completes, the current workflows are now invalid since there is a new commit on the PR branch. Because of this, the results of the tests can not validate the PR, rendering the PR impossible to merge.
Step no. 1 does not trigger another round of Actions since it was committed and pushed by an Action itself and that behavior would just create an endless loop of Actions anyways.
What I want is a way to run step no. 1 automatically before anything else happens so that simple warnings get squashed without developers having to do anything manually.
I am trying to avoid doing this through pre-commit hooks since that would require developers to manually set up their environments the same way.
How can I create the flow I am describing by using GitHub Actions?
Since we don't have the actual action script I can only assume what steps it performs, and in what order (see the details under TL;DR).
The true issue is that your action is failing the separation of concerns principle, i.e. it is doing validation (code quality analysis, read-only) as it should, but it is also doing modification (code formatting correction).
Code formatting is, in general, a task more suited for a pre-commit or pre-push hook instead. If badly formatted code does get pushed, code formatting check should fail the build instead of auto-correcting it.
TL;DR
A simplified example... The origin repository is github.com/example/app, the pull request is for the branch new-feature, and the action looks something like this:
steps:
- name: Checkout repository (1)
uses: actions/checkout
- name: Check code formatting (2)
run: run-lint -autofix && git add . && git commit "formatted"
- name: Run tests and check code quality (3)
run: run-tests && run-sonar
- name: Merge it (4)
...
When a contributor pushes changes to the new-feature branch a build will be triggered, and it will be done by e.g. GitHub's build-bot-42.
The build-bot-42 will go through the action's steps in order:
(1) get a copy of the code in question onto itself - build-bot-42 is not the same computer as the one storing GitHub's git repository. The checkout action will basically do the following:
cd ${unique-temp-dir}
git init
git fetch --all
git checkout origin/new-feature
(2) run a lint tool in auto-correct mode, and then apply the changes in a git commit.
(3) run tests and the static code analysis.
If all checks pass we have a local git repository ready to be merged and pushed to origin (in that order).
Of course, if the tests and/code quality don't pass the pull request still has the badly formatted code because the action didn't push the code formatting changes.

how to trigger github action workflow by creating tags only from main branch?

Right now if we are creating a tag with any branch, our action workflow starts running. we want to trigger action workflow only if we create a tag from the main branch.
my current YAML file looks like below. let us know what needs to be changed here
on:
push:
tags:
- '*'

In GitLab API, how do I set merge commit message for merge requests?

I have a few different CI/CD flows, one of them automatically creates GitLab merge requests for specific branches. Each merge request has a generated description and title, with links to resolved issues, etc. After merge request is merged, GitLab creates a merge commit with default schema, and it looks like this:
Merge branch '<my branch>' into '<my other branch>'
<Title of merge request>
See merge request <number of merge request>
I'd like this merge commit to be diffferent, and contain merge request description only, since CD should use it to generate changelogs for each build. I've tried to find an option to change it in GitLab API, but I can't find any parameter or request that would allow me to set merge commit message when it's created, or change it afterwards.
Is there any way to copy merge request description to merge commit body automatically? Maybe some API fields, or templates that can be used?
Based on this issue that’s been open for three years, that functionality isn’t even in the UI so an API operation for it most likely wouldn’t exist until that does. https://gitlab.com/gitlab-org/gitlab/-/issues/2551
Your best option until then is to use git:
Clone the repo
Rebase and reword the commit message
Push it back to the remote

Google Cloud Build - Github Trigger - Filter Files Don't Work

When Github Trigger is set to listen a tag the files filter is ignored and the trigger is set on every push
I have tried different settings on multiple triggers and nothing works
I've tried using a path like this packages/backend-node/src/* and didn't work either
I noticed something similar but found the following in the docs:
If you push a change to a newly created branch, then Cloud Build
treats all the files in the repository as changed files.
So pushing a new branch to your repo will always trigger your build and ignore the file filters.
Source: https://cloud.google.com/build/docs/automating-builds/create-manage-triggers#build_trigger (the link no longer includes the quote from above)
Open bug report in google's issue tracker: https://issuetracker.google.com/issues/217776771

Get all VCS changes between previous and current build

How can I get all VCS changes between previous and current build? I need to get all commit messages of current branch in one of build steps.
You can get all changes, included in current build, via TeamCity REST API. Just make GET request to url
http://teamcity:8111/app/rest/changes?locator=build:(id:<buildId>)
More details available in the documentation

Resources