Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release runs only on version tags created on main #172

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/.act/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 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 commands can be run to exercise the GitHub Actions locally.

Will pass the `main` conditional and run the `build-and-sign-image` job.

```bash
gh act -W .github/workflows/build-and-sign-image.yml -e .github/workflows/.act/push-event-valid.json
```

Will fail the `main` conditional and not run the `build-and-sign-image` job.

```bash
gh act -W .github/workflows/build-and-sign-image.yml -e .github/workflows/.act/push-event-invalid.json
```
3 changes: 3 additions & 0 deletions .github/workflows/.act/push-event-invalid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ref": "refs/tags/v200.3.0"
}
3 changes: 3 additions & 0 deletions .github/workflows/.act/push-event-valid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ref": "refs/tags/v0.3.0"
}
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
Loading