feat(base): configure direnv to autoapply for files under /workspaces #182
Workflow file for this run
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
name: Build | |
on: | |
push: | |
branches: | |
- main | |
tags: | |
- "v*.*.*" | |
pull_request: | |
branches: | |
- main | |
schedule: | |
- cron: 0 1 * * 1 | |
workflow_dispatch: | |
permissions: | |
contents: write | |
packages: write | |
pull-requests: read | |
jobs: | |
commitlint: | |
runs-on: ubuntu-latest | |
env: | |
GITHUB_TOKEN: '{{ "${{ secrets.GITHUB_TOKEN }}" }}' | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # fetch-depth is required | |
- uses: wagoid/commitlint-github-action@v5 | |
pre-commit: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # fetch-depth is required | |
- name: Set up Go without go.mod | |
uses: actions/setup-go@v5 | |
if: ${{ hashFiles('go.mod') == '' }} | |
with: | |
check-latest: true | |
- name: Set up Go with go.mod | |
uses: actions/setup-go@v5 | |
if: ${{ hashFiles('go.mod') != '' }} | |
with: | |
go-version-file: go.mod | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: 3.x | |
- name: Setup JS | |
uses: actions/setup-node@v4 | |
with: | |
node-version: lts/* | |
- name: Install dependencies | |
run: | | |
go install ./... || true | |
npm ci || true | |
- uses: pre-commit/[email protected] | |
base: | |
runs-on: ubuntu-latest | |
needs: | |
- commitlint | |
- pre-commit | |
outputs: | |
docker_registry: ${{ steps.tags.outputs.docker_registry }} | |
matrix: ${{ steps.tags.outputs.matrix }} | |
tag: ${{ steps.tags.outputs.tag }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup JS | |
uses: actions/setup-node@v4 | |
with: | |
node-version: lts/* | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Generate Docker tag | |
id: tags | |
run: | | |
echo "docker_registry=ghcr.io/${GITHUB_REPOSITORY,,}" >> "$GITHUB_OUTPUT" | |
echo "matrix={\"img\": $(jq -ncR '[inputs]' <<< $(ls -d images/* | grep -v '/base'))}" >> "$GITHUB_OUTPUT" | |
echo "tag=$(date --iso-8601)" >> "$GITHUB_OUTPUT" | |
- name: Install Dev Container CLI | |
run: | | |
npm install -g @devcontainers/cli | |
devcontainer --version | |
- name: Build Dev Container | |
run: | | |
docker pull ${{ steps.tags.outputs.docker_registry }}/base:latest || true | |
devcontainer build \ | |
--platform=linux/amd64 \ | |
--image-name=${{ steps.tags.outputs.docker_registry }}/base:${{ steps.tags.outputs.tag }} \ | |
--image-name=${{ steps.tags.outputs.docker_registry }}/base:latest \ | |
--workspace-folder=images/base | |
if [ ${{ github.ref == 'refs/heads/main' }} = "true" ]; then | |
echo "Pushing images" | |
docker push ${{ steps.tags.outputs.docker_registry }}/base:${{ steps.tags.outputs.tag }} | |
docker push ${{ steps.tags.outputs.docker_registry }}/base:latest | |
else | |
echo "Saving base image" | |
docker save ${{ steps.tags.outputs.docker_registry }}/base:latest -o base.tar.gz | |
fi | |
- name: Archive Docker image | |
uses: actions/upload-artifact@v4 | |
if: ${{ github.ref != 'refs/heads/main' }} | |
with: | |
name: docker-image | |
path: base.tar.gz | |
if-no-files-found: error | |
retention-days: 1 | |
compression-level: 0 | |
overwrite: true | |
images: | |
runs-on: ubuntu-latest | |
needs: | |
- base | |
strategy: | |
matrix: ${{ fromJSON(needs.base.outputs.matrix) }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup JS | |
uses: actions/setup-node@v4 | |
with: | |
node-version: lts/* | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Generate Docker tag | |
id: tags | |
run: | | |
echo "name=$(echo ${{ matrix.img }} | sed 's/images\///' )" >> "$GITHUB_OUTPUT" | |
- name: Install Dev Container CLI | |
run: | | |
npm install -g @devcontainers/cli | |
devcontainer --version | |
- name: Import Docker image | |
uses: actions/download-artifact@v4 | |
if: ${{ github.ref != 'refs/heads/main' }} | |
with: | |
name: docker-image | |
- name: Build Dev Container | |
run: | | |
if [ ${{ github.ref == 'refs/heads/main' }} = "true" ]; then | |
echo "Pulling image from registry" | |
docker pull ${{ needs.base.outputs.docker_registry }}/base | |
else | |
echo "Importing image from cache" | |
docker import base.tar.gz ${{ needs.base.outputs.docker_registry }}/base | |
fi | |
docker pull ${{ needs.base.outputs.docker_registry }}/${{ steps.tags.outputs.name }}:latest || true | |
devcontainer build \ | |
--platform=linux/amd64 \ | |
--image-name=${{ needs.base.outputs.docker_registry }}/${{ steps.tags.outputs.name }}:${{ needs.base.outputs.tag }} \ | |
--image-name=${{ needs.base.outputs.docker_registry }}/${{ steps.tags.outputs.name }}:latest \ | |
--workspace-folder=${{ matrix.img }} | |
if [ ${{ github.ref == 'refs/heads/main' }} = "true" ]; then | |
echo "Pushing images" | |
docker push ${{ needs.base.outputs.docker_registry }}/${{ steps.tags.outputs.name }}:${{ needs.base.outputs.tag }} | |
docker push ${{ needs.base.outputs.docker_registry }}/${{ steps.tags.outputs.name }}:latest | |
fi |