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
- Add better act documentation and support
  • Loading branch information
ciroque committed Jan 9, 2024
1 parent 027aa9d commit 577156a
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 3 deletions.
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

0 comments on commit 577156a

Please sign in to comment.