Skip to content

Commit

Permalink
feat: flow-01: attempt 01
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihai Alexandrescu committed May 20, 2024
1 parent 9b0bc3f commit e404c98
Show file tree
Hide file tree
Showing 10 changed files with 331 additions and 0 deletions.
70 changes: 70 additions & 0 deletions .github/workflows/flow-01.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: flow-01
run-name: ${{ github.actor }} is learning GitHub Actions

on: [push, workflow_dispatch]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
job-01:
runs-on: ubuntu-latest # github.com/actions/runner-images
container:
image: ubuntu:latest
options: --cpus 1
timeout-minutes: 5
defaults:
run:
shell: bash
steps:
- name: Install git # do it before actions/checkout because of https://github.com/actions/runner/issues/763#issuecomment-1435735340
run: apt update && apt install -y git && git version

- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-go@v5
with:
go-version-file: 'gomodule01/go.mod'
cache: false
cache-dependency-path: "**/go.sum"

- name: Expected failure
if: false
run: exit 5
continue-on-error: true

- name: Display /etc/lsb-release
run: cat /etc/lsb-release

- name: Fix x509 issue
run: apt update && apt install -y --no-install-recommends ca-certificates

- name: Check go mod tidy
shell: bash
run: |
set -v
pwd && ls -lAh
git config --global --add safe.directory "$GITHUB_WORKSPACE"
cd gomodule01
go mod tidy
cd ..
pwd
git version
git diff --name-status --exit-code
- name: Run gomodule01
run: cd gomodule01 ; go run .

- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.58
working-directory: gomodule01
skip-cache: true
skip-save-cache: true
args: --timeout=2m


60 changes: 60 additions & 0 deletions .github/workflows/flow-02.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: flow-02
run-name: ${{ github.actor }} is learning GitHub Actions again

on:
workflow_run:
workflows: ["flow-01"]
types: ["requested"]


concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

defaults:
run:
shell: bash

jobs:
call-reusable-01-from-local-repo:
uses: ./.github/workflows/reusable-01.yaml

job2:
runs-on: ubuntu-latest
needs: [call-reusable-01-from-local-repo]
steps:
- name: Display output from another workflow file
run: echo ${{ needs.call-reusable-01-from-local-repo.outputs.gomodule01_output }} | base64 -d

call-reusable-02-for-build:
uses: ./.github/workflows/reusable-02-build.yaml
with:
binary_base_name: cmd01

download-run-cleanup-binary:
runs-on: ubuntu-latest
container:
image: ubuntu:latest
options: --cpus 1
timeout-minutes: 3
needs: [call-reusable-02-for-build]
env:
binary_name: ${{ needs.call-reusable-02-for-build.outputs.binary_name }}
steps:
- run: test -n ${{ env.binary_name }}

- uses: actions/download-artifact@v4
with:
name: ${{ env.binary_name }}

- name: Run ${{ env.binary_name }}
run: chmod u+x ${{ env.binary_name }} && ./${{ env.binary_name }}

- name: Remove artifact from store
uses: geekyeggo/delete-artifact@v5
with:
name: ${{ env.binary_name }}




49 changes: 49 additions & 0 deletions .github/workflows/reusable-01.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: reusable-01
run-name: ${{ github.actor }} is learning GitHub Actions _reusable-01

on:
workflow_call:
outputs:
gomodule01_output:
description: "The output of the command under gomodule01"
value: ${{ jobs.job-01.outputs.output1 }}

jobs:
job-01:
runs-on: ubuntu-latest
container:
image: ubuntu:latest
options: --cpus 1
timeout-minutes: 3
defaults:
run:
shell: bash
outputs:
output1: ${{ steps.run-gomodule01.outputs.hello}}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: 'gomodule01/go.mod'
cache: false
cache-dependency-path: "**/go.sum"

- name: Expected failure
if: false
run: exit 6
continue-on-error: true

- name: Display /etc/lsb-release
run: cat /etc/lsb-release

- name: Fix x509 issue
run: apt-get update && apt-get install -y --no-install-recommends ca-certificates

- name: Run gomodule01
id: run-gomodule01
# base64 is used to hide the multiline output and it will be decoded on the receiver side
run: |
out="$(cd gomodule01 && go run . | base64)"
echo "hello=$out" | tee -a $GITHUB_OUTPUT
- run: pwd
63 changes: 63 additions & 0 deletions .github/workflows/reusable-02-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: reusable-02
run-name: ${{ github.actor }} is learning GitHub Actions _reusable-02

on:
workflow_call:
inputs:
binary_base_name:
description: "The name of the command to be built under gomodule01"
type: string
default: 'cmd01_default'
required: false
outputs:
binary_name:
description: "The actual name of the command that was built under gomodule01"
value: ${{ jobs.build.outputs.file_name }}

jobs:
build:
runs-on: ubuntu-latest
container:
image: ubuntu:latest
options: --cpus 1
timeout-minutes: 3
defaults:
run:
shell: bash
outputs:
file_name: ${{ steps.normalize-name.outputs.file_name }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: 'gomodule01/go.mod'
cache: false
cache-dependency-path: "**/go.sum"

- name: Expected failure
if: false
run: exit 7
continue-on-error: true

- name: Fix x509 issue
run: apt-get update && apt-get install -y --no-install-recommends ca-certificates

- name: Create normalized file name
id: normalize-name
run: |
NormName=$(echo '${{ inputs.binary_base_name }}_${{ github.ref_name }}' | \
sed 's/[\.\/\\]/-/g' | \
tr '[:upper:]' '[:lower:]' | \
head -c 50)
echo "file_name=$NormName" | tee -a $GITHUB_OUTPUT
- name: Build ${{ steps.normalize-name.outputs.file_name }} under gomodule01
id: build-gomodule01
run: go build -C gomodule01/ -o ${{ steps.normalize-name.outputs.file_name }} .

- name: Upload artifact for ${{ steps.normalize-name.outputs.file_name }}
uses: actions/upload-artifact@v4
with:
name: ${{ steps.normalize-name.outputs.file_name }}
path: gomodule01/${{ steps.normalize-name.outputs.file_name }}
retention-days: 1
32 changes: 32 additions & 0 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: '3'

tasks:
default:
deps:
- task: echo_sth
vars: { TEXT: 'before 2' }
silent: true
- task: loop_smth
vars: { CHAR: "B", LIMIT: 2, EXITCODE: 240 }
- task: loop_smth
vars: { CHAR: "C", LIMIT: 6, EXITCODE: 250 }

echo_sth:
cmds:
- echo {{.TEXT}}

loop_smth:
ignore_error: false
vars:
LIMIT: '{{ default 5 .LIMIT }}'
CHAR: '{{ default "A" .CHAR }}'
EXITCODE: '{{ default 0 .EXITCODE }}'
cmds:
- cmd: |
for VAR in {1..{{.LIMIT}}}
do
echo "{{.CHAR}}: $VAR"
sleep 1
done
exit {{.EXITCODE}}
22 changes: 22 additions & 0 deletions gomodule01/.golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
run:
timeout: 1m
tests: true

linters:
enable:
- gofmt
- gofumpt
- gci
- godot
- misspell
- whitespace
- mnd

linters-settings:
gci:
sections:
- standard
- default
- localmodule
skip-generated: true
custom-order: true
8 changes: 8 additions & 0 deletions gomodule01/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module github.com/mihaialexandrescu/learn-githubactions/gomodule01

go 1.22.3

require (
github.com/davecgh/go-spew v1.1.1
sigs.k8s.io/yaml v1.4.0
)
8 changes: 8 additions & 0 deletions gomodule01/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=
16 changes: 16 additions & 0 deletions gomodule01/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package main

import (
"fmt"

"github.com/davecgh/go-spew/spew"
"sigs.k8s.io/yaml"

"github.com/mihaialexandrescu/learn-githubactions/gomodule01/nothing"
)

func main() {
fmt.Println(nothing.Hello)
spew.Dump(nothing.Hello)
_ = yaml.YAMLToJSON
}
3 changes: 3 additions & 0 deletions gomodule01/nothing/var.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package nothing

var Hello string = "Hello, World!"

0 comments on commit e404c98

Please sign in to comment.