Skip to content
This repository has been archived by the owner on Aug 6, 2023. It is now read-only.

Commit

Permalink
Provide CI for developer environments(#2)
Browse files Browse the repository at this point in the history
* Provide devenv CI

* Fix a typo

* Fix quotation

* Fix inverted condition around cache handling

* Fix inverted condition around cache handling more

* Need to wrapt with nix-shell

* Log with tee

* Fix both of quotation and actionlint issue

* Extract fmt task from default task

* Revert "Bump itself"

This reverts commit b7ada01.

* Add test for basic task
  • Loading branch information
kachick committed Jun 19, 2023
1 parent b7ada01 commit cead825
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 5 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/ci-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: CI - Development Environment
on:
push:
branches: [main]
paths:
- '.github/workflows/ci-dev.yml'
- '*.nix'
- 'Taskfile.yml'
pull_request:
paths:
- '.github/workflows/ci-dev.yml'
- '*.nix'
- 'Taskfile.yml'
schedule:
# About JST 8:00
- cron: '0 17 * * *'
workflow_dispatch:

jobs:
get-version:
runs-on: ubuntu-latest
timeout-minutes: 10
outputs:
current: ${{ steps.current.outputs.current }}
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
cache-dependency-path: 'go.sum'
- run: go install .
- id: current
run: |
current="$(nix-headbump -current)"
echo "current=${current}" | tee -a "$GITHUB_OUTPUT"
tasks:
runs-on: ubuntu-latest
timeout-minutes: 30
needs: [get-version]
steps:
- uses: actions/checkout@v3
- name: 'Cache Nix store'
uses: actions/cache@v3
id: nix-cache
with:
path: /tmp/nixcache
key: ${{ runner.os }}-nix_${{ needs.get-version.outputs.current }}
- uses: cachix/install-nix-action@v21
with:
nix_path: nixpkgs=https://github.com/NixOS/nixpkgs/archive/${{ needs.get-version.outputs.current }}.tar.gz
# https://github.com/cachix/install-nix-action/issues/56#issuecomment-1240991760
- name: 'Import Nix store cache'
if: ${{ steps.nix-cache.outputs.cache-hit == 'true' }}
run: 'nix-store --import < /tmp/nixcache'
- run: nix-build
if: ${{ steps.nix-cache.outputs.cache-hit != 'true' }}
- name: Log current versions
run: nix-shell --run 'task versions'
- name: 'Export Nix store cache'
if: ${{ steps.nix-cache.outputs.cache-hit != 'true' }}
run: |
readarray -t paths < <(find /nix/store -maxdepth 1 -name '*-*')
nix-store --export "${paths[@]}" > /tmp/nixcache
- name: Run main task
run: nix-shell --run 'task'
9 changes: 7 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@

> task
task: [build] go build -ldflags "-X main.revision=$(git rev-parse --short HEAD)"
task: [fmt] dprint fmt
task: [test] go test
task: [lint] dprint check
task: [lint] go vet
task: [fmt] go fmt
task: [lint] actionlint
PASS
ok nix-headbump 0.313s

> task fmt
task: [fmt] dprint fmt
task: [fmt] go fmt

> ./nix-headbump --version
0.1.0(ceaa32d)
Expand Down
12 changes: 11 additions & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ version: '3'
tasks:
default:
deps:
- task: fmt
- task: lint
- task: test
- task: build
install:
cmds:
- go install -ldflags "-X main.revision=$(git rev-parse --short HEAD)"
build:
cmds:
- go build -ldflags "-X main.revision=$(git rev-parse --short HEAD)"
test:
cmds:
- go test
fmt:
cmds:
- dprint fmt
Expand All @@ -24,3 +27,10 @@ tasks:
- dprint check
- go vet
- actionlint
versions:
cmds:
- nix --version
- task --version
- go version
- dprint --version
- actionlint --version
2 changes: 1 addition & 1 deletion default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs ? import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/d50f95c6e2a8f58a9e883d918d1e184a6b512900.tar.gz") { } }:
{ pkgs ? import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/e57b65abbbf7a2d5786acc86fdf56cde060ed026.tar.gz") { } }:

pkgs.mkShell {
buildInputs = [
Expand Down
2 changes: 1 addition & 1 deletion nix-headbump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ func TestGetCurrentVersion(t *testing.T) {
if err != nil {
t.Fatalf("Getting the version has been failed: %s", err.Error())
}
want := "d50f95c6e2a8f58a9e883d918d1e184a6b512900"
want := "e57b65abbbf7a2d5786acc86fdf56cde060ed026"

if got != want {
t.Errorf("got %q, wanted %q", got, want)
Expand Down

0 comments on commit cead825

Please sign in to comment.