Skip to content

Generate image

Generate image #21

name: Generate image
on:
workflow_dispatch:
inputs:
target:
description: 'Image target name'
required: true
type: string
log-level:
description: 'Log level'
required: true
default: 'info'
type: choice
options:
- info
- warning
- debug
jobs:
generate:
name: Generate image
runs-on: ubuntu-latest
permissions:
contents: write
discussions: write
outputs:
image_tag: ${{ steps.set-output.outputs.IMAGE_TAG }}
env:
GITHUB_TOKEN: ${{ secrets.ACTION_ACCESS_TOKEN }}
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y python3-venv python3-pip python-apt-dev python3-apt
- name: Install image generator
run: |
python -m venv venv
source venv/bin/activate
pip install git+https://github.com/EffectiveRange/raspbian-image-generator.git@latest
- name: Generate image
run: |
sudo -E venv/bin/python3 venv/bin/raspbian-image-generator.py \
config/target-config.json ${{ github.event.inputs.target }} \
--log-level ${{ github.event.inputs.log-level }} \
- name: Set output
id: set-output
run: |
VERSION=$(ls -1 image/${{ github.event.inputs.target }})
echo "IMAGE_TAG=${{ github.event.inputs.target }}-$VERSION" >> $GITHUB_OUTPUT
- name: Publish image
uses: actions/upload-artifact@v4
with:
name: ${{ github.event.inputs.target }}
path: image/**/*
if-no-files-found: error
release:
name: Create Release
runs-on: ubuntu-latest
permissions:
contents: write
discussions: write
needs: [ generate ]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: ${{ github.event.inputs.target }}
path: ${{ github.workspace }}/image
- name: Display structure of downloaded files
run: ls -R ${{ github.workspace }}/image
- name: Create tag
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
TAG=${{ needs.generate.outputs.image_tag }}
git tag -fa $TAG -m "Generated image $TAG"
git push origin :refs/tags/$TAG
git push origin --tags
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Release tag
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ needs.generate.outputs.image_tag }}
files: |
${{ github.workspace }}/image/**/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}