概要

GitHub Actionsの処理結果をメールで通知する機会がありましたので、その備忘録です。

今回はGmailを使います。以下が参考になりました。

https://stackoverflow.com/questions/69947109/sending-email-with-github-actions

Gmailの設定

以下に記載があります。2段階認証を有効にして、アプリパスワードを作成します。

https://github.com/dawidd6/action-send-mail?tab=readme-ov-file#gmail

アプリパスワードの設定例は以下です。

ローカルでの動作確認

actを使って、ローカル環境でGitHub Actionsを実行します。

https://github.com/nektos/act

あるリポジトリで以下のようなファイルを作成します。

nojanom:bsese:[:nrspdutNu-neosmsptha-si]io:flni::cniuwauafsitbm:etiueshon:s::ssupstfbntueesauorouScdrresb:odW-ecavvrsjmyolneweenwe$::HTCCBB$radsirraoc{ehoore{ktsd__mrt{$|lemmas{fem(daped:s{lmmntlsa)6do::e{odiicsoti/drDc,etthrewl#art$$ersp::ecce:{{peellgrts{{ltco$i$aeis4ssosry{n{rto:6eey.em{k{dsn5ccmMte:s.-srreAsngg,MsmeenI.tihiAettttLMtttInpss_AphthLd...CTIrupu_-gMMoOLobsbFmmAAm}_c.:.RaaIIp}FesrOiiLLlRsh/eMll__eOsagf@.UPtMi}vcSAef}t}}3oESd}o}h}mRS}ruNW-bAOt.MR$hcED{eo}}{m}}r/ge$ip{to{hsuigbti.otrrheyupbo$.s{ri{etpogorisytiht}uo}br.yre}p}o/sciotmomriyt/}$}{{hagsitbheuebn.sshuacc}e}ssfullycompleted.

以下のようなコマンドでシークレットを使うことができました。

actpush-secret-file.secrets

そのため、以下のようなファイルを用意します。

MMMMAAAAIIIILLLL____UPTFSAORES=ORSaMNWb=AOcMR@EDe==xxaaxamxap@algemb.aboibrlbg.,ccdocemcfc@edxdadmdple.org

結果、以下のようにメールを送信することができました。

%W[[[[[[[[[[[ANNNNNNNNNNNaRooooooooooocNttttttttttttiiiiiiiiiiifffffffffffpiiiiiiiiiiiucccccccccccsYaaaaaaaaaaahotttttttttttuiiiiiiiiiiiooooooooooo-annnnnnnnnnnsreeWWWWWWWWWWWcooooooooooorurrrrrrrrrrreskkkkkkkkkkktifffffffffff-nlllllllllllfgoooooooooooiwwwwwwwwwwwlA///////////epssssssssssspeeeeeeeeeee.lnnnnnnnnnnnseddddddddddde-----------cMmmmmmmmmmmmr-aaaaaaaaaaaesiiiiiiiiiiitelllllllllllsr]]]]]]]]]]]ie🚀u🏁ss🐳i🐳🐳R🐳🐳cSnuJhtgnoiadddgddSbproDooiMooutcocctacccsakckkikkcuniekeecneeecdmrerrlrrscaroSseygpAcrneceeoeuuruenpx-du=ltendeeclha'scMdhaCtihmraatioemtaccivtmnati=mnehafigpl/degimesx=Snhega=:x[eoa=gc/xnntccaea//odkau=tg.dsettcticemprthahtaae/hetehcicuenthuhvlibhthabeafuaiec./rincchkca/etkaaeocrduetcrmtu:rik///nca/oeudd/ocunrbaaantb/uwwct-ufuniitalnobtdd/iatruuddantun:66cee:dta/-trsaoucaaitcc:tccoatka-ttnr-ecliisclrtaoo/ha-tnnditple--ateuassswesltteeictlenndtspddduptl--6rlamm-eaptaaa,tlfiicfaolltyotr'@iorfmvoumo=#3n=r/-mmersiu=nedegstfsnheer=tdtrnyv=-ntp3/mearovanmyiaicepnrlo=ot/@ui=rvnfn[u3tot"ner=tmrc[aaae"iciiPtltnsua"/.sliajull"cse="-t]stfir""ouwu-nshef"sei"//rldd=e"ea/vwwrd/iouendrnvudkn/l6dinl-inu"argl]c=lta"cic]motdn.c=-m[sId]ef=n[ds]-om,aitlr@yv3r/unningitwith-container-architecturelinux/amd64'.
DxTHTCCBBexoehoorepx:lemmasllmmnto<xodiicyxx,etthrmxxp::eexllgn@oxiratgyxnermmxkfdCae:ssoin/,mlthhp.telcptaeorpdtmosse>c:dem2s/a-0sgi2inx4ftxohx1rub1t.9hceom1r/9en:pa5ok2saimtuorray19x6x/xgeh_aesdibteoern/csoumcmciets/sxfxuxllycompleted.

失敗時の挙動確認

失敗時の挙動確認にあたっては、以下のようにrun: exit 1を使うとよいようでした。

nojanom:bsese:[:nrspdutNu-neosmsptha-si]io:flni::cnrniniuwauauafafsitbmnm:m:etiue:eeshon::s:f::ssupstfbnteuaeesauorouIxScSidrresb:odW-niecelavvrsjmyolttnenuweenwe$::HTCCBPB$raedsdrirraoc{ehoorle{ktn1sed__mrt{$|lemmaes{fetm(F(daped:{lrmmnatlsia)a)6do::s{oeiicssotoii/drDe,ttherewnl#lart$$ecsw::ecauce:{{prealcgrlrts{{lecs$i$haeeis4otr{n{ertFo:6ssysea{k{cdsaMn5eem.t:ks.ia-scceMsfgg,MlismrrnA.aihitAleteetIMittthInpttLAlhtheLd.ssF_Iuupu_-g..aTLrbsbGFmmMMiO_e.:.iRaaAAlFsrtOiiIIe}Rih/eHMllLLd}Onagfu@.__Mib}vcUP-t}t}}3oSA}h}h}AmES$}eucRS{btNW{#d.iAOecoMRg<ponEDiulmstso/}}hey$l}}urm{ob@e{g.ensrxtgeaifpmptooprhrslouiecbmt.e.oocsrrroseeymp>fod}ose}rittatoihrleys.r}e}p/ocsoimtmoirty/$${{{{ggiitthhuubb..srheapo}s}itory}}.

シークレットの登録

ローカル環境での検証が終わったら、変更内容をGitHubにpushします。その際、GitHub CLIのghコマンドを使って、以下のようにシークレットを登録しました。

gggghhhhsssseeeeccccrrrreeeettttsssseeeettttMMMMAAAAIIIILLLL____UPTFSAORESORSMNW-AObMRo-EDdbyod--"ybbaoob"ddcyy@e""xxaa"xamxap@algemb.aboibrlbg.,ccdocemcf"c@edxdadmdp"le.org"

まとめ

Slackなどに通知するほうが一般的かと思いますが、参考になりましたら幸いです。