From 37d7dcb00250a1d4f433922530898b46578ee986 Mon Sep 17 00:00:00 2001 From: Yosiah de Koeyer Date: Mon, 11 Dec 2023 22:47:08 +1100 Subject: [PATCH] Attempt to gen and trigger --- .github/workflows/ci.yaml | 36 ++++++++++++++++++++++++-------- .github/workflows/test.yaml.tmpl | 12 ++++------- Taskfile.yaml | 22 +++++++++++++++++++ 3 files changed, 53 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 4a3510b..023e786 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -46,7 +46,7 @@ jobs: commit_message: Update compiled binaries file_pattern: "bin/*" - test-gen: + gen-tests: needs: [lint, build] runs-on: ubuntu-latest permissions: @@ -55,13 +55,31 @@ jobs: - name: Checkout Repository uses: actions/checkout@v4 - - uses: jason-dour/action-setup-gomplate@v1.0.0 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - run: gomplate --version + - name: Install Task + uses: arduino/setup-task@v1 - - name: Check SHA + - name: Generate tests run: | - echo "${{ github.event.pull_request.head.sha }}" - echo "${{ github.ref }}" + task gen-tests + + - uses: stefanzweifel/git-auto-commit-action@v5 + if: github.event_name == 'pull_request' + with: + commit_message: Update tests + file_pattern: ".github/workflows/test.yaml" + + trigger-tests: + needs: [gen-tests] + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Trigger generated tests + uses: convictional/trigger-workflow-and-wait@v1.6.1 + with: + owner: Y0sh1dk + repo: gha-docker-image-exists + github_token: ${{ secrets.GITHUB_PERSONAL_ACCESS_TOKEN }} + workflow_file_name: test.yml + ref: ${{ github.head_ref}} + wait_workflow: true diff --git a/.github/workflows/test.yaml.tmpl b/.github/workflows/test.yaml.tmpl index ee2625b..c18396b 100644 --- a/.github/workflows/test.yaml.tmpl +++ b/.github/workflows/test.yaml.tmpl @@ -1,11 +1,7 @@ -name: {{{ .Env.ACTION_NAME }}} +name: [[[ .Env.WORKFLOW_NAME ]]] Test on: workflow_dispatch: - inputs: - version: - description: "Version of action to run" - required: true jobs: success: @@ -14,7 +10,7 @@ jobs: - name: GHA Docker Image Exists id: gha-docker-image-exists continue-on-error: true - uses: Y0sh1dk/gha-docker-image-exists@{{{ .Env.ACTION_VERSION }}} + uses: Y0sh1dk/gha-docker-image-exists@[[[ .Env.ACTION_VERSION ]]] with: image: nginx:latest @@ -32,9 +28,9 @@ jobs: - name: GHA Docker Image Exists id: gha-docker-image-exists continue-on-error: true - uses: Y0sh1dk/gha-docker-image-exists@{{{ .Env.ACTION_VERSION }}} + uses: Y0sh1dk/gha-docker-image-exists@[[[ .Env.ACTION_VERSION ]]] with: - image: nginx:foobar + image: nginx:invalid-tag - name: Check output run: | diff --git a/Taskfile.yaml b/Taskfile.yaml index 6e69c25..10440df 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -33,6 +33,19 @@ tasks: golang:{{ .GO_VERSION }} \ {{ .COMMAND }} + _gomplate-docker: &gomplate-docker + internal: true + cmds: + - | + docker run \ + --rm \ + -e WORKFLOW_NAME={{ .WORKFLOW_NAME }} \ + -e ACTION_VERSION={{ .ACTION_VERSION }} \ + -v $(pwd):/app \ + -w /app \ + hairyhenderson/gomplate:stable \ + {{ .COMMAND }} + build: <<: *go-docker internal: false @@ -43,6 +56,15 @@ tasks: vars: COMMAND: go build -o bin/{{ .GIT_REPO_NAME }}-{{ .GOOS }}-{{ .GOARCH }} *.go {{ .CLI_ARGS }} + gen-tests: + <<: *gomplate-docker + internal: false + desc: Generate test workflows + vars: + WORKFLOW_NAME: "{{ default .GIT_REPO_NAME .WORKFLOW_NAME }}" + ACTION_VERSION: "{{ .ACTION_VERSION }}" + COMMAND: -f .github/workflows/test.yaml.tmpl --left-delim "[[[" --right-delim "]]]" > .github/workflows/test.yaml + build-all: desc: Build the application for all platforms vars: