From 9c3197ce603c4d3908d26e4f573802b07d20f5bc Mon Sep 17 00:00:00 2001 From: conflictwar <78981120+conflictwar@users.noreply.github.com> Date: Sun, 14 Feb 2021 06:24:09 -0600 Subject: [PATCH 01/12] Create msbuild.yml --- .github/workflows/msbuild.yml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .github/workflows/msbuild.yml diff --git a/.github/workflows/msbuild.yml b/.github/workflows/msbuild.yml new file mode 100644 index 0000000000..4a5d3097d7 --- /dev/null +++ b/.github/workflows/msbuild.yml @@ -0,0 +1,32 @@ +name: MSBuild + +on: [push] + +env: + # Path to the solution file relative to the root of the project. + SOLUTION_FILE_PATH: . + + # Configuration type to build. + # You can convert this to a build matrix if you need coverage of multiple configuration types. + # https://docs.github.com/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix + BUILD_CONFIGURATION: Release + +jobs: + build: + runs-on: windows-latest + + steps: + - uses: actions/checkout@v2 + + - name: Add MSBuild to PATH + uses: microsoft/setup-msbuild@v1 + + - name: Restore NuGet packages + working-directory: ${{env.GITHUB_WORKSPACE}} + run: nuget restore ${{env.SOLUTION_FILE_PATH}} + + - name: Build + working-directory: ${{env.GITHUB_WORKSPACE}} + # Add additional options to the MSBuild command line here (like platform or verbosity level). + # See https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference + run: msbuild /m /p:Configuration=${{env.BUILD_CONFIGURATION}} ${{env.SOLUTION_FILE_PATH}} From 092f175b0e348413caa2e80d5fce6831260235d2 Mon Sep 17 00:00:00 2001 From: conflictwar <78981120+conflictwar@users.noreply.github.com> Date: Sun, 14 Feb 2021 21:27:10 -0600 Subject: [PATCH 02/12] Delete NodeRpcProxy.cpp --- src/NodeRpcProxy/NodeRpcProxy.cpp | 695 ------------------------------ 1 file changed, 695 deletions(-) delete mode 100644 src/NodeRpcProxy/NodeRpcProxy.cpp diff --git a/src/NodeRpcProxy/NodeRpcProxy.cpp b/src/NodeRpcProxy/NodeRpcProxy.cpp deleted file mode 100644 index b1b4a549a0..0000000000 --- a/src/NodeRpcProxy/NodeRpcProxy.cpp +++ /dev/null @@ -1,695 +0,0 @@ -// Copyright (c) 2011-2016 The Cryptonote developers -// Distributed under the MIT/X11 software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#include "NodeRpcProxy.h" -#include "NodeErrors.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "Common/StringTools.h" -#include "CryptoNoteCore/CryptoNoteBasicImpl.h" -#include "CryptoNoteCore/CryptoNoteTools.h" -#include "Rpc/CoreRpcServerCommandsDefinitions.h" -#include "Rpc/HttpClient.h" -#include "Rpc/JsonRpc.h" - -#ifndef AUTO_VAL_INIT -#define AUTO_VAL_INIT(n) boost::value_initialized() -#endif - -using namespace Crypto; -using namespace Common; -using namespace System; - -namespace CryptoNote { - -namespace { - -std::error_code interpretResponseStatus(const std::string& status) { - if (CORE_RPC_STATUS_BUSY == status) { - return make_error_code(error::NODE_BUSY); - } else if (CORE_RPC_STATUS_OK != status) { - return make_error_code(error::INTERNAL_NODE_ERROR); - } - return std::error_code(); -} - -} - -NodeRpcProxy::NodeRpcProxy(const std::string& nodeHost, unsigned short nodePort) : - m_rpcTimeout(10000), - m_pullInterval(5000), - m_nodeHost(nodeHost), - m_nodePort(nodePort), - m_lastLocalBlockTimestamp(0), - m_connected(true) { - resetInternalState(); -} - -NodeRpcProxy::~NodeRpcProxy() { - try { - shutdown(); - } catch (std::exception&) { - } -} - -void NodeRpcProxy::resetInternalState() { - m_stop = false; - m_peerCount.store(0, std::memory_order_relaxed); - m_nodeHeight.store(0, std::memory_order_relaxed); - m_networkHeight.store(0, std::memory_order_relaxed); - m_lastKnowHash = CryptoNote::NULL_HASH; - m_knownTxs.clear(); -} - -void NodeRpcProxy::init(const INode::Callback& callback) { - std::lock_guard lock(m_mutex); - - if (m_state != STATE_NOT_INITIALIZED) { - callback(make_error_code(error::ALREADY_INITIALIZED)); - return; - } - - m_state = STATE_INITIALIZING; - resetInternalState(); - m_workerThread = std::thread([this, callback] { - workerThread(callback); - }); -} - -bool NodeRpcProxy::shutdown() { - std::unique_lock lock(m_mutex); - - if (m_state == STATE_NOT_INITIALIZED) { - return true; - } else if (m_state == STATE_INITIALIZING) { - m_cv_initialized.wait(lock, [this] { return m_state != STATE_INITIALIZING; }); - if (m_state == STATE_NOT_INITIALIZED) { - return true; - } - } - - assert(m_state == STATE_INITIALIZED); - assert(m_dispatcher != nullptr); - - m_dispatcher->remoteSpawn([this]() { - m_stop = true; - // Run all spawned contexts - m_dispatcher->yield(); - }); - - if (m_workerThread.joinable()) { - m_workerThread.join(); - } - m_state = STATE_NOT_INITIALIZED; - - return true; -} - -void NodeRpcProxy::workerThread(const INode::Callback& initialized_callback) { - try { - Dispatcher dispatcher; - m_dispatcher = &dispatcher; - ContextGroup contextGroup(dispatcher); - m_context_group = &contextGroup; - HttpClient httpClient(dispatcher, m_nodeHost, m_nodePort); - m_httpClient = &httpClient; - Event httpEvent(dispatcher); - m_httpEvent = &httpEvent; - m_httpEvent->set(); - - { - std::lock_guard lock(m_mutex); - assert(m_state == STATE_INITIALIZING); - m_state = STATE_INITIALIZED; - m_cv_initialized.notify_all(); - } - - initialized_callback(std::error_code()); - - contextGroup.spawn([this]() { - Timer pullTimer(*m_dispatcher); - while (!m_stop) { - updateNodeStatus(); - if (!m_stop) { - pullTimer.sleep(std::chrono::milliseconds(m_pullInterval)); - } - } - }); - - contextGroup.wait(); - // Make sure all remote spawns are executed - m_dispatcher->yield(); - } catch (std::exception&) { - } - - m_dispatcher = nullptr; - m_context_group = nullptr; - m_httpClient = nullptr; - m_httpEvent = nullptr; - m_connected = false; - m_rpcProxyObserverManager.notify(&INodeRpcProxyObserver::connectionStatusUpdated, m_connected); -} - -void NodeRpcProxy::updateNodeStatus() { - bool updateBlockchain = true; - while (updateBlockchain) { - updateBlockchainStatus(); - updateBlockchain = !updatePoolStatus(); - } -} - -bool NodeRpcProxy::updatePoolStatus() { - std::vector knownTxs = getKnownTxsVector(); - Crypto::Hash tailBlock = m_lastKnowHash; - - bool isBcActual = false; - std::vector> addedTxs; - std::vector deletedTxsIds; - - std::error_code ec = doGetPoolSymmetricDifference(std::move(knownTxs), tailBlock, isBcActual, addedTxs, deletedTxsIds); - if (ec) { - return true; - } - - if (!isBcActual) { - return false; - } - - if (!addedTxs.empty() || !deletedTxsIds.empty()) { - updatePoolState(addedTxs, deletedTxsIds); - m_observerManager.notify(&INodeObserver::poolChanged); - } - - return true; -} - -void NodeRpcProxy::updateBlockchainStatus() { - CryptoNote::COMMAND_RPC_GET_LAST_BLOCK_HEADER::request req = AUTO_VAL_INIT(req); - CryptoNote::COMMAND_RPC_GET_LAST_BLOCK_HEADER::response rsp = AUTO_VAL_INIT(rsp); - - std::error_code ec = jsonRpcCommand("getlastblockheader", req, rsp); - - if (!ec) { - Crypto::Hash blockHash; - if (!parse_hash256(rsp.block_header.hash, blockHash)) { - return; - } - - if (blockHash != m_lastKnowHash) { - m_lastKnowHash = blockHash; - m_nodeHeight.store(static_cast(rsp.block_header.height), std::memory_order_relaxed); - m_lastLocalBlockTimestamp.store(rsp.block_header.timestamp, std::memory_order_relaxed); - m_observerManager.notify(&INodeObserver::localBlockchainUpdated, m_nodeHeight.load(std::memory_order_relaxed)); - } - } - - CryptoNote::COMMAND_RPC_GET_INFO::request getInfoReq = AUTO_VAL_INIT(getInfoReq); - CryptoNote::COMMAND_RPC_GET_INFO::response getInfoResp = AUTO_VAL_INIT(getInfoResp); - - ec = jsonCommand("/getinfo", getInfoReq, getInfoResp); - if (!ec) { - //a quirk to let wallets work with previous versions daemons. - //Previous daemons didn't have the 'last_known_block_index' parameter in RPC so it may have zero value. - auto lastKnownBlockIndex = std::max(getInfoResp.last_known_block_index, m_nodeHeight.load(std::memory_order_relaxed)); - if (m_networkHeight.load(std::memory_order_relaxed) != lastKnownBlockIndex) { - m_networkHeight.store(lastKnownBlockIndex, std::memory_order_relaxed); - m_observerManager.notify(&INodeObserver::lastKnownBlockHeightUpdated, m_networkHeight.load(std::memory_order_relaxed)); - } - - updatePeerCount(getInfoResp.incoming_connections_count + getInfoResp.outgoing_connections_count); - } - - if (m_connected != m_httpClient->isConnected()) { - m_connected = m_httpClient->isConnected(); - m_rpcProxyObserverManager.notify(&INodeRpcProxyObserver::connectionStatusUpdated, m_connected); - } -} - -void NodeRpcProxy::updatePeerCount(size_t peerCount) { - if (peerCount != m_peerCount) { - m_peerCount = peerCount; - m_observerManager.notify(&INodeObserver::peerCountUpdated, m_peerCount.load(std::memory_order_relaxed)); - } -} - -void NodeRpcProxy::updatePoolState(const std::vector>& addedTxs, const std::vector& deletedTxsIds) { - for (const auto& hash : deletedTxsIds) { - m_knownTxs.erase(hash); - } - - for (const auto& tx : addedTxs) { - Hash hash = tx->getTransactionHash(); - m_knownTxs.emplace(std::move(hash)); - } -} - -std::vector NodeRpcProxy::getKnownTxsVector() const { - return std::vector(m_knownTxs.begin(), m_knownTxs.end()); -} - -bool NodeRpcProxy::addObserver(INodeObserver* observer) { - return m_observerManager.add(observer); -} - -bool NodeRpcProxy::removeObserver(INodeObserver* observer) { - return m_observerManager.remove(observer); -} - -bool NodeRpcProxy::addObserver(CryptoNote::INodeRpcProxyObserver* observer) { - return m_rpcProxyObserverManager.add(observer); -} - -bool NodeRpcProxy::removeObserver(CryptoNote::INodeRpcProxyObserver* observer) { - return m_rpcProxyObserverManager.remove(observer); -} - -size_t NodeRpcProxy::getPeerCount() const { - return m_peerCount.load(std::memory_order_relaxed); -} - -uint32_t NodeRpcProxy::getLastLocalBlockHeight() const { - return m_nodeHeight.load(std::memory_order_relaxed); -} - -uint32_t NodeRpcProxy::getLastKnownBlockHeight() const { - return m_networkHeight.load(std::memory_order_relaxed); -} - -uint32_t NodeRpcProxy::getLocalBlockCount() const { - return m_nodeHeight.load(std::memory_order_relaxed); -} - -uint32_t NodeRpcProxy::getKnownBlockCount() const { - return m_networkHeight.load(std::memory_order_relaxed) + 1; -} - -uint64_t NodeRpcProxy::getLastLocalBlockTimestamp() const { - return m_lastLocalBlockTimestamp; -} - -void NodeRpcProxy::relayTransaction(const CryptoNote::Transaction& transaction, const Callback& callback) { - std::lock_guard lock(m_mutex); - if (m_state != STATE_INITIALIZED) { - callback(make_error_code(error::NOT_INITIALIZED)); - return; - } - - scheduleRequest(std::bind(&NodeRpcProxy::doRelayTransaction, this, transaction), callback); -} - -void NodeRpcProxy::getRandomOutsByAmounts(std::vector&& amounts, uint64_t outsCount, - std::vector& outs, - const Callback& callback) { - std::lock_guard lock(m_mutex); - if (m_state != STATE_INITIALIZED) { - callback(make_error_code(error::NOT_INITIALIZED)); - return; - } - - scheduleRequest(std::bind(&NodeRpcProxy::doGetRandomOutsByAmounts, this, std::move(amounts), outsCount, std::ref(outs)), - callback); -} - -void NodeRpcProxy::getNewBlocks(std::vector&& knownBlockIds, - std::vector& newBlocks, - uint32_t& startHeight, - const Callback& callback) { - std::lock_guard lock(m_mutex); - if (m_state != STATE_INITIALIZED) { - callback(make_error_code(error::NOT_INITIALIZED)); - return; - } - - scheduleRequest(std::bind(&NodeRpcProxy::doGetNewBlocks, this, std::move(knownBlockIds), std::ref(newBlocks), - std::ref(startHeight)), callback); -} - -void NodeRpcProxy::getTransactionOutsGlobalIndices(const Crypto::Hash& transactionHash, - std::vector& outsGlobalIndices, const Callback& callback) { - std::lock_guard lock(m_mutex); - if (m_state != STATE_INITIALIZED) { - callback(make_error_code(error::NOT_INITIALIZED)); - return; - } - - scheduleRequest(std::bind(&NodeRpcProxy::doGetTransactionOutsGlobalIndices, this, transactionHash, - std::ref(outsGlobalIndices)), callback); -} - -void NodeRpcProxy::queryBlocks(std::vector&& knownBlockIds, uint64_t timestamp, std::vector& newBlocks, - uint32_t& startHeight, const Callback& callback) { - std::lock_guard lock(m_mutex); - if (m_state != STATE_INITIALIZED) { - callback(make_error_code(error::NOT_INITIALIZED)); - return; - } - - scheduleRequest(std::bind(&NodeRpcProxy::doQueryBlocksLite, this, std::move(knownBlockIds), timestamp, - std::ref(newBlocks), std::ref(startHeight)), callback); -} - -void NodeRpcProxy::getPoolSymmetricDifference(std::vector&& knownPoolTxIds, Crypto::Hash knownBlockId, bool& isBcActual, - std::vector>& newTxs, std::vector& deletedTxIds, const Callback& callback) { - std::lock_guard lock(m_mutex); - if (m_state != STATE_INITIALIZED) { - callback(make_error_code(error::NOT_INITIALIZED)); - return; - } - - scheduleRequest([this, knownPoolTxIds, knownBlockId, &isBcActual, &newTxs, &deletedTxIds] () mutable -> std::error_code { - return this->doGetPoolSymmetricDifference(std::move(knownPoolTxIds), knownBlockId, isBcActual, newTxs, deletedTxIds); } , callback); -} - -void NodeRpcProxy::getMultisignatureOutputByGlobalIndex(uint64_t amount, uint32_t gindex, MultisignatureOutput& out, const Callback& callback) { - std::lock_guard lock(m_mutex); - if (m_state != STATE_INITIALIZED) { - callback(make_error_code(error::NOT_INITIALIZED)); - return; - } - - // TODO NOT IMPLEMENTED - callback(std::error_code()); -} - -void NodeRpcProxy::getBlocks(const std::vector& blockHeights, std::vector>& blocks, const Callback& callback) { - std::lock_guard lock(m_mutex); - if (m_state != STATE_INITIALIZED) { - callback(make_error_code(error::NOT_INITIALIZED)); - return; - } - - // TODO NOT IMPLEMENTED - callback(std::error_code()); -} - -void NodeRpcProxy::getBlocks(uint64_t timestampBegin, uint64_t timestampEnd, uint32_t blocksNumberLimit, std::vector& blocks, uint32_t& blocksNumberWithinTimestamps, const Callback& callback) { - std::lock_guard lock(m_mutex); - if (m_state != STATE_INITIALIZED) { - callback(make_error_code(error::NOT_INITIALIZED)); - return; - } - - // TODO NOT IMPLEMENTED - callback(std::error_code()); -} - -void NodeRpcProxy::getBlocks(const std::vector& blockHashes, std::vector& blocks, const Callback& callback) { - std::lock_guard lock(m_mutex); - if (m_state != STATE_INITIALIZED) { - callback(make_error_code(error::NOT_INITIALIZED)); - return; - } - - // TODO NOT IMPLEMENTED - callback(std::error_code()); -} - -void NodeRpcProxy::getTransactions(const std::vector& transactionHashes, std::vector& transactions, const Callback& callback) { - std::lock_guard lock(m_mutex); - if (m_state != STATE_INITIALIZED) { - callback(make_error_code(error::NOT_INITIALIZED)); - return; - } - - // TODO NOT IMPLEMENTED - callback(std::error_code()); -} - -void NodeRpcProxy::getPoolTransactions(uint64_t timestampBegin, uint64_t timestampEnd, uint32_t transactionsNumberLimit, std::vector& transactions, uint64_t& transactionsNumberWithinTimestamps, const Callback& callback) { - std::lock_guard lock(m_mutex); - if (m_state != STATE_INITIALIZED) { - callback(make_error_code(error::NOT_INITIALIZED)); - return; - } - - // TODO NOT IMPLEMENTED - callback(std::error_code()); -} - -void NodeRpcProxy::getTransactionsByPaymentId(const Crypto::Hash& paymentId, std::vector& transactions, const Callback& callback) { - std::lock_guard lock(m_mutex); - if (m_state != STATE_INITIALIZED) { - callback(make_error_code(error::NOT_INITIALIZED)); - return; - } - - // TODO NOT IMPLEMENTED - callback(std::error_code()); -} - -void NodeRpcProxy::isSynchronized(bool& syncStatus, const Callback& callback) { - std::lock_guard lock(m_mutex); - if (m_state != STATE_INITIALIZED) { - callback(make_error_code(error::NOT_INITIALIZED)); - return; - } - - // TODO NOT IMPLEMENTED - callback(std::error_code()); -} - -std::error_code NodeRpcProxy::doRelayTransaction(const CryptoNote::Transaction& transaction) { - COMMAND_RPC_SEND_RAW_TX::request req; - COMMAND_RPC_SEND_RAW_TX::response rsp; - req.tx_as_hex = toHex(toBinaryArray(transaction)); - return jsonCommand("/sendrawtransaction", req, rsp); -} - -std::error_code NodeRpcProxy::doGetRandomOutsByAmounts(std::vector& amounts, uint64_t outsCount, - std::vector& outs) { - COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::request req = AUTO_VAL_INIT(req); - COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::response rsp = AUTO_VAL_INIT(rsp); - req.amounts = std::move(amounts); - req.outs_count = outsCount; - - std::error_code ec = binaryCommand("/getrandom_outs.bin", req, rsp); - if (!ec) { - outs = std::move(rsp.outs); - } - - return ec; -} - -std::error_code NodeRpcProxy::doGetNewBlocks(std::vector& knownBlockIds, - std::vector& newBlocks, - uint32_t& startHeight) { - CryptoNote::COMMAND_RPC_GET_BLOCKS_FAST::request req = AUTO_VAL_INIT(req); - CryptoNote::COMMAND_RPC_GET_BLOCKS_FAST::response rsp = AUTO_VAL_INIT(rsp); - req.block_ids = std::move(knownBlockIds); - - std::error_code ec = binaryCommand("/getblocks.bin", req, rsp); - if (!ec) { - newBlocks = std::move(rsp.blocks); - startHeight = static_cast(rsp.start_height); - } - - return ec; -} - -std::error_code NodeRpcProxy::doGetTransactionOutsGlobalIndices(const Crypto::Hash& transactionHash, - std::vector& outsGlobalIndices) { - CryptoNote::COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::request req = AUTO_VAL_INIT(req); - CryptoNote::COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::response rsp = AUTO_VAL_INIT(rsp); - req.txid = transactionHash; - - std::error_code ec = binaryCommand("/get_o_indexes.bin", req, rsp); - if (!ec) { - outsGlobalIndices.clear(); - for (auto idx : rsp.o_indexes) { - outsGlobalIndices.push_back(static_cast(idx)); - } - } - - return ec; -} - -std::error_code NodeRpcProxy::doQueryBlocksLite(const std::vector& knownBlockIds, uint64_t timestamp, - std::vector& newBlocks, uint32_t& startHeight) { - CryptoNote::COMMAND_RPC_QUERY_BLOCKS_LITE::request req = AUTO_VAL_INIT(req); - CryptoNote::COMMAND_RPC_QUERY_BLOCKS_LITE::response rsp = AUTO_VAL_INIT(rsp); - - req.blockIds = knownBlockIds; - req.timestamp = timestamp; - - std::error_code ec = binaryCommand("/queryblockslite.bin", req, rsp); - if (ec) { - return ec; - } - - startHeight = static_cast(rsp.startHeight); - - for (auto& item: rsp.items) { - BlockShortEntry bse; - bse.hasBlock = false; - - bse.blockHash = std::move(item.blockId); - if (!item.block.empty()) { - if (!fromBinaryArray(bse.block, asBinaryArray(item.block))) { - return std::make_error_code(std::errc::invalid_argument); - } - - bse.hasBlock = true; - } - - for (const auto& txp: item.txPrefixes) { - TransactionShortInfo tsi; - tsi.txId = txp.txHash; - tsi.txPrefix = txp.txPrefix; - bse.txsShortInfo.push_back(std::move(tsi)); - } - - newBlocks.push_back(std::move(bse)); - } - - return std::error_code(); -} - -std::error_code NodeRpcProxy::doGetPoolSymmetricDifference(std::vector&& knownPoolTxIds, Crypto::Hash knownBlockId, bool& isBcActual, - std::vector>& newTxs, std::vector& deletedTxIds) { - CryptoNote::COMMAND_RPC_GET_POOL_CHANGES_LITE::request req = AUTO_VAL_INIT(req); - CryptoNote::COMMAND_RPC_GET_POOL_CHANGES_LITE::response rsp = AUTO_VAL_INIT(rsp); - - req.tailBlockId = knownBlockId; - req.knownTxsIds = knownPoolTxIds; - - std::error_code ec = binaryCommand("/get_pool_changes_lite.bin", req, rsp); - - if (ec) { - return ec; - } - - isBcActual = rsp.isTailBlockActual; - - deletedTxIds = std::move(rsp.deletedTxsIds); - - for (const auto& tpi : rsp.addedTxs) { - newTxs.push_back(createTransactionPrefix(tpi.txPrefix, tpi.txHash)); - } - - return ec; -} - -void NodeRpcProxy::scheduleRequest(std::function&& procedure, const Callback& callback) { - // callback is located on stack, so copy it inside binder - class Wrapper { - public: - Wrapper(std::function&, Callback&)>&& _func, - std::function&& _procedure, const Callback& _callback) - : func(std::move(_func)), procedure(std::move(_procedure)), callback(std::move(_callback)) { - } - Wrapper(const Wrapper& other) - : func(other.func), procedure(other.procedure), callback(other.callback) { - } - Wrapper(Wrapper&& other) // must be noexcept - : func(std::move(other.func)), procedure(std::move(other.procedure)), callback(std::move(other.callback)) { - } - void operator()() { - func(procedure, callback); - } - private: - std::function&, Callback&)> func; - std::function procedure; - Callback callback; - }; - assert(m_dispatcher != nullptr && m_context_group != nullptr); - m_dispatcher->remoteSpawn(Wrapper([this](std::function& procedure, Callback& callback) { - m_context_group->spawn(Wrapper([this](std::function& procedure, const Callback& callback) { - if (m_stop) { - callback(std::make_error_code(std::errc::operation_canceled)); - } else { - std::error_code ec = procedure(); - if (m_connected != m_httpClient->isConnected()) { - m_connected = m_httpClient->isConnected(); - m_rpcProxyObserverManager.notify(&INodeRpcProxyObserver::connectionStatusUpdated, m_connected); - } - callback(m_stop ? std::make_error_code(std::errc::operation_canceled) : ec); - } - }, std::move(procedure), std::move(callback))); - }, std::move(procedure), callback)); -} - -template -std::error_code NodeRpcProxy::binaryCommand(const std::string& url, const Request& req, Response& res) { - std::error_code ec; - - try { - EventLock eventLock(*m_httpEvent); - invokeBinaryCommand(*m_httpClient, url, req, res); - ec = interpretResponseStatus(res.status); - } catch (const ConnectException&) { - ec = make_error_code(error::CONNECT_ERROR); - } catch (const std::exception&) { - ec = make_error_code(error::NETWORK_ERROR); - } - - return ec; -} - -template -std::error_code NodeRpcProxy::jsonCommand(const std::string& url, const Request& req, Response& res) { - std::error_code ec; - - try { - EventLock eventLock(*m_httpEvent); - invokeJsonCommand(*m_httpClient, url, req, res); - ec = interpretResponseStatus(res.status); - } catch (const ConnectException&) { - ec = make_error_code(error::CONNECT_ERROR); - } catch (const std::exception&) { - ec = make_error_code(error::NETWORK_ERROR); - } - - return ec; -} - -template -std::error_code NodeRpcProxy::jsonRpcCommand(const std::string& method, const Request& req, Response& res) { - std::error_code ec = make_error_code(error::INTERNAL_NODE_ERROR); - - try { - EventLock eventLock(*m_httpEvent); - - JsonRpc::JsonRpcRequest jsReq; - - jsReq.setMethod(method); - jsReq.setParams(req); - - HttpRequest httpReq; - HttpResponse httpRes; - - httpReq.setUrl("/json_rpc"); - httpReq.setBody(jsReq.getBody()); - - m_httpClient->request(httpReq, httpRes); - - JsonRpc::JsonRpcResponse jsRes; - - if (httpRes.getStatus() == HttpResponse::STATUS_200) { - jsRes.parse(httpRes.getBody()); - if (jsRes.getResult(res)) { - ec = interpretResponseStatus(res.status); - } - } - } catch (const ConnectException&) { - ec = make_error_code(error::CONNECT_ERROR); - } catch (const std::exception&) { - ec = make_error_code(error::NETWORK_ERROR); - } - - return ec; -} - -} From 501c7b97db69d5b24e4705406f15cdcaba5beafa Mon Sep 17 00:00:00 2001 From: conflictwar <78981120+conflictwar@users.noreply.github.com> Date: Wed, 2 Jun 2021 02:07:24 -0500 Subject: [PATCH 03/12] Create 2msbuild.yml --- .github/workflows/2msbuild.yml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .github/workflows/2msbuild.yml diff --git a/.github/workflows/2msbuild.yml b/.github/workflows/2msbuild.yml new file mode 100644 index 0000000000..29b6acebc1 --- /dev/null +++ b/.github/workflows/2msbuild.yml @@ -0,0 +1,32 @@ +name: MSBuild + +on: [push] + +env: + # Path to the solution file relative to the root of the project. + SOLUTION_FILE_PATH: . + + # Configuration type to build. + # You can convert this to a build matrix if you need coverage of multiple configuration types. + # https://docs.github.com/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix + BUILD_CONFIGURATION: Release + +jobs: + build: + runs-on: windows-latest + + steps: + - uses: actions/checkout@v2 + + - name: Add MSBuild to PATH + uses: microsoft/setup-msbuild@v1.0.2 + + - name: Restore NuGet packages + working-directory: ${{env.GITHUB_WORKSPACE}} + run: nuget restore ${{env.SOLUTION_FILE_PATH}} + + - name: Build + working-directory: ${{env.GITHUB_WORKSPACE}} + # Add additional options to the MSBuild command line here (like platform or verbosity level). + # See https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference + run: msbuild /m /p:Configuration=${{env.BUILD_CONFIGURATION}} ${{env.SOLUTION_FILE_PATH}} From aa9bbdf1e4ca1cd4888917d869bd42e1dbb8f74c Mon Sep 17 00:00:00 2001 From: conflictwar <78981120+conflictwar@users.noreply.github.com> Date: Wed, 2 Jun 2021 02:12:50 -0500 Subject: [PATCH 04/12] Create cmake.yml --- .github/workflows/cmake.yml | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .github/workflows/cmake.yml diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml new file mode 100644 index 0000000000..e282e38914 --- /dev/null +++ b/.github/workflows/cmake.yml @@ -0,0 +1,38 @@ +name: CMake + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +env: + # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) + BUILD_TYPE: Release + +jobs: + build: + # The CMake configure and build commands are platform agnostic and should work equally + # well on Windows or Mac. You can convert this to a matrix build if you need + # cross-platform coverage. + # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Configure CMake + # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. + # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type + run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + + - name: Build + # Build your program with the given configuration + run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} + + - name: Test + working-directory: ${{github.workspace}}/build + # Execute tests defined by the CMake configuration. + # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail + run: ctest -C ${{env.BUILD_TYPE}} + From 562f3030d69973af816a4658bb24589ae12a27f6 Mon Sep 17 00:00:00 2001 From: conflictwar <78981120+conflictwar@users.noreply.github.com> Date: Wed, 2 Jun 2021 02:13:38 -0500 Subject: [PATCH 05/12] Create openshift.yml --- .github/workflows/openshift.yml | 179 ++++++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100644 .github/workflows/openshift.yml diff --git a/.github/workflows/openshift.yml b/.github/workflows/openshift.yml new file mode 100644 index 0000000000..11b0f57adf --- /dev/null +++ b/.github/workflows/openshift.yml @@ -0,0 +1,179 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +### The OpenShift Starter workflow will: +# - Checkout your repository +# - Perform a Docker build +# - Push the built image to an image registry +# - Log in to your OpenShift cluster +# - Create an OpenShift app from the image and expose it to the internet. + +### Before you begin: +# - Have write access to a container image registry such as quay.io or Dockerhub. +# - Have access to an OpenShift cluster. +# - For instructions to get started with OpenShift see https://www.openshift.com/try +# - The project you wish to add this workflow to should have a Dockerfile. +# - If you don't have a Dockerfile at the repository root, see the buildah-build step. +# - Builds from scratch are also available, but require more configuration. + +### To get the workflow running: +# 1. Add this workflow to your repository. +# 2. Edit the top-level 'env' section, which contains a list of environment variables that must be configured. +# 3. Create the secrets referenced in the 'env' section under your repository Settings. +# 4. Edit the 'branches' in the 'on' section to trigger the workflow on a push to your branch. +# 5. Commit and push your changes. + +# For a more sophisticated example, see https://github.com/redhat-actions/spring-petclinic/blob/main/.github/workflows/petclinic-sample.yaml +# Also see our GitHub organization, https://github.com/redhat-actions/ +# ▶️ See a video of how to set up this workflow at https://www.youtube.com/watch?v=6hgBO-1pKho + +name: OpenShift + +# ⬇️ Modify the fields marked with ⬇️ to fit your project, and create any secrets that are referenced. +# https://docs.github.com/en/free-pro-team@latest/actions/reference/encrypted-secrets +env: + # ⬇️ EDIT with your registry and registry path. + REGISTRY: quay.io/ + # ⬇️ EDIT with your registry username. + REGISTRY_USER: + REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }} + + # ⬇️ EDIT to log into your OpenShift cluster and set up the context. + # See https://github.com/redhat-actions/oc-login#readme for how to retrieve these values. + OPENSHIFT_SERVER: ${{ secrets.OPENSHIFT_SERVER }} + OPENSHIFT_TOKEN: ${{ secrets.OPENSHIFT_TOKEN }} + + # ⬇️ EDIT with any additional port your application should expose. + # By default, oc new-app action creates a service to the image's lowest numeric exposed port. + APP_PORT: "" + + # ⬇️ EDIT if you wish to set the kube context's namespace after login. Leave blank to use the default namespace. + OPENSHIFT_NAMESPACE: "" + + # If you wish to manually provide the APP_NAME and TAG, set them here, otherwise they will be auto-detected. + APP_NAME: "" + TAG: "" + +on: + # https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows + push: + # Edit to the branch(es) you want to build and deploy on each push. + branches: [ master ] + +jobs: + openshift-ci-cd: + name: Build and deploy to OpenShift + runs-on: ubuntu-18.04 + environment: production + + outputs: + ROUTE: ${{ steps.deploy-and-expose.outputs.route }} + SELECTOR: ${{ steps.deploy-and-expose.outputs.selector }} + + steps: + - name: Check if secrets exists + uses: actions/github-script@v3 + with: + script: | + const secrets = { + REGISTRY_PASSWORD: `${{ secrets.REGISTRY_PASSWORD }}`, + OPENSHIFT_SERVER: `${{ secrets.OPENSHIFT_SERVER }}`, + OPENSHIFT_TOKEN: `${{ secrets.OPENSHIFT_TOKEN }}`, + }; + + const missingSecrets = Object.entries(secrets).filter(([ name, value ]) => { + if (value.length === 0) { + core.warning(`Secret "${name}" is not set`); + return true; + } + core.info(`✔️ Secret "${name}" is set`); + return false; + + }); + + if (missingSecrets.length > 0) { + core.setFailed(`❌ At least one required secret is not set in the repository. \n` + + "You can add it using:\n" + + "GitHub UI: https://docs.github.com/en/actions/reference/encrypted-secrets#creating-encrypted-secrets-for-a-repository \n" + + "GitHub CLI: https://cli.github.com/manual/gh_secret_set \n" + + "Also, refer to https://github.com/redhat-actions/oc-login#getting-started-with-the-action-or-see-example"); + } + else { + core.info(`✅ All the required secrets are set`); + } + + - uses: actions/checkout@v2 + + - name: Determine app name + if: env.APP_NAME == '' + run: | + echo "APP_NAME=$(basename $PWD)" | tee -a $GITHUB_ENV + + - name: Determine tag + if: env.TAG == '' + run: | + echo "TAG=${GITHUB_SHA::7}" | tee -a $GITHUB_ENV + + # https://github.com/redhat-actions/buildah-build#readme + - name: Build from Dockerfile + id: image-build + uses: redhat-actions/buildah-build@v2 + with: + image: ${{ env.APP_NAME }} + tags: ${{ env.TAG }} + # If you don't have a dockerfile, see: + # https://github.com/redhat-actions/buildah-build#scratch-build-inputs + # Otherwise, point this to your Dockerfile relative to the repository root. + dockerfiles: | + ./Dockerfile + + # https://github.com/redhat-actions/push-to-registry#readme + - name: Push to registry + id: push-to-registry + uses: redhat-actions/push-to-registry@v2 + with: + image: ${{ steps.image-build.outputs.image }} + tags: ${{ steps.image-build.outputs.tags }} + registry: ${{ env.REGISTRY }} + username: ${{ env.REGISTRY_USER }} + password: ${{ env.REGISTRY_PASSWORD }} + + # The path the image was pushed to is now stored in ${{ steps.push-to-registry.outputs.registry-path }} + + # oc-login works on all platforms, but oc must be installed first. + # The GitHub Ubuntu runner already includes oc. + # Otherwise, https://github.com/redhat-actions/oc-installer#readme is available. + + # https://github.com/redhat-actions/oc-login#readme + - name: Log in to OpenShift + uses: redhat-actions/oc-login@v1 + with: + openshift_server_url: ${{ env.OPENSHIFT_SERVER }} + openshift_token: ${{ env.OPENSHIFT_TOKEN }} + insecure_skip_tls_verify: true + namespace: ${{ env.OPENSHIFT_NAMESPACE }} + + # This step should create a deployment, service, and route to run your app and expose it to the internet. + # https://github.com/redhat-actions/oc-new-app#readme + - name: Create and expose app + id: deploy-and-expose + uses: redhat-actions/oc-new-app@v1 + with: + app_name: ${{ env.APP_NAME }} + image: ${{ steps.push-to-registry.outputs.registry-path }} + namespace: ${{ env.OPENSHIFT_NAMESPACE }} + port: ${{ env.APP_PORT }} + + - name: View application route + run: | + [[ -n ${{ env.ROUTE }} ]] || (echo "Determining application route failed in previous step"; exit 1) + echo "======================== Your application is available at: ========================" + echo ${{ env.ROUTE }} + echo "===================================================================================" + echo + echo "Your app can be taken down with: \"oc delete all --selector='${{ env.SELECTOR }}'\"" + env: + ROUTE: ${{ steps.deploy-and-expose.outputs.route }} + SELECTOR: ${{ steps.deploy-and-expose.outputs.selector }} From 0c0f697defc9a797fefecf2bfe65fc29be08b504 Mon Sep 17 00:00:00 2001 From: conflictwar <78981120+conflictwar@users.noreply.github.com> Date: Wed, 2 Jun 2021 02:13:39 -0500 Subject: [PATCH 06/12] Create openshift.yml --- .github/workflows/openshift.yml | 179 ++++++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100644 .github/workflows/openshift.yml diff --git a/.github/workflows/openshift.yml b/.github/workflows/openshift.yml new file mode 100644 index 0000000000..11b0f57adf --- /dev/null +++ b/.github/workflows/openshift.yml @@ -0,0 +1,179 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +### The OpenShift Starter workflow will: +# - Checkout your repository +# - Perform a Docker build +# - Push the built image to an image registry +# - Log in to your OpenShift cluster +# - Create an OpenShift app from the image and expose it to the internet. + +### Before you begin: +# - Have write access to a container image registry such as quay.io or Dockerhub. +# - Have access to an OpenShift cluster. +# - For instructions to get started with OpenShift see https://www.openshift.com/try +# - The project you wish to add this workflow to should have a Dockerfile. +# - If you don't have a Dockerfile at the repository root, see the buildah-build step. +# - Builds from scratch are also available, but require more configuration. + +### To get the workflow running: +# 1. Add this workflow to your repository. +# 2. Edit the top-level 'env' section, which contains a list of environment variables that must be configured. +# 3. Create the secrets referenced in the 'env' section under your repository Settings. +# 4. Edit the 'branches' in the 'on' section to trigger the workflow on a push to your branch. +# 5. Commit and push your changes. + +# For a more sophisticated example, see https://github.com/redhat-actions/spring-petclinic/blob/main/.github/workflows/petclinic-sample.yaml +# Also see our GitHub organization, https://github.com/redhat-actions/ +# ▶️ See a video of how to set up this workflow at https://www.youtube.com/watch?v=6hgBO-1pKho + +name: OpenShift + +# ⬇️ Modify the fields marked with ⬇️ to fit your project, and create any secrets that are referenced. +# https://docs.github.com/en/free-pro-team@latest/actions/reference/encrypted-secrets +env: + # ⬇️ EDIT with your registry and registry path. + REGISTRY: quay.io/ + # ⬇️ EDIT with your registry username. + REGISTRY_USER: + REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }} + + # ⬇️ EDIT to log into your OpenShift cluster and set up the context. + # See https://github.com/redhat-actions/oc-login#readme for how to retrieve these values. + OPENSHIFT_SERVER: ${{ secrets.OPENSHIFT_SERVER }} + OPENSHIFT_TOKEN: ${{ secrets.OPENSHIFT_TOKEN }} + + # ⬇️ EDIT with any additional port your application should expose. + # By default, oc new-app action creates a service to the image's lowest numeric exposed port. + APP_PORT: "" + + # ⬇️ EDIT if you wish to set the kube context's namespace after login. Leave blank to use the default namespace. + OPENSHIFT_NAMESPACE: "" + + # If you wish to manually provide the APP_NAME and TAG, set them here, otherwise they will be auto-detected. + APP_NAME: "" + TAG: "" + +on: + # https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows + push: + # Edit to the branch(es) you want to build and deploy on each push. + branches: [ master ] + +jobs: + openshift-ci-cd: + name: Build and deploy to OpenShift + runs-on: ubuntu-18.04 + environment: production + + outputs: + ROUTE: ${{ steps.deploy-and-expose.outputs.route }} + SELECTOR: ${{ steps.deploy-and-expose.outputs.selector }} + + steps: + - name: Check if secrets exists + uses: actions/github-script@v3 + with: + script: | + const secrets = { + REGISTRY_PASSWORD: `${{ secrets.REGISTRY_PASSWORD }}`, + OPENSHIFT_SERVER: `${{ secrets.OPENSHIFT_SERVER }}`, + OPENSHIFT_TOKEN: `${{ secrets.OPENSHIFT_TOKEN }}`, + }; + + const missingSecrets = Object.entries(secrets).filter(([ name, value ]) => { + if (value.length === 0) { + core.warning(`Secret "${name}" is not set`); + return true; + } + core.info(`✔️ Secret "${name}" is set`); + return false; + + }); + + if (missingSecrets.length > 0) { + core.setFailed(`❌ At least one required secret is not set in the repository. \n` + + "You can add it using:\n" + + "GitHub UI: https://docs.github.com/en/actions/reference/encrypted-secrets#creating-encrypted-secrets-for-a-repository \n" + + "GitHub CLI: https://cli.github.com/manual/gh_secret_set \n" + + "Also, refer to https://github.com/redhat-actions/oc-login#getting-started-with-the-action-or-see-example"); + } + else { + core.info(`✅ All the required secrets are set`); + } + + - uses: actions/checkout@v2 + + - name: Determine app name + if: env.APP_NAME == '' + run: | + echo "APP_NAME=$(basename $PWD)" | tee -a $GITHUB_ENV + + - name: Determine tag + if: env.TAG == '' + run: | + echo "TAG=${GITHUB_SHA::7}" | tee -a $GITHUB_ENV + + # https://github.com/redhat-actions/buildah-build#readme + - name: Build from Dockerfile + id: image-build + uses: redhat-actions/buildah-build@v2 + with: + image: ${{ env.APP_NAME }} + tags: ${{ env.TAG }} + # If you don't have a dockerfile, see: + # https://github.com/redhat-actions/buildah-build#scratch-build-inputs + # Otherwise, point this to your Dockerfile relative to the repository root. + dockerfiles: | + ./Dockerfile + + # https://github.com/redhat-actions/push-to-registry#readme + - name: Push to registry + id: push-to-registry + uses: redhat-actions/push-to-registry@v2 + with: + image: ${{ steps.image-build.outputs.image }} + tags: ${{ steps.image-build.outputs.tags }} + registry: ${{ env.REGISTRY }} + username: ${{ env.REGISTRY_USER }} + password: ${{ env.REGISTRY_PASSWORD }} + + # The path the image was pushed to is now stored in ${{ steps.push-to-registry.outputs.registry-path }} + + # oc-login works on all platforms, but oc must be installed first. + # The GitHub Ubuntu runner already includes oc. + # Otherwise, https://github.com/redhat-actions/oc-installer#readme is available. + + # https://github.com/redhat-actions/oc-login#readme + - name: Log in to OpenShift + uses: redhat-actions/oc-login@v1 + with: + openshift_server_url: ${{ env.OPENSHIFT_SERVER }} + openshift_token: ${{ env.OPENSHIFT_TOKEN }} + insecure_skip_tls_verify: true + namespace: ${{ env.OPENSHIFT_NAMESPACE }} + + # This step should create a deployment, service, and route to run your app and expose it to the internet. + # https://github.com/redhat-actions/oc-new-app#readme + - name: Create and expose app + id: deploy-and-expose + uses: redhat-actions/oc-new-app@v1 + with: + app_name: ${{ env.APP_NAME }} + image: ${{ steps.push-to-registry.outputs.registry-path }} + namespace: ${{ env.OPENSHIFT_NAMESPACE }} + port: ${{ env.APP_PORT }} + + - name: View application route + run: | + [[ -n ${{ env.ROUTE }} ]] || (echo "Determining application route failed in previous step"; exit 1) + echo "======================== Your application is available at: ========================" + echo ${{ env.ROUTE }} + echo "===================================================================================" + echo + echo "Your app can be taken down with: \"oc delete all --selector='${{ env.SELECTOR }}'\"" + env: + ROUTE: ${{ steps.deploy-and-expose.outputs.route }} + SELECTOR: ${{ steps.deploy-and-expose.outputs.selector }} From 3f334eb0e062ef98ea7aa831fa32e265f8a125aa Mon Sep 17 00:00:00 2001 From: conflictwar <78981120+conflictwar@users.noreply.github.com> Date: Wed, 2 Jun 2021 02:15:13 -0500 Subject: [PATCH 07/12] Create ruby.yml --- .github/workflows/ruby.yml | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .github/workflows/ruby.yml diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml new file mode 100644 index 0000000000..e26f6edf7e --- /dev/null +++ b/.github/workflows/ruby.yml @@ -0,0 +1,35 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. +# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake +# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby + +name: Ruby + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + test: + + runs-on: ubuntu-latest + strategy: + matrix: + ruby-version: ['2.6', '2.7', '3.0'] + + steps: + - uses: actions/checkout@v2 + - name: Set up Ruby + # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby, + # change this to (see https://github.com/ruby/setup-ruby#versioning): + # uses: ruby/setup-ruby@v1 + uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e + with: + ruby-version: ${{ matrix.ruby-version }} + bundler-cache: true # runs 'bundle install' and caches installed gems automatically + - name: Run tests + run: bundle exec rake From dcb5b52f197942aeafcd72c49cb735940137cc7d Mon Sep 17 00:00:00 2001 From: conflictwar <78981120+conflictwar@users.noreply.github.com> Date: Wed, 2 Jun 2021 02:21:37 -0500 Subject: [PATCH 08/12] Create docker-publish.yml --- .github/workflows/docker-publish.yml | 80 ++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 .github/workflows/docker-publish.yml diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000000..088eb70920 --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,80 @@ +name: Docker + +on: + push: + # Publish `master` as Docker `latest` image. + branches: + - master + + # Publish `v1.2.3` tags as releases. + tags: + - v* + + # Run tests for any PRs. + pull_request: + +env: + # TODO: Change variable to your image's name. + IMAGE_NAME: image + +jobs: + # Run tests. + # See also https://docs.docker.com/docker-hub/builds/automated-testing/ + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Run tests + run: | + if [ -f docker-compose.test.yml ]; then + docker-compose --file docker-compose.test.yml build + docker-compose --file docker-compose.test.yml run sut + else + docker build . --file Dockerfile + fi + + # Push image to GitHub Packages. + # See also https://docs.docker.com/docker-hub/builds/ + push: + # Ensure test job passes before pushing image. + needs: test + + runs-on: ubuntu-latest + if: github.event_name == 'push' + + permissions: + contents: read + packages: write + + steps: + - uses: actions/checkout@v2 + + - name: Build image + run: docker build . --file Dockerfile --tag $IMAGE_NAME + + - name: Log into registry + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin + + - name: Push image + run: | + IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME + + # Change all uppercase to lowercase + IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') + + # Strip git ref prefix from version + VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') + + # Strip "v" prefix from tag name + [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') + + # Use Docker `latest` tag convention + [ "$VERSION" == "master" ] && VERSION=latest + + echo IMAGE_ID=$IMAGE_ID + echo VERSION=$VERSION + + docker tag $IMAGE_NAME $IMAGE_ID:$VERSION + docker push $IMAGE_ID:$VERSION From beb14df173ccef71a499d5bacb38cb9ae9e02ca2 Mon Sep 17 00:00:00 2001 From: conflictwar <78981120+conflictwar@users.noreply.github.com> Date: Wed, 2 Jun 2021 02:23:31 -0500 Subject: [PATCH 09/12] Create greetings.yml --- .github/workflows/greetings.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .github/workflows/greetings.yml diff --git a/.github/workflows/greetings.yml b/.github/workflows/greetings.yml new file mode 100644 index 0000000000..ee1cb11677 --- /dev/null +++ b/.github/workflows/greetings.yml @@ -0,0 +1,16 @@ +name: Greetings + +on: [pull_request, issues] + +jobs: + greeting: + runs-on: ubuntu-latest + permissions: + issues: write + pull-requests: write + steps: + - uses: actions/first-interaction@v1 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + issue-message: 'Message that will be displayed on users first issue' + pr-message: 'Message that will be displayed on users first pull request' From e663c0c6d3ac74cc3211cd2ac2a31cbd987ad9cd Mon Sep 17 00:00:00 2001 From: conflictwar <78981120+conflictwar@users.noreply.github.com> Date: Wed, 2 Jun 2021 02:23:41 -0500 Subject: [PATCH 10/12] Create label.yml --- .github/workflows/label.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/workflows/label.yml diff --git a/.github/workflows/label.yml b/.github/workflows/label.yml new file mode 100644 index 0000000000..5cdc45e6d4 --- /dev/null +++ b/.github/workflows/label.yml @@ -0,0 +1,22 @@ +# This workflow will triage pull requests and apply a label based on the +# paths that are modified in the pull request. +# +# To use this workflow, you will need to set up a .github/labeler.yml +# file with configuration. For more information, see: +# https://github.com/actions/labeler + +name: Labeler +on: [pull_request] + +jobs: + label: + + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write + + steps: + - uses: actions/labeler@v2 + with: + repo-token: "${{ secrets.GITHUB_TOKEN }}" From baa59d3a4c8d6f917cf2275a7dfa1c02e2c5e645 Mon Sep 17 00:00:00 2001 From: conflictwar <78981120+conflictwar@users.noreply.github.com> Date: Wed, 2 Jun 2021 02:23:51 -0500 Subject: [PATCH 11/12] Create manual.yml --- .github/workflows/manual.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/manual.yml diff --git a/.github/workflows/manual.yml b/.github/workflows/manual.yml new file mode 100644 index 0000000000..47f24e11ff --- /dev/null +++ b/.github/workflows/manual.yml @@ -0,0 +1,30 @@ +# This is a basic workflow that is manually triggered + +name: Manual workflow + +# Controls when the action will run. Workflow runs when manually triggered using the UI +# or API. +on: + workflow_dispatch: + # Inputs the workflow accepts. + inputs: + name: + # Friendly description to be shown in the UI instead of 'name' + description: 'Person to greet' + # Default value if no value is explicitly provided + default: 'World' + # Input has to be provided for the workflow to run + required: true + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "greet" + greet: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Runs a single command using the runners shell + - name: Send greeting + run: echo "Hello ${{ github.event.inputs.name }}" From db27069b7234ec27ddffb88192e4ee3ac5472b78 Mon Sep 17 00:00:00 2001 From: conflictwar <78981120+conflictwar@users.noreply.github.com> Date: Wed, 2 Jun 2021 02:24:45 -0500 Subject: [PATCH 12/12] Create stale.yml --- .github/workflows/stale.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/workflows/stale.yml diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml new file mode 100644 index 0000000000..30c3dd9bc9 --- /dev/null +++ b/.github/workflows/stale.yml @@ -0,0 +1,22 @@ +name: Mark stale issues and pull requests + +on: + schedule: + - cron: "30 1 * * *" + +jobs: + stale: + + runs-on: ubuntu-latest + permissions: + issues: write + pull-requests: write + + steps: + - uses: actions/stale@v3 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + stale-issue-message: 'Stale issue message' + stale-pr-message: 'Stale pull request message' + stale-issue-label: 'no-issue-activity' + stale-pr-label: 'no-pr-activity'