From c21629effc4646ada1d967dc013a96e12daadfcc Mon Sep 17 00:00:00 2001 From: SebClem Date: Mon, 20 Jan 2025 11:34:22 +0100 Subject: [PATCH] Migrate to gitea action --- .gitea/workflows/docker.yml | 86 ++++++++++++++++++------------------- .woodpecker.yml | 34 --------------- action.yml | 32 ++++++++++++++ entrypoint.go | 41 +++++++++--------- go.mod | 1 + go.sum | 2 + 6 files changed, 99 insertions(+), 97 deletions(-) delete mode 100644 .woodpecker.yml create mode 100644 action.yml diff --git a/.gitea/workflows/docker.yml b/.gitea/workflows/docker.yml index 7409d47..2e2dfbb 100644 --- a/.gitea/workflows/docker.yml +++ b/.gitea/workflows/docker.yml @@ -1,48 +1,48 @@ -name: ci +# name: ci -on: - push: - branches: - - "master" - tags: - - "*" - pull_request: - branches: - - "master" +# on: +# push: +# branches: +# - "master" +# tags: +# - "*" +# pull_request: +# branches: +# - "master" -jobs: - docker: - runs-on: ubuntu-latest - container: - image: catthehacker/ubuntu:act-latest - steps: - - name: Checkout - uses: actions/checkout@v4 +# jobs: +# docker: +# runs-on: ubuntu-latest +# container: +# image: catthehacker/ubuntu:act-latest +# steps: +# - name: Checkout +# uses: actions/checkout@v4 - - name: Docker meta - id: meta - uses: docker/metadata-action@v5 - with: - images: | - git.sebclem.fr/${{ gitea.repository }} - tags: | - type=ref,event=branch - type=ref,event=pr - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} +# - name: Docker meta +# id: meta +# uses: docker/metadata-action@v5 +# with: +# images: | +# git.sebclem.fr/${{ gitea.repository }} +# tags: | +# type=ref,event=branch +# type=ref,event=pr +# type=semver,pattern={{version}} +# type=semver,pattern={{major}}.{{minor}} - - name: Login to registry - if: github.ref_type == 'tag' - uses: docker/login-action@v3 - with: - registry: git.sebclem.fr - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} +# - name: Login to registry +# if: github.ref_type == 'tag' +# uses: docker/login-action@v3 +# with: +# registry: git.sebclem.fr +# username: ${{ secrets.DOCKERHUB_USERNAME }} +# password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Build and push - uses: docker/build-push-action@v6 - with: - context: . - push: ${{ github.ref_type == 'tag' }} - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} +# - name: Build and push +# uses: docker/build-push-action@v6 +# with: +# context: . +# push: ${{ github.ref_type == 'tag' }} +# tags: ${{ steps.meta.outputs.tags }} +# labels: ${{ steps.meta.outputs.labels }} diff --git a/.woodpecker.yml b/.woodpecker.yml deleted file mode 100644 index 60a72f5..0000000 --- a/.woodpecker.yml +++ /dev/null @@ -1,34 +0,0 @@ -steps: - build-only: - image: woodpeckerci/plugin-docker-buildx - settings: - repo: git.sebclem.fr/sebclem/${CI_REPO_NAME} - cache_from: git.sebclem.fr/sebclem/${CI_REPO_NAME} - registry: git.sebclem.fr - dry_run: true - auto_tag: true - logins: - - registry: https://git.sebclem.fr - username: - from_secret: docker_user - password: - from_secret: docker_token - when: - event: [push, pull_request, manual] - - publish: - image: woodpeckerci/plugin-docker-buildx - settings: - platforms: linux/amd64 - auto_tag: true - repo: git.sebclem.fr/sebclem/${CI_REPO_NAME} - cache_from: git.sebclem.fr/sebclem/${CI_REPO_NAME} - logins: - - registry: https://git.sebclem.fr - username: - from_secret: docker_user - password: - from_secret: docker_token - when: - event: - - tag \ No newline at end of file diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..03e8796 --- /dev/null +++ b/action.yml @@ -0,0 +1,32 @@ +name: Gitea action Ansible runner +description: "Simple action to run Ansible playbook" +runs: + using: go + main: entrypoint.go + +inputs: + check_syntax: + description: Check playbook syntax + default: "false" + check: + description: Run playbook in check mode + default: "false" + diff: + description: Add '--check' + default: "false" + verbosity: + description: verbosity, int form 0 to 3 + default: "0" + limit: + description: Limit + tags: + description: Tags + private_key: + description: The private key used by ansible + vault_token: + description: Token used to unlock vault + galaxy_file: + description: Ansible galaxy requirement file + playbook: + description: Playbook file + required: true diff --git a/entrypoint.go b/entrypoint.go index 254251c..12400fe 100644 --- a/entrypoint.go +++ b/entrypoint.go @@ -6,6 +6,7 @@ import ( "strconv" "strings" + "github.com/sethvargo/go-githubactions" "go.uber.org/zap" "go.uber.org/zap/zapcore" ) @@ -38,8 +39,8 @@ func runCommand(sugar *zap.SugaredLogger, args ...string) { func getPluginConfig(sugar *zap.SugaredLogger) pluginConfig { config := pluginConfig{} - check_syntax, present := os.LookupEnv("PLUGIN_CHECK_SYNTAX") - if !present { + check_syntax := githubactions.GetInput("check_syntax") + if check_syntax == "" { config.check_syntax = false } else { converted, err := strconv.ParseBool(check_syntax) @@ -49,8 +50,8 @@ func getPluginConfig(sugar *zap.SugaredLogger) pluginConfig { config.check_syntax = converted } - check, present := os.LookupEnv("PLUGIN_CHECK") - if !present { + check := githubactions.GetInput("check") + if check == "" { config.check = false } else { converted, err := strconv.ParseBool(check) @@ -60,8 +61,8 @@ func getPluginConfig(sugar *zap.SugaredLogger) pluginConfig { config.check = converted } - diff, present := os.LookupEnv("PLUGIN_DIFF") - if !present { + diff := githubactions.GetInput("diff") + if diff == "" { config.diff = false } else { converted, err := strconv.ParseBool(diff) @@ -71,8 +72,8 @@ func getPluginConfig(sugar *zap.SugaredLogger) pluginConfig { config.diff = converted } - verbosity, present := os.LookupEnv("PLUGIN_VERBOSITY") - if !present { + verbosity := githubactions.GetInput("verbosity") + if verbosity == "" { config.verbosity = 0 } else { converted, err := strconv.ParseInt(verbosity, 10, 0) @@ -82,44 +83,44 @@ func getPluginConfig(sugar *zap.SugaredLogger) pluginConfig { config.verbosity = converted } - limit, present := os.LookupEnv("PLUGIN_LIMIT") - if !present { + limit := githubactions.GetInput("limit") + if limit == "" { config.limit = nil } else { config.limit = &limit } - tags, present := os.LookupEnv("PLUGIN_TAGS") - if !present { + tags := githubactions.GetInput("tags") + if tags == "" { config.tags = nil } else { config.tags = &tags } - privateKey, present := os.LookupEnv("PLUGIN_PRIVATE_KEY") - if !present { + privateKey := githubactions.GetInput("private_key") + if privateKey == "" { sugar.Warn("⚠️ 'private_key' setting not defined !") config.privateKey = nil } else { config.privateKey = &privateKey } - vaultToken, present := os.LookupEnv("PLUGIN_VAULT_TOKEN") - if !present { + vaultToken := githubactions.GetInput("vault_token") + if vaultToken == "" { config.vaultToken = nil } else { config.vaultToken = &vaultToken } - galaxyFile, present := os.LookupEnv("PLUGIN_GALAXY_FILE") - if !present { + galaxyFile := githubactions.GetInput("galaxy_file") + if galaxyFile == "" { config.galaxyFile = nil } else { config.galaxyFile = &galaxyFile } - playbook, present := os.LookupEnv("PLUGIN_PLAYBOOK") - if !present { + playbook := githubactions.GetInput("playbook") + if playbook == "" { sugar.Fatal("⚠️ 'playbook' setting not defined, ABORT!") } else { config.playbook = &playbook diff --git a/go.mod b/go.mod index ce6385e..341cbf3 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.20 require go.uber.org/zap v1.27.0 require ( + github.com/sethvargo/go-githubactions v1.3.0 // indirect go.uber.org/atomic v1.7.0 // indirect go.uber.org/multierr v1.10.0 // indirect ) diff --git a/go.sum b/go.sum index d44fc25..565262e 100644 --- a/go.sum +++ b/go.sum @@ -5,6 +5,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/sethvargo/go-githubactions v1.3.0 h1:Kg633LIUV2IrJsqy2MfveiED/Ouo+H2P0itWS0eLh8A= +github.com/sethvargo/go-githubactions v1.3.0/go.mod h1:7/4WeHgYfSz9U5vwuToCK9KPnELVHAhGtRwLREOQV80= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=