From 710dc5b41a141e916f337416c8ecf951aa3cb407 Mon Sep 17 00:00:00 2001 From: ifurther <55025025+ifurther@users.noreply.github.com> Date: Sun, 14 Jan 2024 17:34:10 +0800 Subject: [PATCH] update ci file --- .github/workflows/release.yml | 18 +++--------------- Makefile | 19 +++++++++++++++++++ nixos.pkr.hcl | 1 + 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 48d6c5b..fde4336 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -32,13 +32,9 @@ jobs: qemu libvirt-daemon-system - name: Create Vagrant Cloud Box - run: | - curl \ - --request POST \ - --header "Content-Type: application/json" \ - --header "Authorization: Bearer ${{ secrets.ATLAS_TOKEN }}" \ - https://app.vagrantup.com/api/v2/boxes \ - --data '{ "box": { "username": "nixbox", "name": "nixos" } }' + env: + ATLAS_TOKEN: ${{ secrets.ATLAS_TOKEN }} + run: make vagrantcloud-create - name: Setup `packer` uses: hashicorp/setup-packer@main @@ -50,11 +46,3 @@ jobs: env: ATLAS_TOKEN: ${{ secrets.ATLAS_TOKEN }} run: make VERSION=${GITHUB_REF#refs/heads/nixos-} BUILDER=${{ matrix.BUILDER }} packer-build - - - name: Release the Vagrant Cloud box - run: | - curl \ - --request PUT \ - --header "Authorization: Bearer ${{ secrets.ATLAS_TOKEN }}" \ - "https://app.vagrantup.com/api/v2/box/nixbox/nixos/version/${GITHUB_REF#refs/heads/nixos-}/release" - diff --git a/Makefile b/Makefile index a3a081e..42b06e1 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,9 @@ BUILDER ?= virtualbox-iso.virtualbox VERSION ?= 23.05 ARCH ?= x86_64 REPO ?= nixbox/nixos +CI_VERSION ?= ${GITHUB_REF#refs/heads/nixos-} +REPO_NAME = $(word 1, $(subst /, ,${REPO})) +BOX_NAME = $(word 2, $(subst /, ,${REPO})) BUILD_PROVIDER = $(word 2, $(subst ., ,${BUILDER})) all: help @@ -50,11 +53,27 @@ vagrant-push: vagrant-plugin ## Push builded vagrant box --no-private \ --short-description "NixOS ${VERSION}" \ ${REPO}-${VERSION} ${VERSION} ${BUILD_PROVIDER} nixos-${VERSION}-${BUILDER}-${ARCH}.box + +vagrantcloud-create: ## Create Vagrant Cloud box + @curl \ + --request POST \ + --header "Content-Type: application/json" \ + --header "Authorization: Bearer ${ATLAS_TOKEN}" \ + https://app.vagrantup.com/api/v2/boxes \ + --data '{ "box": { "username": "'"${REPO_NAME}"'", "name": "'"${BOX_NAME}"'", "is_private": false } }' + +vagrantcloud-release: ## Release Vagrant CLoude box + @curl \ + --request PUT \ + --header "Authorization: Bearer ${ATLAS_TOKEN}" \ + "https://app.vagrantup.com/api/v2/box/${REPO}/version/${CI_VERSION}/release" + packer-build: nixos.pkr.hcl version ##Use packer push to vagrant-cloud packer init $< packer build \ -var arch=${ARCH} \ -var builder="${BUILDER}" \ + -var cloud_repo=${REPO} \ -var version=${VERSION} \ -var iso_checksum="$(shell curl -sL https://channels.nixos.org/nixos-${VERSION}/latest-nixos-minimal-${ARCH}-linux.iso.sha256 | grep -Eo '^[0-9a-z]{64}')" \ --only=${BUILDER} \ diff --git a/nixos.pkr.hcl b/nixos.pkr.hcl index cdcb365..5f0bd67 100644 --- a/nixos.pkr.hcl +++ b/nixos.pkr.hcl @@ -195,6 +195,7 @@ build { access_token = "${var.cloud_token}" box_tag = "${var.cloud_repo}" version = "${var.version}" + architecture = "${lookup(var.vagrant_cloud_arch, var.arch, "amd64")}" } } }