diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..0a30cc8d --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,27 @@ +name: Test action + +on: + push: + branches: + - master + +jobs: + main: + runs-on: ubuntu-latest + strategy: + matrix: + branch: [test] + steps: + - name: Checkout + uses: actions/checkout@v1 + - name: Send mail + uses: ./ + with: + server_address: ${{secrets.ADDRESS}} + server_port: 465 + username: ${{secrets.USERNAME}} + password: ${{secrets.PASSWORD}} + subject: ${{github.repository}} + body: Test of action completed successfully! + to: ${{secrets.USERNAME}} + from: github-actions \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index af667303..aa167135 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,5 @@ -FROM alpine:3.10 +FROM ruby:2.6-alpine -COPY LICENSE README.md / +COPY entrypoint.rb / -COPY entrypoint.sh /entrypoint.sh - -ENTRYPOINT ["/entrypoint.sh"] +ENTRYPOINT ["/entrypoint.rb"] diff --git a/README.md b/README.md index 25842b56..6cb1d61e 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,19 @@ -# Container Action Template +# Send mail Github Action -To get started, click the `Use this template` button on this repository [which will create a new repository based on this template](https://github.blog/2019-06-06-generate-new-repositories-with-repository-templates/). +An action that simply sends a mail to multiple recipients. -For info on how to build your first Container action, see the [toolkit docs folder](https://github.com/actions/toolkit/blob/master/docs/container-action.md). +## Usage + +```yaml +- name: Send mail + uses: dawidd6/action-send-mail@master + with: + server_address: smtp.gmail.com + server_port: 465 + username: ${{secrets.MAIL_USERNAME}} + password: ${{secrets.MAIL_PASSWORD}} + subject: Github Actions job result + body: Build job of ${{github.repository}} completed successfully! + to: obiwan@tatooine.com,yoda@dagobah.com + from: Luke Skywalker +``` diff --git a/action.yml b/action.yml index 4353abb9..8172b86a 100644 --- a/action.yml +++ b/action.yml @@ -1,12 +1,34 @@ -name: 'Container Action Template' -description: 'Get started with Container actions' -author: 'GitHub' -inputs: - myInput: - description: 'Input to use' - default: 'world' +name: Send mail +description: Send mail to multiple recipients +author: dawidd6 +branding: + icon: mail + color: blue +inputs: + server_address: + description: SMTP server address + required: true + server_port: + description: SMTP server port + required: true + username: + description: Authenticate as this user to SMTP server + required: true + password: + description: Authenticate with this password to SMTP server + required: true + subject: + description: Subject of mail message + required: true + body: + description: Body of mail message + required: true + to: + description: Recipients mail addresses (separated with comma) + required: true + from: + description: Full name of mail sender + required: true runs: - using: 'docker' - image: 'Dockerfile' - args: - - ${{ inputs.myInput }} + using: docker + image: Dockerfile \ No newline at end of file diff --git a/entrypoint.rb b/entrypoint.rb new file mode 100755 index 00000000..707a0635 --- /dev/null +++ b/entrypoint.rb @@ -0,0 +1,33 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +require 'net/smtp' + +# Inputs +address = ENV["INPUT_SERVER_ADDRESS"] +port = ENV["INPUT_SERVER_PORT"] +username = ENV["INPUT_USERNAME"] +password = ENV["INPUT_PASSWORD"] +subject = ENV["INPUT_SUBJECT"] +body = ENV["INPUT_BODY"] +to = ENV["INPUT_TO"] +from = ENV["INPUT_FROM"] + +# Message +message = < + +#{body} +EOM + +# Send +begin + smtp = Net::SMTP.new(address, port.to_i) + smtp.enable_tls + smtp.start(address, username, password, :login) + smtp.send_message(message, username, to.split(",")) +rescue StandardError => e + puts "Error: #{e.message}" + exit 1 +end diff --git a/entrypoint.sh b/entrypoint.sh deleted file mode 100755 index 3b8cd2da..00000000 --- a/entrypoint.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -l - -echo "hello $1"