trying to setup a pre-push hook using pre-commit - push

I am trying to set up a pre-push hook using pre-commit https://pre-commit.com/
when i make a pre-commit hook it works fine like before commit all the checks work but in case of push no hook runs
This is how my .pre-commit-config-yaml looks like in case of push
- repo: local
hooks:
- id: Test
name: Test
stages: [push]
entry: python3 test.py
language: system
types: [python]
Does anyone know what am doing wrong?

Related

GitHub Action - reusable workflow: Run a github actions workflow in the context of the called workflow

I got a "caller" workflow and a "called" workflow.
Caller workflow:
name: caller
on:
workflow_dispatch:
jobs:
call-another-workflow:
uses: project/called/.github/workflows/main.yml#main
Called workflow:
name: called
on:
workflow_dispatch:
workflow_call:
jobs:
run_python_script:
runs-on: [ self-hosted ]
steps:
# Following step will be executed in the caller context (should be executed in the called context)
- uses: actions/checkout#v3
- name: Setup python
uses: actions/setup-python#v4
with:
python-version: '3.9'
# Cannot find requirements.txt (wrong repository is checked out)
- name: Install python packages
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Execute the python script
run: python some_python_code.py
Error: <path> can't open file <path> [Errno 2] No such file or directory
-> The wrong repository is checked out (caller repo is checked out instead of the called which is needed). If I trigger the called workflow manually (the 'actions/checkout#v3' is checking out the right repo) the workflow runs successfully.
The caller workflow should 'just' trigger the called workflow in a way, that the workflow runs like it was triggered manually.
Unfortunately the github actions documentation says:
If you reuse a workflow from a different repository, any actions in the called workflow run as if they were part of the caller workflow. For example, if the called workflow uses actions/checkout, the action checks out the contents of the repository that hosts the caller workflow, not the called workflow.
(reference: https://docs.github.com/en/actions/using-workflows/reusing-workflows#overview)
-> Do we have the possibility to just trigger the workflow in a way that it is running like I triggered it manually?
Alternatively, I can trigger the workflow from another workflow via web interface. But then it gets messy. Some ideas?

How can I run a workflow with smoke tests to run in PR merge checks and then a workflow with all tests to run after merge to main branch?

This is the config.yml file I have created. It has 2 workflows. Smoke tests & cypress-all-tests
version: 2.1
orbs:
cypress: cypress-io/cypress#1
workflows:
pre-merge-run:
jobs:
- cypress/run:
name: Smoke tests
command: npm run cy:smoke
filters:
branches:
ignore:
-main
cypress-all-tests:
jobs:
- cypress/run:
name: All tests
command: npm run cy:all:tests
filters:
branches:
only:
- main
My intention is to run Smoke tests workflow on every pull request before it is merged to the main branch. Then run only cypress-all-tests workflow once the PR is merged to the main branch.
When the config file is run by CircleCI, this is what happens:
Only smoke tests run on the pull request before merge (which is what I want)
BUT
Both the workflows run after the PR is merged to the main branch (which is not what I need). Only the workflow cypress-all-tests should be running now.
I don't know where am I making the mistake.
So it was a silly mistake!
I just had to put a space between - and main. You can see the absence of a space in the screenshot below.

How do I get Azure Pipeline to set Build.SourceBranch to do the tag

When I do npm version patch && git push I want it to run a step based on a condition.
trigger:
branches:
include:
- master
tags:
include:
- '*'
...
steps:
- bash: |
npm publish
displayName: 'npm publish'
condition: startsWith(variables['Build.SourceBranch'], 'refs/tags/')
But I always get refs/heads/master for source branch.
UPDATE:
git push does not normally push tags by default.
git push --tags or git push --follow-tags will push the necessary tags. To ensure that this occurs by default
git config --global push.followtags true
However, this does not fully work either, because if you push master with tag the refs/heads/master still becomes Build.SourceBranch
So I have to push the tag specifically and ensure that the build triggers, but I'd rather avoid that.
I'd also like to avoid creating a separate pipeline with a different trigger (namely the tags) to do the build.
From the YAML documentation, it seems like that is only used for manual or scheduled builds, not a CI trigger.
tags: [ string ] # list of tags required on the pipeline to pickup
default artifacts, optional; Used only for manual or scheduled
triggers
I imagine you would only get it if you were doing something like the below to manually run a tag:
For most my cases specifically, I let the CI build run have a step that manages the tag creation rather than pushing a new tag.

Add and run GitHub Actions on feature branch?

I'm currently using the "git-flow" branching model outlined here. Following that model, once I've completed work on a feature branch, I'd like to add new GitHub actions to that branch (for example, to run my feaure's automated tests) before the branch is merged.
Following the branching model, I don't want to define the actions in a workflow file on the default branch before that feature branch is merged into it. Ideally I want to add the actions on the feature branch itself before the merge, but this doesn't appear to work.
I've added the below sample workflow to my feature branch, but GitHub does not detect it. Am I missing something here, or can workflows only detected and run once they're on the default branch? If the latter is true, do people generally merge their branches, then add workflows for them?
# Name workflow
name: Test workflow
# Read only permissions
permissions: read-all
# Triggered once every 15 minutes
on:
workflow_dispatch:
schedule:
- cron: '15 * * * *'
# Listing of jobs to be run
jobs:
# Just output the Python version for now.
python-tests:
name: Python Tests
runs-on: ubuntu-latest
# Use the environment configured with secrets
environment: python-test-environment
# Set the working directory?
defaults:
run:
working-directory: tests
steps:
# Checkout the repository
- name: Checkout
uses: actions/checkout#v2
ref: 'dev-tests'
# Configure Python
- name: Set up Python 3.7
uses: actions/setup-python#v2
with:
python-version: 3.7
# Output the Python version
- name: Display version
run: python -c "import sys; print(sys.version)"
Update: I can see now that the "schedule" trigger only works on the default branch. However, removing it and just using the workflow_dispatch trigger still (on the feature branch YML file) still does not show the workflow on GitHub.

Using GitHub actions like GitLab CI/CD

I just started to migrate all my GitLab repositories to GitHub. I wasn't using GitHub for a while so I stumbled over the - at least for me new feature - GitHub Actions.
Since I just started a new project, I wanted to use GitHub Actions for build and deploy my new application. I've really no idea what I'm doing wrong, I'll attach my workflow file below.
What I want to achieve is, everytime I push to a branch that's not my master and that hasn't the prefix 'release/', I want to execute this build and deploy for my development system. Later I will also setup the same script but for a staging (pre production) system ONLY if I push into a branch with the prefix 'release/' and indeed the same a thrid time for production for the master branch only.
What I'm wondering about is, the actions get - at least for my understanding - executed sporadically. I want an behaviour like I had in GitLab: Everytime I push a feature branch or whatever from my local working machine, the development pipeline should get executed. Then I'll create a pull request. Only if the pipeline was successful, I want to be able to merge. After the merge into a branch (for example feature/... into develop), I would like to automatically execute the pipeline for development.
I'm not even sure if this is possible. Maybe I also didn't understood the concept of actions correctly.
name: Publish Development
on:
push:
branches:
- '**'
- '!master'
- '!release/**'
pull_request:
branches:
- '**'
- '!master'
- '!release/**'
jobs:
build-and-deploy:
name: Build and Deploy
runs-on: ubuntu-latest
steps:
- name: check out repository
uses: actions/checkout#v2
with:
token: ${{ secrets.PRIVATE_ACCESS_TOKEN}}
- name: install dependencies
run: npm install
- name: install dependencies
run: npm --prefix ./functions install ./functions
- name: deploy to firebase
uses: w9jds/firebase-action#master
with:
args: deploy
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
PROJECT_ID: ${{ secrets.FIREBASE_PROJECT_ID }}
Thanks!
EDIT: Well it turned out that I just started to try new technology during some service interruption. GitHub was experiencing some issues in their infrastructure. Its working now as expected.
Well it turned out that I just started to try new technology during some service interruption. GitHub was experiencing some issues in their infrastructure. Its working now as expected.