Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 52 additions & 30 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,70 @@ on:
pull_request:
push:
branches: [main]
workflow_call:
inputs:
ref:
description: Revision to verify
type: string
required: true
outputs:
sha:
description: Exact commit verified by all jobs
value: ${{ jobs.lint.outputs.sha }}

permissions:
contents: read

concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
group: ci-${{ github.workflow }}-${{ inputs.ref || github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
lint:
name: lint
runs-on: ubuntu-latest
outputs:
sha: ${{ steps.revision.outputs.sha }}
steps:
- uses: actions/checkout@v7
with:
ref: ${{ inputs.ref || github.sha }}
- id: revision
run: echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
- uses: jdx/mise-action@v4
with:
cache: true
- uses: actions/cache@v6
with:
path: |
~/go/pkg/mod
~/.cache/go-build
~/.cache/golangci-lint
key: ${{ runner.os }}-lint-${{ hashFiles('mise.toml', 'go.sum') }}
restore-keys: ${{ runner.os }}-lint-
- run: task check:versions deps lint
- run: task release:check

test:
name: test (${{ matrix.os }})
needs: lint
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install toolchain from mise.toml
uses: jdx/mise-action@v4

- name: Build
run: go build ./...

- name: Vet
run: go vet ./...

- name: Test
run: go test -count=1 ./...

lint:
name: lint
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install toolchain from mise.toml
uses: jdx/mise-action@v4

- name: golangci-lint
run: golangci-lint run ./...
- uses: actions/checkout@v7
with:
ref: ${{ needs.lint.outputs.sha }}
- uses: jdx/mise-action@v4
with:
cache: true
- uses: actions/cache@v6
with:
path: |
~/go/pkg/mod
~/.cache/go-build
key: ${{ runner.os }}-go-${{ hashFiles('mise.toml', 'go.sum') }}
restore-keys: ${{ runner.os }}-go-
- run: task check:versions build vet test test:scripts
62 changes: 19 additions & 43 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,71 +6,46 @@ on:
workflow_dispatch:

permissions:
contents: write
actions: write
contents: read

concurrency:
group: nightly
cancel-in-progress: false

jobs:
nightly:
permissions:
contents: write
actions: write
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v7
with:
fetch-depth: 0
ref: main

- name: Check for new commits since the last nightly
id: check
run: |
LATEST_NIGHTLY=$(git tag -l 'v*-nightly.*' --sort=-v:refname | head -1)
if [ -z "$LATEST_NIGHTLY" ]; then
echo "No previous nightly tag, proceeding"
echo "has_changes=true" >> "$GITHUB_OUTPUT"
elif [ "$(git rev-list "${LATEST_NIGHTLY}..HEAD" --count)" -gt 0 ]; then
echo "New commits since $LATEST_NIGHTLY"
echo "has_changes=true" >> "$GITHUB_OUTPUT"
else
echo "No new commits since $LATEST_NIGHTLY, skipping"
echo "has_changes=false" >> "$GITHUB_OUTPUT"
fi

- name: Compute next patch version
if: steps.check.outputs.has_changes == 'true'
id: version
run: |
# The manifest holds the last released version. A nightly must sort
# above it under semver, so tag the next patch: 0.6.0 -> v0.6.1-nightly.<date>.
RELEASED=$(jq -r '.["."]' .release-please-manifest.json)
IFS=. read -r MAJOR MINOR PATCH <<< "$RELEASED"
echo "next=${MAJOR}.${MINOR}.$((PATCH + 1))" >> "$GITHUB_OUTPUT"

- name: Create nightly tag
if: steps.check.outputs.has_changes == 'true'
- name: Create or retry nightly
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
DATE=$(date -u +%Y%m%d)
TAG="v${{ steps.version.outputs.next }}-nightly.${DATE}"
echo "Creating tag: $TAG"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "$TAG" -m "Nightly build $DATE"
git push origin "$TAG"
gh workflow run prerelease.yml --ref "$TAG"
run: bash scripts/nightly.sh

cleanup:
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Delete nightly releases older than 7 days
uses: actions/github-script@v7
uses: actions/github-script@v9
with:
script: |
const cutoff = new Date();
cutoff.setDate(cutoff.getDate() - 7);
const releases = await github.rest.repos.listReleases({
const releases = await github.paginate(github.rest.repos.listReleases, {
owner: context.repo.owner, repo: context.repo.repo, per_page: 100,
});
for (const release of releases.data) {
if (!release.tag_name.includes('-nightly.')) continue;
for (const release of releases) {
if (!/^v\d+\.\d+\.\d+-nightly\.\d{8}$/.test(release.tag_name)) continue;
if (new Date(release.created_at) >= cutoff) continue;
console.log(`Deleting old nightly release: ${release.tag_name}`);
await github.rest.repos.deleteRelease({
Expand All @@ -81,6 +56,7 @@ jobs:
owner: context.repo.owner, repo: context.repo.repo, ref: `tags/${release.tag_name}`,
});
} catch (e) {
if (e.status !== 404) throw e;
console.log(`Tag ${release.tag_name} already deleted`);
}
}
50 changes: 37 additions & 13 deletions .github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,51 @@ on:
workflow_dispatch:

permissions:
contents: write
contents: read

concurrency:
group: prerelease-${{ github.ref }}
cancel-in-progress: false

jobs:
validate:
runs-on: ubuntu-latest
outputs:
sha: ${{ steps.revision.outputs.sha }}
steps:
- uses: actions/checkout@v7
- name: Require a supported prerelease tag
run: bash scripts/validate-prerelease.sh "$GITHUB_REF"
- id: revision
run: echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"

verify:
needs: validate
uses: ./.github/workflows/ci.yml
with:
ref: ${{ needs.validate.outputs.sha }}

goreleaser:
needs: verify
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/checkout@v7
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v5
ref: ${{ needs.verify.outputs.sha }}
- uses: jdx/mise-action@v4
with:
go-version-file: go.mod

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
cache: true
- uses: actions/cache@v6
with:
distribution: goreleaser
version: "~> v2"
args: release --clean
path: |
~/go/pkg/mod
~/.cache/go-build
key: ${{ runner.os }}-go-${{ hashFiles('mise.toml', 'go.sum') }}
restore-keys: ${{ runner.os }}-go-
- run: task release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GORELEASER_CURRENT_TAG: ${{ github.ref_name }}
49 changes: 31 additions & 18 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,57 @@ on:
branches: [main]

permissions:
contents: write
pull-requests: write
contents: read

concurrency:
group: release-main
cancel-in-progress: false

jobs:
release-please:
permissions:
contents: write
pull-requests: write
runs-on: ubuntu-latest
outputs:
release_created: ${{ steps.release.outputs.release_created }}
tag_name: ${{ steps.release.outputs.tag_name }}
steps:
- uses: googleapis/release-please-action@v4
- uses: googleapis/release-please-action@v5
id: release
with:
token: ${{ secrets.GITHUB_TOKEN }}
config-file: release-please-config.json
manifest-file: .release-please-manifest.json

goreleaser:
verify:
needs: release-please
if: ${{ needs.release-please.outputs.release_created == 'true' }}
if: needs.release-please.outputs.release_created == 'true'
uses: ./.github/workflows/ci.yml
with:
ref: ${{ needs.release-please.outputs.tag_name }}

goreleaser:
needs: [release-please, verify]
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/checkout@v7
with:
fetch-depth: 0
ref: ${{ needs.release-please.outputs.tag_name }}

- name: Set up Go
uses: actions/setup-go@v5
ref: ${{ needs.verify.outputs.sha }}
- uses: jdx/mise-action@v4
with:
go-version-file: go.mod

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
cache: true
- uses: actions/cache@v6
with:
distribution: goreleaser
version: "~> v2"
args: release --clean
path: |
~/go/pkg/mod
~/.cache/go-build
key: ${{ runner.os }}-go-${{ hashFiles('mise.toml', 'go.sum') }}
restore-keys: ${{ runner.os }}-go-
- run: task release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GORELEASER_CURRENT_TAG: ${{ needs.release-please.outputs.tag_name }}
4 changes: 0 additions & 4 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ version: 2

project_name: envctl

before:
hooks:
- go mod tidy

builds:
- id: envctl
main: ./cmd/envctl
Expand Down
Loading