GitHub workflow restriction - github

I have deployment action in my GitHub workflow.
I want to restrict this action trigger to the master branch only.
Here is a piece of workflow config:
on:
release:
branches:
- master
types:
- released
But when I'm publishing pre-release for any branch in my project it hits workflow immediately.
What's wrong with it? Please advice.
Tnx!

Related

Github Actions: Deploy main branch to protected environment after pull request is merged

In our github repository, we have set up a protected environment named Sandbox, for which the main branch is the only allowed deployment branch. Now we want to deploy automatically to that environment if a pullrequest is merged into main (and the if the pullrequest in addition bears the label "Sandbox").
Our workflow is roughly as follows:
name: Pull Request Merged
concurrency:
group: ${{ github.ref }}
on:
pull_request:
types: [closed]
jobs:
deploy_to_sandbox:
if: |
github.event.pull_request.merged == true &&
contains(github.event.pull_request.labels.*.name, 'Sandbox')
name: Deploy to Sandbox
uses: ./.github/workflows/deploy.yml
with:
environment: Sandbox
secrets: inherit
The workflow is triggered as expected upon merging a PR, but somehow it tries to deploy from the feature branch instead of deploying from main. Since the environment is protected, the deployment fails accordingly. How can we achieve that the deployment uses the target branch (i. e. , main) that was merged into, instead of the source branch?
There’s no way to specify that a workflow should be triggered when a pull request is merged. the reason why it's the feature branch that gets deployed is because it's the one that triggers the workflow. However, because a merged pull request always results in a push, you can use the push event to accomplish your goal.
For example, let’s say that you want to run a workflow whenever a pull request is merged to your main branch. You can do something like this:
on:
push:
branches:
- main
also if you want to prevent push directly to main it's part of github pro plan.

PR trigger not working with Azure DevOps and GitHub

I have my repos hosted on GitHub and running the pipeline on Azure DevOps, it is an iOS pipeline and I am not getting any error but while I try to raise a PR GitHub always gives a warning that I have conflicts and I have to make changes in the main branch as well, which I don't want to do since it might break the workflow is there any work-around for raising the pr without getting the conflict warning?
This is my YAML file:
pool:
vmImage: macOS-latest
trigger:
batch: true
branches:
include:
- develop
- epic/*
# trigger on PR builds targeting any branches
pr:
autoCancel: true
branches:
include: ['*']
# Adding parameters to Run UI
parameters:
- name: FIID
displayName: FIID
type: string
default: 00516
values:
- 00516
- 00031
This is the kind of conflict I am getting, I don't know what I might be doing wrong but I don't want to make changes in the develop branch everytime I have to raise a PR for xcodepipeline
If anyone could help me out that would be much appreciated, thanks.
Merge develop into your feature branch, fix the conflicts, push the changes. The PR should work like a charm after that.
This link should be useful https://akshayranganath.github.io/Git-Pull-Handling-Merge-Conflict/

Github action update re run for a tag

I have this github action that I think is wrong and didn't run for tags.
name: CI
on:
push:
branches:
- master
- /^v[0-9]+\.[0-9]+\.[0-9]+$/
I think that should be:
name: CI
on:
push:
branches:
- master
tags:
- v.*
My question is, after I update this ci config, how can I re-run this CI so that it runs on the tags? Or should I create a new tag just because I want this CI to run on it (I think this sounds bad since it means I created another release/tag without any actual updates, only CI config)?
Any help would be greatly appreciated!
Since July 2020, you could add a workflow_dispatch event and trigger manually your GitHub ACtion
(the workflow must exist on the default branch for the "Run workflow" button to appear)
That way, you can try and see if it does run based on your new tag criteria.

GitHub Actions showing up in the wrong Workflow

Our team recently switched to GitHub, and we set up some CICD flows using GitHub Actions. Now we have the problem, that certain actions are showing up in the wrong workflow lists.
If you check the below screenshot, you can see...
The currently selected workflow is Release CI
On the right hand side we can see the triggered actions...
But some of these actions actually concern a different workflow, namely Release 1.1. CI (marekd yellow) - which also has it's own entry in the workflow list on the left (marked green).
There is yet another kind of actions showing up (Release 1.1 PR CI), which also have their own workflow in the UI.
--> How comes? Am I misunderstanding the UI here?
In case this is important...
This is the start of the Release CI config:
name: Release CI
on:
push:
tags:
- 'release'
This is the start of the Release 1.1. CI config:
name: Release 1.1 CI
on:
push:
branches: [release_1_1]
This is the start of the Release 1.1 PR CI config:
name: Release 1.1 PR CI
on:
pull_request:
branches: [release_1_1]

Does Automated Commit are ignored by workflow hook?

We have two workflow that trigger on push set up like this:
on:
push:
branches:
- master
Inside of one workflow, it contains an action that push a bump version commit into master.
Inside of the other, it validate if the commit message is a bump and deploy automatically.
Currently, when we push a commit to master, we can see the github action created a commit in master like this:
Automated Version Bump ci: version bump to v1.2.3
Where Automated Version Bump is the name of the GitHub action and ci: version bump to v1.2.3 is the commit message generated by the GitHub action
I was expecting the workflow to trigger again because of the automated commit.
Does that means Automated Commit does not trigger workflow hook?
Thank you!
It seems this behaviour is a feature.
From the workflow events page:
An action in a workflow run can't trigger a new workflow run. For
example, if an action pushes code using the repository's GITHUB_TOKEN,
a new workflow will not run even when the repository contains a
workflow configured to run when push events occur.
So basically, events that originate from a workflow cannot trigger other workflows.
An alternative would be to use a scheduled workflow that checks every couple hours or so and does the validation.
on:
schedule:
- cron: '0 0/2 * * *'