Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
giovanni-orciuolo authored Feb 14, 2024
0 parents commit 297b7f8
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 0 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Build Go executable and submit it to API

on:
push:
branches: [ "main" ]

jobs:
build:
runs-on: ubuntu-22.04
env:
GITHUB_PAT: ${{ secrets.GITHUB_PAT }}
outputs:
artifact-url: ${{ steps.artifact-upload.outputs.artifact-url }}
steps:
- uses: actions/checkout@v3
if: ${{ env.GITHUB_PAT != '' }}

- name: Set up Go
uses: actions/setup-go@v4
if: ${{ env.GITHUB_PAT != '' }}
with:
go-version: '1.20'

- name: Build
if: ${{ env.GITHUB_PAT != '' }}
run: go build ./...

- name: Upload build artifact
id: artifact-upload
uses: actions/[email protected]
if: ${{ env.GITHUB_PAT != '' }}
with:
path: '.'
if-no-files-found: error
retention-days: 1
overwrite: true

- name: Dump artifact url
if: ${{ env.GITHUB_PAT != '' }}
env:
ARTIFACT_URL: ${{ steps.artifact-upload.outputs.artifact-url }}
run: echo "Artifact URL => $ARTIFACT_URL"

upload:
needs: build
env:
GITHUB_PAT: ${{ secrets.GITHUB_PAT }}
runs-on: ubuntu-22.04
steps:
- name: Submit build artifact to CKB
uses: dkershner6/post-api-call-action@v2
if: ${{ env.GITHUB_PAT != '' }}
with:
url: ${{ vars.API_BASE_URL }}/battles/${{ vars.BATTLE_ID }}/submit
data: "{\"artifactUrl\": \"${{ needs.build.outputs.artifact-url }}\"}"
headers: "{\"Authorization\": \"Bearer ${{ secrets.GITHUB_PAT }}\"}"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea/
*.exe
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# kata-template-golang

This is a basic template for katas to be made in Golang.

Students can already fork this repository, but they will be able to submit their commits only once the battle has started.

## Submitting entries for the battle

The GitHub Action provided in this repository will automatically submit the compiled output for execution and test running in an automated way, and does not need modifications.

Since GitHub authorization is required to identify the committer and assign score to battle participant, students need to populate repository secrets with the value GITHUB_PAT, which is a Personal Access Token generated by them for their own GitHub account. The GitHub action to compile and submit artifacts will not run without a value for GITHUB_PAT. The API endpoint will error out for invalid or expired PATs.

Learn more about repository secrets [here](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions).

Learn more about Personal Access Tokens (PATs) [here](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens).
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/codekatabattle-polimi/golang-kata

go 1.21
26 changes: 26 additions & 0 deletions kata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package main

import (
"fmt"
"log"
"os"
)

func kataSolution(input string) string {
// Write your code here
return input
}

func main() {
// Read the input from input.txt file
file, err := os.ReadFile("input.txt")
if err != nil {
log.Fatal(err)
}

// Print the solution to standard output
_, err = fmt.Print(kataSolution(string(file)))
if err != nil {
log.Fatal(err)
}
}

0 comments on commit 297b7f8

Please sign in to comment.