Migrate to gitea action

This commit is contained in:
SebClem 2025-01-20 11:34:22 +01:00
parent 512ba4964f
commit c21629effc
Signed by: sebclem
GPG Key ID: 5A4308F6A359EA50
6 changed files with 99 additions and 97 deletions

View File

@ -1,48 +1,48 @@
name: ci # name: ci
on: # on:
push: # push:
branches: # branches:
- "master" # - "master"
tags: # tags:
- "*" # - "*"
pull_request: # pull_request:
branches: # branches:
- "master" # - "master"
jobs: # jobs:
docker: # docker:
runs-on: ubuntu-latest # runs-on: ubuntu-latest
container: # container:
image: catthehacker/ubuntu:act-latest # image: catthehacker/ubuntu:act-latest
steps: # steps:
- name: Checkout # - name: Checkout
uses: actions/checkout@v4 # uses: actions/checkout@v4
- name: Docker meta # - name: Docker meta
id: meta # id: meta
uses: docker/metadata-action@v5 # uses: docker/metadata-action@v5
with: # with:
images: | # images: |
git.sebclem.fr/${{ gitea.repository }} # git.sebclem.fr/${{ gitea.repository }}
tags: | # tags: |
type=ref,event=branch # type=ref,event=branch
type=ref,event=pr # type=ref,event=pr
type=semver,pattern={{version}} # type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}} # type=semver,pattern={{major}}.{{minor}}
- name: Login to registry # - name: Login to registry
if: github.ref_type == 'tag' # if: github.ref_type == 'tag'
uses: docker/login-action@v3 # uses: docker/login-action@v3
with: # with:
registry: git.sebclem.fr # registry: git.sebclem.fr
username: ${{ secrets.DOCKERHUB_USERNAME }} # username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }} # password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push # - name: Build and push
uses: docker/build-push-action@v6 # uses: docker/build-push-action@v6
with: # with:
context: . # context: .
push: ${{ github.ref_type == 'tag' }} # push: ${{ github.ref_type == 'tag' }}
tags: ${{ steps.meta.outputs.tags }} # tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }} # labels: ${{ steps.meta.outputs.labels }}

View File

@ -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

32
action.yml Normal file
View File

@ -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

View File

@ -6,6 +6,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/sethvargo/go-githubactions"
"go.uber.org/zap" "go.uber.org/zap"
"go.uber.org/zap/zapcore" "go.uber.org/zap/zapcore"
) )
@ -38,8 +39,8 @@ func runCommand(sugar *zap.SugaredLogger, args ...string) {
func getPluginConfig(sugar *zap.SugaredLogger) pluginConfig { func getPluginConfig(sugar *zap.SugaredLogger) pluginConfig {
config := pluginConfig{} config := pluginConfig{}
check_syntax, present := os.LookupEnv("PLUGIN_CHECK_SYNTAX") check_syntax := githubactions.GetInput("check_syntax")
if !present { if check_syntax == "" {
config.check_syntax = false config.check_syntax = false
} else { } else {
converted, err := strconv.ParseBool(check_syntax) converted, err := strconv.ParseBool(check_syntax)
@ -49,8 +50,8 @@ func getPluginConfig(sugar *zap.SugaredLogger) pluginConfig {
config.check_syntax = converted config.check_syntax = converted
} }
check, present := os.LookupEnv("PLUGIN_CHECK") check := githubactions.GetInput("check")
if !present { if check == "" {
config.check = false config.check = false
} else { } else {
converted, err := strconv.ParseBool(check) converted, err := strconv.ParseBool(check)
@ -60,8 +61,8 @@ func getPluginConfig(sugar *zap.SugaredLogger) pluginConfig {
config.check = converted config.check = converted
} }
diff, present := os.LookupEnv("PLUGIN_DIFF") diff := githubactions.GetInput("diff")
if !present { if diff == "" {
config.diff = false config.diff = false
} else { } else {
converted, err := strconv.ParseBool(diff) converted, err := strconv.ParseBool(diff)
@ -71,8 +72,8 @@ func getPluginConfig(sugar *zap.SugaredLogger) pluginConfig {
config.diff = converted config.diff = converted
} }
verbosity, present := os.LookupEnv("PLUGIN_VERBOSITY") verbosity := githubactions.GetInput("verbosity")
if !present { if verbosity == "" {
config.verbosity = 0 config.verbosity = 0
} else { } else {
converted, err := strconv.ParseInt(verbosity, 10, 0) converted, err := strconv.ParseInt(verbosity, 10, 0)
@ -82,44 +83,44 @@ func getPluginConfig(sugar *zap.SugaredLogger) pluginConfig {
config.verbosity = converted config.verbosity = converted
} }
limit, present := os.LookupEnv("PLUGIN_LIMIT") limit := githubactions.GetInput("limit")
if !present { if limit == "" {
config.limit = nil config.limit = nil
} else { } else {
config.limit = &limit config.limit = &limit
} }
tags, present := os.LookupEnv("PLUGIN_TAGS") tags := githubactions.GetInput("tags")
if !present { if tags == "" {
config.tags = nil config.tags = nil
} else { } else {
config.tags = &tags config.tags = &tags
} }
privateKey, present := os.LookupEnv("PLUGIN_PRIVATE_KEY") privateKey := githubactions.GetInput("private_key")
if !present { if privateKey == "" {
sugar.Warn("⚠️ 'private_key' setting not defined !") sugar.Warn("⚠️ 'private_key' setting not defined !")
config.privateKey = nil config.privateKey = nil
} else { } else {
config.privateKey = &privateKey config.privateKey = &privateKey
} }
vaultToken, present := os.LookupEnv("PLUGIN_VAULT_TOKEN") vaultToken := githubactions.GetInput("vault_token")
if !present { if vaultToken == "" {
config.vaultToken = nil config.vaultToken = nil
} else { } else {
config.vaultToken = &vaultToken config.vaultToken = &vaultToken
} }
galaxyFile, present := os.LookupEnv("PLUGIN_GALAXY_FILE") galaxyFile := githubactions.GetInput("galaxy_file")
if !present { if galaxyFile == "" {
config.galaxyFile = nil config.galaxyFile = nil
} else { } else {
config.galaxyFile = &galaxyFile config.galaxyFile = &galaxyFile
} }
playbook, present := os.LookupEnv("PLUGIN_PLAYBOOK") playbook := githubactions.GetInput("playbook")
if !present { if playbook == "" {
sugar.Fatal("⚠️ 'playbook' setting not defined, ABORT!") sugar.Fatal("⚠️ 'playbook' setting not defined, ABORT!")
} else { } else {
config.playbook = &playbook config.playbook = &playbook

1
go.mod
View File

@ -5,6 +5,7 @@ go 1.20
require go.uber.org/zap v1.27.0 require go.uber.org/zap v1.27.0
require ( require (
github.com/sethvargo/go-githubactions v1.3.0 // indirect
go.uber.org/atomic v1.7.0 // indirect go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.10.0 // indirect go.uber.org/multierr v1.10.0 // indirect
) )

2
go.sum
View File

@ -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/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 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 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/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.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=