Skip to content

Commit

Permalink
build: Add GH workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Apr 1, 2023
1 parent 746b8e6 commit 1cd0d30
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 56 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/early-access.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: EarlyAccess

on:
push:
branches: [ main ]

jobs:
precheck:
if: github.repository == 'jreleaser/helloworld-swift' && startsWith(github.event.head_commit.message, 'Releasing version') != true
runs-on: ubuntu-latest
outputs:
VERSION: ${{ steps.vars.outputs.VERSION }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Version
id: vars
shell: bash
run: |
VERSION=$(cat VERSION)
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
build:
needs: [ precheck ]
if: endsWith(${{ needs.precheck.outputs.VERSION }}, '-SNAPSHOT')
uses: jreleaser/helloworld-swift/.github/workflows/reusable-build.yml@main
with:
version: ${{ needs.precheck.outputs.VERSION }}

release:
needs: [ precheck, build ]
if: endsWith(${{ needs.precheck.outputs.VERSION }}, '-SNAPSHOT')
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Download artifacts
uses: actions/download-artifact@v3

- name: Release
uses: jreleaser/release-action@v2
with:
arguments: release -PartifactsDir=artifacts -PskipArchiveResolver
env:
JRELEASER_PROJECT_VERSION: ${{ needs.precheck.outputs.VERSION }}
JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: JReleaser output
if: always()
uses: actions/upload-artifact@v3
with:
retention-days: 1
name: jreleaser-release
path: |
out/jreleaser/trace.log
out/jreleaser/output.properties
74 changes: 74 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Release

on:
workflow_dispatch:
inputs:
version:
description: 'Release version'
required: true

jobs:
precheck:
name: Precheck
runs-on: ubuntu-latest
outputs:
VERSION: ${{ steps.vars.outputs.VERSION }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Cancel previous run
uses: styfle/[email protected]
with:
access_token: ${{ secrets.GITHUB_TOKEN }}

- name: Version
id: vars
shell: bash
run: |
echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
build:
needs: [ precheck ]
uses: jreleaser/helloworld-swift/.github/workflows/reusable-build.yml@main
with:
version: ${{ needs.precheck.outputs.VERSION }}

release:
name: Release
needs: [ precheck, build ]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Download artifacts
uses: actions/download-artifact@v3

- name: Commit version
run: |
echo ${{ github.event.inputs.version }} > VERSION
git add VERSION
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "GitHub Action"
git commit -a -m "Releasing version ${{ needs.precheck.outputs.VERSION }}"
git push origin main
- name: Release
uses: jreleaser/release-action@v2
with:
arguments: release -PartifactsDir=artifacts -PskipArchiveResolver
env:
JRELEASER_PROJECT_VERSION: ${{ needs.precheck.outputs.VERSION }}
JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: JReleaser output
if: always()
uses: actions/upload-artifact@v3
with:
name: jreleaser-release
path: |
out/jreleaser/trace.log
out/jreleaser/output.properties
55 changes: 55 additions & 0 deletions .github/workflows/reusable-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Build

on:
workflow_call:
inputs:
version:
required: true
type: string

jobs:
build:
name: 'Build ${{ matrix.os }}'
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macOS-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Swift
uses: swift-actions/[email protected]
with:
swift-version: '5'

- name: Build
shell: bash
run: swift build

- name: Assemble
uses: jreleaser/release-action@v2
with:
arguments: assemble -PbuildDir="{{ buildDir${{ runner.os}} }}"
env:
JRELEASER_PROJECT_VERSION: ${{ inputs.version }}
JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
retention-days: 1
name: artifacts
path: |
out/jreleaser/assemble/helloworld/archive/*.zip
- name: JReleaser output
if: always()
uses: actions/upload-artifact@v3
with:
retention-days: 1
name: jreleaser-${{ runner.os }}
path: |
out/jreleaser/trace.log
out/jreleaser/output.properties
3 changes: 0 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,5 @@ let package = Package(
.executableTarget(
name: "helloworld",
dependencies: []),
.testTarget(
name: "helloworldTests",
dependencies: ["helloworld"]),
]
)
3 changes: 1 addition & 2 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

This repository shows how to configure link:https://github.com/features/actions[GitHub Actions] and link:https://jreleaser.org/[JReleaser] to:

* compile a helloworld app for the followign targets:
* compile a helloworld app for the following targets:
** macos-x86_64
** linux-x86_64
** windows-x86_64
* assemble zip distributions with JReleaser
* create rolling early-access releases with JReleaser on every push to `main` branch
47 changes: 0 additions & 47 deletions Tests/helloworldTests/helloworldTests.swift

This file was deleted.

7 changes: 3 additions & 4 deletions jreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
environment:
properties:
artifactsDir: out/jreleaser/assemble/helloworld/archive
buildDirOsx: x86_64-apple-macosx
buildDir: '{{buildDirOsx}}'
buildDirmacOs: x86_64-apple-macosx
buildDirLinux: x86_64-unknown-linux-gnu
buildDir: '{{buildDirmacOs}}'

project:
name: helloworld
Expand Down Expand Up @@ -46,7 +47,5 @@ distributions:
artifacts:
- path: '{{artifactsDir}}/{{distributionName}}-{{projectVersion}}-osx-x86_64.zip'
platform: 'osx-x86_64'
- path: '{{artifactsDir}}/{{distributionName}}-{{projectVersion}}-windows-x86_64.zip'
platform: 'windows-x86_64'
- path: '{{artifactsDir}}/{{distributionName}}-{{projectVersion}}-linux-x86_64.zip'
platform: 'linux-x86_64'

0 comments on commit 1cd0d30

Please sign in to comment.