diff --git a/.github/workflows/.act/README.md b/.github/workflows/.act/README.md new file mode 100644 index 0000000..597571c --- /dev/null +++ b/.github/workflows/.act/README.md @@ -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 +``` diff --git a/.github/workflows/.act/push-event.json b/.github/workflows/.act/push-event.json new file mode 100644 index 0000000..119e84c --- /dev/null +++ b/.github/workflows/.act/push-event.json @@ -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": "your-email@example.com", + "username": "your-username" + }, + "committer": { + "name": "Your Name", + "email": "your-email@example.com", + "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": "your-email@example.com", + "username": "your-username" + }, + "committer": { + "name": "Your Name", + "email": "your-email@example.com", + "username": "your-username" + } + }, + "repository": { + "name": "nginx-loadbalancer-kubernetes", + "full_name": "nginxinc/nginx-loadbalancer-kubernetes" + }, + "pusher": { + "name": "ciroque", + "email": "ciroque@live.com" + }, + "sender": { + "login": "ciroque" + } +} diff --git a/.github/workflows/build-and-sign-image.yml b/.github/workflows/build-and-sign-image.yml index 2fbf227..3d2faff 100644 --- a/.github/workflows/build-and-sign-image.yml +++ b/.github/workflows/build-and-sign-image.yml @@ -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 diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 454c716..dc9aa86 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -11,10 +11,8 @@ on: push: branches: - main - - * - + - '*' jobs: - build: runs-on: ubuntu-latest steps: