-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Publish port service experimental action
- Loading branch information
Showing
3 changed files
with
160 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
name: port-service | ||
author: Gowtham Sai (gwthm.in@gmail.com) | ||
description: Reports service to getport | ||
inputs: | ||
clientId: | ||
required: true | ||
description: 'Client ID' | ||
clientSecret: | ||
required: true | ||
description: 'Client secret' | ||
testCoverage: | ||
required: false | ||
descripition: 'Service test coverage' | ||
sonarStatus: | ||
required: false | ||
description: 'Service sonar status' | ||
runs: | ||
using: 'composite' | ||
steps: | ||
- name: "Extract packages" | ||
id: extract-packages | ||
shell: bash | ||
run: | | ||
ruby ${{ github.action_path }}/packages.rb | ||
cat packages.txt >> "$GITHUB_OUTPUT" | ||
- name: "Extract packages identifiers" | ||
id: extract-packages-identifiers | ||
shell: bash | ||
run: | | ||
echo "identifiers=$(echo '${{steps.extract-packages.outputs.packages}}' | jq --compact-output -r '[.[] | .identifier]')" >> "$GITHUB_OUTPUT" | ||
# Extract packages from package manager version file based on the language. | ||
- name: "Readme content" | ||
id: readme | ||
shell: bash | ||
run: | | ||
echo "readme=$(awk '{printf("%s\n", $0)}' README.md | tr '\n' '|' | sed 's/|/\\n/g')" >> "$GITHUB_OUTPUT" | ||
- name: "Report service to port" | ||
uses: port-labs/port-github-action@v1 | ||
with: | ||
clientId: ${{ inputs.clientId }} | ||
clientSecret: ${{ inputs.clientSecret }} | ||
identifier: ${{ github.event.repository.name }} | ||
title: ${{ github.event.repository.name }} | ||
blueprint: service | ||
properties: | | ||
{ | ||
"name": "${{ github.event.repository.name }}", | ||
"url": "${{ github.server_url }}/${{ github.repository }}", | ||
"README": "${{ steps.readme.outputs.readme }}", | ||
"about": "${{ github.event.repository.description }}", | ||
"test_coverage": "${{ inputs.testCoverage }}", | ||
"sonar_status": "${{ inputs.sonarStatus }}" | ||
} | ||
relations: | | ||
{ | ||
"package": ${{ steps.extract-packages-identifiers.outputs.identifiers }} | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'json' | ||
|
||
$packages = [] | ||
|
||
# Extract Python package information from requirements.txt | ||
def extract_python_packages | ||
return unless File.exist?('requirements.txt') | ||
|
||
$packages += File.readlines('requirements.txt').map do |line| | ||
name, version = line.strip.split('==') | ||
{"properties" => {"name" => name, "version" => version, "language" => "Python"}, "blueprint" => "package", "identifier" => "#{name}@#{version}", "title" => "#{name}@#{version}"} | ||
end | ||
end | ||
|
||
# Extract Node.js package information from package.json | ||
def extract_node_packages | ||
return unless File.exist?('package.json') | ||
|
||
package_json = JSON.parse(File.read('package.json')) | ||
$packages += (package_json['dependencies'] || {}).merge(package_json['devDependencies'] || {}).map do |key, value| | ||
{"properties" => {"name" => key, "version" => value, "language" => "Node"}, "blueprint" => "package", "identifier" => "#{key.gsub(/[\/.^]/, '-')}@#{value}", "title" => "#{key}@#{value}"} | ||
end | ||
end | ||
|
||
# Extract Go package information from go.mod | ||
def extract_go_packages | ||
return unless File.exist?('go.mod') | ||
|
||
in_require_block = false | ||
|
||
# Regex pattern to match and capture host | ||
host_pattern = /^(https?:\/\/)?([^\/]+)\/(.+)$/ | ||
|
||
File.readlines('go.mod').each do |line| | ||
if line =~ /^require\s+\(/ | ||
in_require_block = true | ||
elsif line =~ /^\)\s*$/ | ||
in_require_block = false | ||
elsif in_require_block && line =~ /^\s*([^\s]+)\s+([^\s]+)\s*$/ | ||
name_with_host, version = $1, $2.gsub(/\+incompatible$/, '') | ||
|
||
# Use regex to match and capture host | ||
match = name_with_host.match(host_pattern) | ||
|
||
if match | ||
host, name = match.captures[1..2] # Extract the second and third captured groups | ||
else | ||
host = nil | ||
name = name_with_host | ||
end | ||
|
||
# $packages << {"properties" => {"name" => name, "version" => version, "language" => "Go"}, "blueprint" => "package", "identifier" => "#{name_with_host}@#{version}", "title" => "#{name}@#{version}"} | ||
# We should consider identifier as package after trimming host. | ||
$packages << {"properties" => {"name" => name, "version" => version, "language" => "Go"}, "blueprint" => "package", "identifier" => "#{name}@#{version}", "title" => "#{name}@#{version}"} | ||
end | ||
end | ||
end | ||
|
||
# Extract Ruby package information from Gemfile.lock | ||
def extract_ruby_packages | ||
return unless File.exist?('Gemfile.lock') | ||
|
||
in_specification_block = false | ||
|
||
File.readlines('Gemfile.lock').each do |line| | ||
line.strip! | ||
|
||
if line.start_with?('GEM') | ||
in_specification_block = true | ||
elsif in_specification_block && line =~ /^(\S+)\s+\(([^,]+),.*\)$/ | ||
name, version = $1, $2 | ||
$packages << {"properties" => {"name" => name, "version" => version, "language" => "Ruby"}, "blueprint" => "package", "identifier" => "#{name}@#{version}", "title" => "#{name}@#{version}"} | ||
elsif line.empty? && in_specification_block | ||
in_specification_block = false | ||
end | ||
end | ||
end | ||
|
||
# Helper method to write packages to the output file | ||
def write_to_file(packages=$packages) | ||
File.open('packages.txt', 'a') do |file| | ||
file.puts 'packages=' + JSON.generate(packages) | ||
end | ||
end | ||
|
||
# Main script | ||
extract_python_packages | ||
extract_node_packages | ||
extract_go_packages | ||
extract_ruby_packages | ||
write_to_file | ||
|