From ccf14e2230d8e24f12d89d7616721bfb01fc9001 Mon Sep 17 00:00:00 2001 From: Shunsuke Suzuki Date: Wed, 21 Sep 2022 19:22:41 +0900 Subject: [PATCH 1/6] ci: set up CI --- .github/workflows/actionlint.yaml | 16 +++ .github/workflows/prettier.yaml | 14 +++ .../workflows/renovate-config-validator.yaml | 22 ++++ .github/workflows/test.yaml | 105 ++++++++++++++++++ .prettierignore | 1 + aqua.yaml | 8 ++ renovate.json | 13 +++ 7 files changed, 179 insertions(+) create mode 100644 .github/workflows/actionlint.yaml create mode 100644 .github/workflows/prettier.yaml create mode 100644 .github/workflows/renovate-config-validator.yaml create mode 100644 .github/workflows/test.yaml create mode 100644 .prettierignore create mode 100644 aqua.yaml create mode 100644 renovate.json diff --git a/.github/workflows/actionlint.yaml b/.github/workflows/actionlint.yaml new file mode 100644 index 0000000..cf63593 --- /dev/null +++ b/.github/workflows/actionlint.yaml @@ -0,0 +1,16 @@ +--- +name: actionlint +on: + push: + branches: [main] + pull_request: + branches: [main] +jobs: + default: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: aquaproj/aqua-installer@v1.1.2 + with: + aqua_version: v1.19.2 + - run: actionlint diff --git a/.github/workflows/prettier.yaml b/.github/workflows/prettier.yaml new file mode 100644 index 0000000..2a0464b --- /dev/null +++ b/.github/workflows/prettier.yaml @@ -0,0 +1,14 @@ +--- +name: prettier +on: + push: + branches: [main] + pull_request: + branches: [main] +jobs: + prettier: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - run: npm i -g prettier + - run: prettier -c . diff --git a/.github/workflows/renovate-config-validator.yaml b/.github/workflows/renovate-config-validator.yaml new file mode 100644 index 0000000..3e33595 --- /dev/null +++ b/.github/workflows/renovate-config-validator.yaml @@ -0,0 +1,22 @@ +name: renovate-config-validator + +on: + pull_request: + branches: + - main + paths: + - .github/workflows/renovate-config-validator.yaml + - renovate.json + push: + branches: + - main + paths: + - .github/workflows/renovate-config-validator.yaml + - renovate.json + +jobs: + validate: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: suzuki-shunsuke/github-action-renovate-config-validator@v0.1.2 diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..1bbbadb --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,105 @@ +name: test + +on: + pull_request: + branches: [main] + push: + branches: [main] + +jobs: + test-pull-request: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: ./ + with: + data: | + { + "event_name": "pull_request", + "event": { + "sha": "a705bd6d8bc3882c983477cb3f20ab74ef8c24c2", + "sender": { + "login": "suzuki-shunsuke" + }, + "repository": { + "full_name": "gha-trigger/gha-trigger", + "name": "gha-trigger", + "owner": { + "login": "gha-trigger" + } + }, + "pull_request": { + "number": 149, + "merge_commit_sha": "4528ea7ab7a8eef7e596097934a78eab90fb8b33", + "base": { + "ref": "main" + }, + "head": { + "sha": "b6d8f3331c6845997b9408163a127e01fd32c120", + "ref": "renovate/github.com-aws-aws-sdk-go-1.x" + }, + "html_url": "https://github.com/gha-trigger/step-summary-action/pull/9" + } + } + } + - name: Test GHA_ACTOR + run: | + [ "$GHA_ACTOR" = suzuki-shunsuke ] + - name: Test GHA_EVENT_NAME + run: | + [ "$GHA_EVENT_NAME" = pull_request ] + - name: Test GHA_REPOSITORY + run: | + [ "$GHA_REPOSITORY" = gha-trigger/gha-trigger ] + - name: Test GHA_REPOSITORY_OWNER + run: | + [ "$GHA_REPOSITORY_OWNER" = gha-trigger ] + - name: Test GHA_REPOSITORY_NAME + run: | + [ "$GHA_REPOSITORY_NAME" = gha-trigger ] + test-push: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: ./ + with: + data: | + { + "event_name": "push", + "event": { + "sha": "a705bd6d8bc3882c983477cb3f20ab74ef8c24c2", + "sender": { + "login": "suzuki-shunsuke" + }, + "repository": { + "full_name": "gha-trigger/gha-trigger", + "name": "gha-trigger", + "owner": { + "login": "gha-trigger" + } + } + } + } + test-release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: ./ + with: + data: | + { + "event_name": "push", + "event": { + "sha": "a705bd6d8bc3882c983477cb3f20ab74ef8c24c2", + "sender": { + "login": "suzuki-shunsuke" + }, + "repository": { + "full_name": "gha-trigger/gha-trigger", + "name": "gha-trigger", + "owner": { + "login": "gha-trigger" + } + } + } + } diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..dd44972 --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +*.md diff --git a/aqua.yaml b/aqua.yaml new file mode 100644 index 0000000..96c6375 --- /dev/null +++ b/aqua.yaml @@ -0,0 +1,8 @@ +--- +# aqua - Declarative CLI Version Manager +# https://aquaproj.github.io/ +registries: + - type: standard + ref: v3.58.0 # renovate: depName=aquaproj/aqua-registry +packages: + - name: rhysd/actionlint@v1.6.18 diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..6b6b239 --- /dev/null +++ b/renovate.json @@ -0,0 +1,13 @@ +{ + "extends": [ + "config:base", + "github>suzuki-shunsuke/renovate-config", + "github>aquaproj/aqua-renovate-config#1.2.5" + ], + "packageRules": [ + { + "matchUpdateTypes": ["digest"], + "enabled": false + } + ] +} From 3684c87a04939502766d2370b0f864d870bf6d6f Mon Sep 17 00:00:00 2001 From: Shunsuke Suzuki Date: Wed, 21 Sep 2022 20:08:09 +0900 Subject: [PATCH 2/6] ci: update test --- .github/workflows/test.yaml | 91 +++++++++++++++++++++++++++++++++++-- 1 file changed, 88 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 1bbbadb..6252f06 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -57,6 +57,30 @@ jobs: - name: Test GHA_REPOSITORY_NAME run: | [ "$GHA_REPOSITORY_NAME" = gha-trigger ] + - name: Test GHA_SHA + run: | + [ "$GHA_SHA" = 4528ea7ab7a8eef7e596097934a78eab90fb8b33 ] + - name: Test GHA_COMMIT_STATUS_SHA + run: | + [ "$GHA_COMMIT_STATUS_SHA" = 4528ea7ab7a8eef7e596097934a78eab90fb8b33 ] + - name: Test GHA_BASE_REF + run: | + [ "$GHA_BASE_REF" = main ] + - name: Test GHA_HEAD_SHA + run: | + [ "$GHA_HEAD_SHA" = b6d8f3331c6845997b9408163a127e01fd32c120 ] + - name: Test GHA_REF + run: | + [ "$GHA_REF" = refs/pull/149/merge ] + - name: Test GHA_REF_NAME + run: | + [ "$GHA_REF_NAME" = 149/merge ] + - name: Test GHA_PULL_REQUEST_NUMBER + run: | + [ "$GHA_PULL_REQUEST_NUMBER" = 149 ] + - name: Test GHA_ENV + run: | + [ -n "$GHA_ENV" ] test-push: runs-on: ubuntu-latest steps: @@ -67,10 +91,12 @@ jobs: { "event_name": "push", "event": { - "sha": "a705bd6d8bc3882c983477cb3f20ab74ef8c24c2", "sender": { "login": "suzuki-shunsuke" }, + "head_commit": { + "id": "a705bd6d8bc3882c983477cb3f20ab74ef8c24c2" + }, "repository": { "full_name": "gha-trigger/gha-trigger", "name": "gha-trigger", @@ -80,6 +106,36 @@ jobs: } } } + - name: Test GHA_ACTOR + run: | + [ "$GHA_ACTOR" = suzuki-shunsuke ] + - name: Test GHA_EVENT_NAME + run: | + [ "$GHA_EVENT_NAME" = push ] + - name: Test GHA_REPOSITORY + run: | + [ "$GHA_REPOSITORY" = gha-trigger/gha-trigger ] + - name: Test GHA_REPOSITORY_OWNER + run: | + [ "$GHA_REPOSITORY_OWNER" = gha-trigger ] + - name: Test GHA_REPOSITORY_NAME + run: | + [ "$GHA_REPOSITORY_NAME" = gha-trigger ] + - name: Test GHA_SHA + run: | + [ "$GHA_SHA" = 4528ea7ab7a8eef7e596097934a78eab90fb8b33 ] + - name: Test GHA_COMMIT_STATUS_SHA + run: | + [ "$GHA_COMMIT_STATUS_SHA" = 4528ea7ab7a8eef7e596097934a78eab90fb8b33 ] + - name: Test GHA_REF + run: | + [ "$GHA_REF" = ] + - name: Test GHA_REF_NAME + run: | + [ "$GHA_REF_NAME" = ] + - name: Test GHA_ENV + run: | + [ -n "$GHA_ENV" ] test-release: runs-on: ubuntu-latest steps: @@ -88,12 +144,14 @@ jobs: with: data: | { - "event_name": "push", + "event_name": "release", "event": { - "sha": "a705bd6d8bc3882c983477cb3f20ab74ef8c24c2", "sender": { "login": "suzuki-shunsuke" }, + "release": { + "tag_name": "v0.1.0" + }, "repository": { "full_name": "gha-trigger/gha-trigger", "name": "gha-trigger", @@ -103,3 +161,30 @@ jobs: } } } + - name: Test GHA_ACTOR + run: | + [ "$GHA_ACTOR" = suzuki-shunsuke ] + - name: Test GHA_EVENT_NAME + run: | + [ "$GHA_EVENT_NAME" = release ] + - name: Test GHA_REPOSITORY + run: | + [ "$GHA_REPOSITORY" = gha-trigger/gha-trigger ] + - name: Test GHA_REPOSITORY_OWNER + run: | + [ "$GHA_REPOSITORY_OWNER" = gha-trigger ] + - name: Test GHA_REPOSITORY_NAME + run: | + [ "$GHA_REPOSITORY_NAME" = gha-trigger ] + - name: Test GHA_SHA + run: | + [ "$GHA_SHA" = ] + - name: Test GHA_REF + run: | + [ "$GHA_REF" = v0.1.0 ] + - name: Test GHA_REF_NAME + run: | + [ "$GHA_REF_NAME" = v0.1.0 ] + - name: Test GHA_ENV + run: | + [ -n "$GHA_ENV" ] From 2f005bf8c2b7fa0d4643736ed597a041917cf0dd Mon Sep 17 00:00:00 2001 From: Shunsuke Suzuki Date: Wed, 21 Sep 2022 20:25:16 +0900 Subject: [PATCH 3/6] fix: fix GHA_REF_NAME --- .github/workflows/test.yaml | 12 ++++++------ action.yaml | 22 ++++++++++++++++++++-- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 6252f06..f12535f 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -17,7 +17,6 @@ jobs: { "event_name": "pull_request", "event": { - "sha": "a705bd6d8bc3882c983477cb3f20ab74ef8c24c2", "sender": { "login": "suzuki-shunsuke" }, @@ -91,6 +90,7 @@ jobs: { "event_name": "push", "event": { + "ref": "refs/heads/renovate/github.com-aws-aws-sdk-go-1.x", "sender": { "login": "suzuki-shunsuke" }, @@ -123,16 +123,16 @@ jobs: [ "$GHA_REPOSITORY_NAME" = gha-trigger ] - name: Test GHA_SHA run: | - [ "$GHA_SHA" = 4528ea7ab7a8eef7e596097934a78eab90fb8b33 ] + [ "$GHA_SHA" = a705bd6d8bc3882c983477cb3f20ab74ef8c24c2 ] - name: Test GHA_COMMIT_STATUS_SHA run: | - [ "$GHA_COMMIT_STATUS_SHA" = 4528ea7ab7a8eef7e596097934a78eab90fb8b33 ] + [ "$GHA_COMMIT_STATUS_SHA" = a705bd6d8bc3882c983477cb3f20ab74ef8c24c2 ] - name: Test GHA_REF run: | - [ "$GHA_REF" = ] + [ "$GHA_REF" = refs/heads/renovate/github.com-aws-aws-sdk-go-1.x ] - name: Test GHA_REF_NAME run: | - [ "$GHA_REF_NAME" = ] + [ "$GHA_REF_NAME" = renovate/github.com-aws-aws-sdk-go-1.x ] - name: Test GHA_ENV run: | [ -n "$GHA_ENV" ] @@ -178,7 +178,7 @@ jobs: [ "$GHA_REPOSITORY_NAME" = gha-trigger ] - name: Test GHA_SHA run: | - [ "$GHA_SHA" = ] + [ "$GHA_SHA" = "" ] - name: Test GHA_REF run: | [ "$GHA_REF" = v0.1.0 ] diff --git a/action.yaml b/action.yaml index e8ddc5c..de59836 100644 --- a/action.yaml +++ b/action.yaml @@ -58,6 +58,7 @@ runs: GHA_PULL_REQUEST_NUMBER=${{fromJSON(inputs.data).event.pull_request.number}} EOS if: startsWith(env.GHA_EVENT_NAME, 'pull_request') + - shell: bash # GITHUB_REF # > For workflows triggered by release, this is the release tag created. @@ -67,6 +68,7 @@ runs: GHA_REF_NAME=${{fromJSON(inputs.data).event.release.tag_name}} EOS if: env.GHA_EVENT_NAME == 'release' + - shell: bash # GITHUB_REF # > For workflows triggered by push, this is the branch or tag ref that was pushed. @@ -75,12 +77,28 @@ runs: # When you delete a branch, # the SHA in the workflow run (and its associated refs) reverts to the default branch of the repository. cat << EOS >> "$GITHUB_ENV" - GHA_REF=${{fromJSON(inputs.data).event.ref}} - GHA_REF_NAME=$(basename "${{fromJSON(inputs.data).event.ref}}") + GHA_REF=$REF GHA_SHA=${{fromJSON(inputs.data).event.head_commit.id}} GHA_COMMIT_STATUS_SHA=${{fromJSON(inputs.data).event.head_commit.id}} EOS if: env.GHA_EVENT_NAME == 'push' + env: + REF: ${{fromJSON(inputs.data).event.ref}} + + - shell: bash + run: | + cat << EOS >> "$GITHUB_ENV" + GHA_REF_NAME=${GHA_REF#refs/heads/} + EOS + if: "env.GHA_EVENT_NAME == 'push' && startsWith(env.GHA_REF, 'refs/heads/')" + + - shell: bash + run: | + cat << EOS >> "$GITHUB_ENV" + GHA_REF_NAME=${GHA_REF#refs/tags/} + EOS + if: "env.GHA_EVENT_NAME == 'push' && startsWith(env.GHA_REF, 'refs/tags/')" + # TODO GITHUB_REF # > The branch or tag ref that triggered the workflow run. # > For other triggers, this is the branch or tag ref that triggered the workflow run. From adaee6f9ab153dbb03522c36e2ec7554faac9efb Mon Sep 17 00:00:00 2001 From: Shunsuke Suzuki Date: Wed, 21 Sep 2022 20:42:44 +0900 Subject: [PATCH 4/6] fix: fix GHA_SHA --- .github/workflows/test.yaml | 2 +- action.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index f12535f..5b99b3d 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -61,7 +61,7 @@ jobs: [ "$GHA_SHA" = 4528ea7ab7a8eef7e596097934a78eab90fb8b33 ] - name: Test GHA_COMMIT_STATUS_SHA run: | - [ "$GHA_COMMIT_STATUS_SHA" = 4528ea7ab7a8eef7e596097934a78eab90fb8b33 ] + [ "$GHA_COMMIT_STATUS_SHA" = b6d8f3331c6845997b9408163a127e01fd32c120 ] - name: Test GHA_BASE_REF run: | [ "$GHA_BASE_REF" = main ] diff --git a/action.yaml b/action.yaml index de59836..f0a8428 100644 --- a/action.yaml +++ b/action.yaml @@ -54,7 +54,7 @@ runs: GHA_HEAD_REF=${{fromJSON(inputs.data).event.pull_request.head.ref}} GHA_REF=refs/pull/${{fromJSON(inputs.data).event.pull_request.number}}/merge GHA_REF_NAME=${{fromJSON(inputs.data).event.pull_request.number}}/merge - GHA_SHA=${{fromJSON(inputs.data).pull_request.merge_commit_sha}} + GHA_SHA=${{fromJSON(inputs.data).event.pull_request.merge_commit_sha}} GHA_PULL_REQUEST_NUMBER=${{fromJSON(inputs.data).event.pull_request.number}} EOS if: startsWith(env.GHA_EVENT_NAME, 'pull_request') From 32664d733ddda6e88ca2bbfb848cbbdff3c7bea7 Mon Sep 17 00:00:00 2001 From: Shunsuke Suzuki Date: Wed, 21 Sep 2022 20:46:31 +0900 Subject: [PATCH 5/6] refactor: refactor pull_request number --- action.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/action.yaml b/action.yaml index f0a8428..736c216 100644 --- a/action.yaml +++ b/action.yaml @@ -52,10 +52,10 @@ runs: GHA_HEAD_SHA=${{fromJSON(inputs.data).event.pull_request.head.sha}} GHA_COMMIT_STATUS_SHA=${{fromJSON(inputs.data).event.pull_request.head.sha}} GHA_HEAD_REF=${{fromJSON(inputs.data).event.pull_request.head.ref}} - GHA_REF=refs/pull/${{fromJSON(inputs.data).event.pull_request.number}}/merge - GHA_REF_NAME=${{fromJSON(inputs.data).event.pull_request.number}}/merge + GHA_REF=refs/pull/${{fromJSON(inputs.data).event.number}}/merge + GHA_REF_NAME=${{fromJSON(inputs.data).event.number}}/merge GHA_SHA=${{fromJSON(inputs.data).event.pull_request.merge_commit_sha}} - GHA_PULL_REQUEST_NUMBER=${{fromJSON(inputs.data).event.pull_request.number}} + GHA_PULL_REQUEST_NUMBER=${{fromJSON(inputs.data).event.number}} EOS if: startsWith(env.GHA_EVENT_NAME, 'pull_request') From 46d9885851c16dc09da4d6722ce655f17b632e24 Mon Sep 17 00:00:00 2001 From: Shunsuke Suzuki Date: Wed, 21 Sep 2022 20:47:35 +0900 Subject: [PATCH 6/6] ci: fix test data --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 5b99b3d..77c8010 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -17,6 +17,7 @@ jobs: { "event_name": "pull_request", "event": { + "number": 149, "sender": { "login": "suzuki-shunsuke" }, @@ -28,7 +29,6 @@ jobs: } }, "pull_request": { - "number": 149, "merge_commit_sha": "4528ea7ab7a8eef7e596097934a78eab90fb8b33", "base": { "ref": "main"