Skip to content

Commit

Permalink
ci/fix-github-release-action (#83)
Browse files Browse the repository at this point in the history
Reviewed-on: https://git.montehaselino.de/DHBW/dhbw-abb-typst-template/pulls/83
Co-authored-by: servostar <sven.vogel123@web.de>
Co-committed-by: servostar <sven.vogel123@web.de>
  • Loading branch information
Servostar committed Nov 21, 2024
1 parent 9e3567a commit 36f8ffd
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 76 deletions.
16 changes: 0 additions & 16 deletions .github/workflows/ci.yml

This file was deleted.

60 changes: 47 additions & 13 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
name: release
name: Build'n check on ${{ github.event.head_commit.message }}

on:
push:
tags:
- 'v*.*.*'
branches:
- main

jobs:
release:
build:
name: Check Template and Build example
runs-on: ubuntu-latest
steps:
- name: Check out repository code
Expand All @@ -15,16 +16,49 @@ jobs:
uses: cachix/install-nix-action@v27
with:
nix_path: nixpkgs=channel:nixos-unstable
- name: Run CI
run: nix-shell --run ./run-ci.sh
- name: Stylecheck
run: nix-shell --run "./run-fmt.sh --check src/lib.typ"
- id: build
name: Build
run: |
nix-shell --run ./run-ci.sh
- name: Upload artifact
id: artifact-upload
uses: actions/upload-artifact@v3
with:
name: example-document
path: ${{ github.workspace }}/example.pdf
if-no-files-found: error
retention-days: 1
- name: Output artifact ID
run: echo 'Artifact ID is ${{ steps.artifact-upload.outputs.artifact-id }}'
release:
runs-on: ubuntu-latest
needs: build
if: startsWith(github.ref, 'refs/tags/')
permissions:
contents: write
steps:
- name: Check out repository code
uses: actions/checkout@v3
- name: Setup go
uses: https://github.com/actions/setup-go@v4
uses: actions/setup-go@v4
with:
go-version: '>=1.20.1'
- name: Create release
id: create-release
uses: https://gitea.com/actions/release-action@main
- name: Download Artifcat
id: download
uses: actions/download-artifact@v3
with:
name: example-document
path: ${{ github.workspace }}/Example.pdf
- name: 'Artifact Download Path'
run: echo ${{ steps.download.outputs.download-path }}
- name: Prepare Release
run: echo ${{ github.sha }} > Release.txt
- name: Release ${{ GITHUB_REF_NAME }}
uses: softprops/action-gh-release@v2
with:
files: |-
example.pdf
api_key: '${{secrets.RELEASE_TOKEN}}'
files: |
Example.pdf
Release.txt
LICENSE
48 changes: 1 addition & 47 deletions run-ci.sh
Original file line number Diff line number Diff line change
@@ -1,49 +1,3 @@
#!/bin/bash

function log() {
local timestamp=$(date +"%Y-%m-%d %H:%M:%S")
echo "$1 at $timestamp: $2"
}

function abort() {
log "ERROR" "test case $1 has failed"
exit 1
}

function print-box() {
printf "\\n"
echo ".----------------------------------------------------------------."
printf "| %-62s |\\n" "$1"
echo "'----------------------------------------------------------------'"
}

function enter-section() {
print-box "$1"

log "INFO" "running task in section $1: $2"
log "INFO" "section output following..."
printf "\\n"

eval "$2"
exit_status=$?

if [ "$3" == "should fail" ]; then
log "INFO" "expected to fail..."
if [ $exit_status -eq 0 ]; then
abort "command: $2 failed in section: $1 with: $exit_status"
fi
else
log "INFO" "expected to pass..."
if [ ! $exit_status -eq 0 ]; then
abort "command: $2 failed in section: $1 with: $exit_status"
fi
fi

printf "\\n"
log "INFO" "section $1 completed successfully"
}

enter-section "Typstyle checking" "./run-fmt.sh --check src/lib.typ" 0
enter-section "Compiling template..." "typst compile template/main.typ --root . --font-path fonts example.pdf"

log "INFO" "CI completed successfully"
typst compile template/main.typ --root . --font-path fonts example.pdf

0 comments on commit 36f8ffd

Please sign in to comment.