Rewrite actions

This commit is contained in:
Aaron Dewes 2022-12-29 09:29:21 +01:00 committed by AaronDewes
parent c0c4caa1e8
commit 857840885a
4 changed files with 211 additions and 74 deletions

114
.github/workflows/build.yml vendored Normal file
View File

@ -0,0 +1,114 @@
name: Build binaries
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build-linux:
name: Build for Linux
runs-on: ubuntu-latest
strategy:
matrix:
arch: [amd64, arm64]
fail-fast: false
steps:
- uses: actions/checkout@v3
- name: Cache Dart dependencies
id: cache-deps
uses: actions/cache@v3
with:
path: /tmp/dart
key: ${{ runner.os }}-dart-deps-${{ matrix.arch }}
- name: Create temporary dir for Dart deps
if: steps.cache-deps.outputs.cache-hit != 'true'
run: mkdir -p /tmp/dart
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Install dependencies
run:
docker run --platform linux/${{ matrix.arch }} -i --rm -v /tmp/dart:/tmp/dart -e PUB_CACHE=/tmp/dart -v $(pwd):/work --workdir /work dart:stable dart pub get
- name: Build
run:
docker run --platform linux/${{ matrix.arch }} -i --rm -v /tmp/dart:/tmp/dart -e PUB_CACHE=/tmp/dart -v $(pwd):/work --workdir /work dart:stable dart compile exe bin/nostr_console.dart --output bin/nostr_console_linux_${{ matrix.arch }}
- name: Make file executable
run: |
sudo chown -R $(whoami) bin
chmod 755 bin/nostr_console_linux_${{ matrix.arch }}
- name: Archive production artifacts
uses: actions/upload-artifact@v3
with:
name: nostr_console_linux_${{ matrix.arch }}
path: |
bin/nostr_console_linux_${{ matrix.arch }}
build-others:
name: Build
runs-on: ${{ matrix.os }}-latest
strategy:
matrix:
os: [macos, windows]
fail-fast: false
env:
PUB_CACHE=: tmp/dart
steps:
- uses: actions/checkout@v3
- name: Cache Dart dependencies
id: cache-deps
uses: actions/cache@v3
with:
path: /tmp/dart
key: ${{ runner.os }}-dart-deps-amd64
- name: Create temporary dir for Dart deps
if: steps.cache-deps.outputs.cache-hit != 'true'
run: mkdir -p /tmp/dart
- name: Install Dart
uses: dart-lang/setup-dart@v1
- name: Install dependencies
run: dart pub get
- name: Build (macOS)
if: ${{ matrix.os == 'macos' }}
run: dart compile exe bin/nostr_console.dart --output bin/nostr_console_${{ matrix.os }}_amd64
# This has the .exe extension
# There is probably a better way to do this
- name: Build (Windows)
if: ${{ matrix.os == 'windows' }}
run: dart compile exe bin/nostr_console.dart --output bin/nostr_console_${{ matrix.os }}_amd64.exe
- name: Make file executable (macOS only)
if: ${{ matrix.os == 'macos' }}
run: chmod 755 bin/nostr_console_${{ matrix.os }}_amd64
- name: Archive production artifacts (macOS)
if: ${{ matrix.os == 'macos' }}
uses: actions/upload-artifact@v3
with:
name: nostr_console_${{ matrix.os }}_amd64
path: |
bin/nostr_console_${{ matrix.os }}_amd64
- name: Archive production artifacts (Windows)
if: ${{ matrix.os == 'windows' }}
uses: actions/upload-artifact@v3
with:
name: nostr_console_${{ matrix.os }}_amd64.exe
path: |
bin/nostr_console_${{ matrix.os }}_amd64.exe

View File

@ -1,45 +1,27 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
name: Dart
# do a built only on change to pubspec.yaml file with its version change
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions
# matrix logic taken from https://github.com/sass/dart-sass/blob/main/.github/workflows/ci.yml
name: Compile & test
on:
push:
paths:
- 'pubspec.yaml'
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build_all:
name: "${{matrix.os}}_${{matrix.arch}}"
runs-on: "${{matrix.os}}-latest"
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu, windows, macos]
arch: [x64]
dart_channel: [stable]
os: [ubuntu-latest, macos-latest, windows-latest]
fail-fast: false
steps:
- uses: actions/checkout@v3
# Note: This workflow uses the latest stable version of the Dart SDK.
# You can specify other versions if desired, see documentation here:
# https://github.com/dart-lang/setup-dart/blob/main/README.md
# - uses: dart-lang/setup-dart@v1
- uses: dart-lang/setup-dart@v1
with: {sdk: "${{ matrix.dart_channel }}"}
- name: Install dependencies
run: dart pub get
@ -55,34 +37,4 @@ jobs:
# package:test for this step to succeed. Note that Flutter projects will
# want to change this to 'flutter test'.
- name: Run tests
run: dart test -r expanded
- name: compile exe
run: dart compile exe bin/nostr_console.dart --output bin/nostr_console_${{matrix.os}}_${{matrix.arch}}
- name: change permission to make it executible
run: chmod 755 bin/nostr_console_${{matrix.os}}_${{matrix.arch}}
- name: Archive production artifacts
uses: actions/upload-artifact@v3
with:
name: nostr_console_${{matrix.os}}_${{matrix.arch}}
path: |
bin/nostr_console_${{matrix.os}}_${{matrix.arch}}
- name: List files in the repository
run: |
ls ${{ github.workspace }}/bin
- name: Rename exe for windows only
if: ${{ matrix.os == 'windows'}}
run: cp ${{ github.workspace }}/bin/nostr_console_${{matrix.os}}_${{matrix.arch}} ${{ github.workspace }}/bin/nostr_console_${{matrix.os}}_${{matrix.arch}}.exe
- name: Download a Build Artifact
uses: actions/download-artifact@v3.0.0
with:
# Artifact name
name: nostr_console_${{matrix.os}}_${{matrix.arch}}
# Destination path
path: ./
run: dart test

88
.github/workflows/docker-publish.yml vendored Normal file
View File

@ -0,0 +1,88 @@
name: Build & publish Docker container images
on:
schedule:
- cron: '22 17 * * *'
push:
branches: [ "main" ]
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]
pull_request:
branches: [ "main" ]
env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@main
with:
cosign-release: 'v1.13.1'
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v3
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64
- name: Sign the published Docker image
if: ${{ github.event_name != 'pull_request' }}
env:
COSIGN_EXPERIMENTAL: "true"
# This step uses the identity token to provision an ephemeral certificate
# against the sigstore community Fulcio instance.
run: echo "${{ steps.meta.outputs.tags }}" | xargs -I {} cosign sign {}@${{ steps.build-and-push.outputs.digest }}

View File

@ -1,17 +0,0 @@
name: GitHub Actions Demo
on: [push]
jobs:
Explore-GitHub-Actions:
runs-on: ubuntu-latest
steps:
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: Check out repository code
uses: actions/checkout@v3
- run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
- name: List files in the repository
run: |
ls ${{ github.workspace }}
- run: echo "🍏 This job's status is ${{ job.status }}."