Skip to content

Commit

Permalink
Release runs only on version tags created on main
Browse files Browse the repository at this point in the history
- typo correction
- Add job to find current branch
  • Loading branch information
ciroque committed Jan 9, 2024
1 parent 027aa9d commit fe6f58b
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 3 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/.act/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Act events

This project uses [act](https://github.com/nektos/act) to help test GitHub Actions locally. This directory contains act event definitions.

## Requirements

- [act](https://github.com/nektos/act), this guide assumes you have installed act as a [GitHub CLI extension](https://github.com/nektos/act#installation-as-github-cli-extension).
- [Docker](https://www.docker.com/)

## Running act

The following command can be run to exercise the GitHub Actions locally.

```bash
gh act -W .github/workflows/build-and-sign-image.yml -e .github/workflows/.act/push-event.json
```
56 changes: 56 additions & 0 deletions .github/workflows/.act/push-event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"ref": "refs/tags/v0.3.15",
"before": "0000000000000000000000000000000000000000",
"after": "1234567890abcdef1234567890abcdef12345678",
"created": false,
"deleted": false,
"forced": false,
"base_ref": "refs/heads/main",
"compare": "https://github.com/your-username/your-repo-name/compare/your-tag-name",
"commits": [
{
"id": "1234567890abcdef1234567890abcdef12345678",
"tree_id": "1234567890abcdef1234567890abcdef12345678",
"message": "Commit message associated with the main branch",
"timestamp": "2024-01-01T00:00:00+00:00",
"author": {
"name": "Your Name",
"email": "[email protected]",
"username": "your-username"
},
"committer": {
"name": "Your Name",
"email": "[email protected]",
"username": "your-username"
}
}
],
"head_commit": {
"id": "1234567890abcdef1234567890abcdef12345678",
"tree_id": "1234567890abcdef1234567890abcdef12345678",
"distinct": true,
"message": "Head commit message on main branch",
"timestamp": "2024-01-01T00:00:00+00:00",
"author": {
"name": "Your Name",
"email": "[email protected]",
"username": "your-username"
},
"committer": {
"name": "Your Name",
"email": "[email protected]",
"username": "your-username"
}
},
"repository": {
"name": "nginx-loadbalancer-kubernetes",
"full_name": "nginxinc/nginx-loadbalancer-kubernetes"
},
"pusher": {
"name": "ciroque",
"email": "[email protected]"
},
"sender": {
"login": "ciroque"
}
}
22 changes: 22 additions & 0 deletions .github/workflows/build-and-sign-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,30 @@ env:
IMAGE_NAME: ${{ github.repository }}

jobs:
find_origin_branch:
runs-on: ubuntu-latest
outputs:
branch: ${{ steps.find_origin_branch.outputs.branch }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Get the tag's SHA
id: get_tag_sha
run: |
echo "**************** Looking for SHA of tag: ${{ github.ref }}"
echo "::set-output name=sha::$(git rev-parse ${{ github.ref }})"
- name: Find origin branch
id: find_origin_branch
run: |
echo "**************** Looking for branch containing: ${{ steps.get_tag_sha.outputs.sha }}"
echo "::set-output name=branch::$(git branch -r --contains ${{ steps.get_tag_sha.outputs.sha }} | grep -v HEAD | sed -e 's/^[[:space:]]*origin\///' | grep -e '^main$')"
build_and_sign_image:
runs-on: ubuntu-latest
needs: find_origin_branch
if: needs.find_origin_branch.outputs.branch == 'main'
permissions:
contents: write
packages: write
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ on:
push:
branches:
- main
- *

- '*'
jobs:

build:
runs-on: ubuntu-latest
steps:
Expand Down

0 comments on commit fe6f58b

Please sign in to comment.