generated from codekatabattle-polimi/kata-template-golang
-
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.
- Loading branch information
0 parents
commit 297b7f8
Showing
5 changed files
with
105 additions
and
0 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
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 }}\"}" |
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,2 @@ | ||
.idea/ | ||
*.exe |
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,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). |
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,3 @@ | ||
module github.com/codekatabattle-polimi/golang-kata | ||
|
||
go 1.21 |
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,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) | ||
} | ||
} |