Skip to content

Commit

Permalink
deploy-pages and abstract file names
Browse files Browse the repository at this point in the history
  • Loading branch information
ameknite committed Sep 23, 2023
1 parent 5ca9510 commit d0cac7f
Showing 1 changed file with 102 additions and 59 deletions.
161 changes: 102 additions & 59 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ env:

# Build platforms

# Valid platforms: "web, linux, windows, intel, apple_silicon"
# - "intel" and "apple_silicon" are for build to MacOS,
# for breviety you can write "macos" to build for both.
# - you can also write "wasm" to build for web.
# Valid platforms: "web, linux, windows, macos_intel, macos_apple_silicon"
# - Write "intel" and "apple" to abbreviate "macos_intel" and "macos_apple_silicon," respectively.
# - Write "macos" to build for both "intel" and "apple"
# - Write "web" or "wasm" to build for the web
build_for: "web, linux, windows, macos"

# Releases
Expand All @@ -28,8 +28,11 @@ env:
# Check the url of your game page in itch.io

permissions:
# To upload files to GitHub Releases
contents: write
# To deploy to Pages
pages: write
# To verify the deployment originates from an appropriate source
id-token: write

on:
Expand All @@ -47,7 +50,7 @@ on:
default: web,linux,windows,macos
publish_to:
description: "Publish to:"
default: releases,itchio,pages
default: github_releases
itchio_target:
description: "Itchio target: <user>/<your-game>"
type: string
Expand All @@ -71,11 +74,14 @@ jobs:
itchio_target: ${{ inputs.itchio_target || env.itchio_target }}
tag: ${{ ( inputs.tag || steps.get_version.outputs.tag ) }}

# Build for Web Wasm
# Build for Web Wasm
build-web:
runs-on: ubuntu-latest
needs: load-env
if: needs.load-env.outputs.run_build_web == 'true'
env:
platform: web

steps:
- uses: actions/checkout@v4

Expand All @@ -91,28 +97,42 @@ jobs:
run: |
cargo build --release --target wasm32-unknown-unknown
- name: Set file name
id: set_file_name
run: |
echo "file_name=${{ env.binary }}_${{ needs.load-env.outputs.tag }}_${{ env.platform }}" >> "$GITHUB_OUTPUT"
- name: Prepare package
run: |
wasm-bindgen --no-typescript --out-name bevy_game --out-dir wasm --target web target/wasm32-unknown-unknown/release/${{ env.binary }}.wasm
cp -r assets wasm/
- name: Upload github-page to artifacts
if: needs.load-env.outputs.run_publish_github_pages == 'true'
uses: actions/upload-pages-artifact@v2
with:
path: ./wasm
retention-days: 1

- name: Package as a zip
working-directory: ./wasm
run: |
zip --recurse-paths ../${{ env.binary }}_${{ needs.load-env.outputs.tag }}_web.zip .
zip --recurse-paths ../${{ steps.set_file_name.outputs.file_name }}.zip .
- name: Upload binaries to artifacts
uses: actions/upload-artifact@v3
with:
path: ${{ env.binary }}_${{ needs.load-env.outputs.tag }}_web.zip
name: web
name: ${{ env.platform }}
path: ${{ steps.set_file_name.outputs.file_name }}.zip
retention-days: 1

# Build for Linux x86_64
build-linux:
runs-on: ubuntu-latest
needs: load-env
if: needs.load-env.outputs.run_build_linux == 'true'
env:
platform: linux
steps:
- uses: actions/checkout@v4

Expand All @@ -128,6 +148,11 @@ jobs:
run: |
cargo build --release --target x86_64-unknown-linux-gnu
- name: Set file name
id: set_file_name
run: |
echo "file_name=${{ env.binary }}_${{ needs.load-env.outputs.tag }}_${{ env.platform }}" >> "$GITHUB_OUTPUT"
- name: Prepare package
run: |
mkdir linux
Expand All @@ -137,20 +162,22 @@ jobs:
- name: Package as a zip
working-directory: ./linux
run: |
zip --recurse-paths ../${{ env.binary }}_${{ needs.load-env.outputs.tag }}_linux.zip .
zip --recurse-paths ../${{ steps.set_file_name.outputs.file_name }}.zip .
- name: Upload binaries to artifacts
uses: actions/upload-artifact@v3
with:
path: ${{ env.binary }}_${{ needs.load-env.outputs.tag }}_linux.zip
name: linux
name: ${{ env.platform }}
path: ${{ steps.set_file_name.outputs.file_name }}.zip
retention-days: 1

# Build for Windows x86_64
build-windows:
runs-on: windows-latest
needs: load-env
if: needs.load-env.outputs.run_build_windows == 'true'
env:
platform: windows
steps:
- uses: actions/checkout@v4

Expand All @@ -162,28 +189,37 @@ jobs:
run: |
cargo build --release --target x86_64-pc-windows-msvc
- name: Set file name
id: set_file_name
shell: bash
run: |
echo "file_name=${{ env.binary }}_${{ needs.load-env.outputs.tag }}_${{ env.platform }}" >> "$GITHUB_OUTPUT"
- name: Prepare package
shell: bash
run: |
mkdir windows
cp target/x86_64-pc-windows-msvc/release/${{ env.binary }}.exe windows/
cp -r assets windows/
- name: Package as a zip
run: |
Compress-Archive -Path windows/* -DestinationPath "${{ env.binary }}_${{ needs.load-env.outputs.tag }}_windows.zip"
Compress-Archive -Path windows/* -DestinationPath "${{ steps.set_file_name.outputs.file_name }}.zip"
- name: Upload binaries to artifacts
uses: actions/upload-artifact@v3
with:
path: ${{ env.binary }}_${{ needs.load-env.outputs.tag }}_windows.zip
name: windows
name: ${{ env.platform }}
path: ${{ steps.set_file_name.outputs.file_name }}.zip
retention-days: 1

# Build for MacOS x86_64
build-macos-intel:
runs-on: macos-latest
needs: load-env
if: needs.load-env.outputs.run_build_macos_intel == 'true'
env:
platform: macos_intel
steps:
- uses: actions/checkout@v4

Expand All @@ -200,25 +236,33 @@ jobs:
run: |
cargo build --release --target x86_64-apple-darwin
- name: Set Paths
id: set_paths
run: |
echo "file_name=${{ env.binary }}_${{ needs.load-env.outputs.tag }}_${{ env.platform }}" >> "$GITHUB_OUTPUT"
echo "app_structure=${{ env.binary }}.app/Contents/MacOS" >> "$GITHUB_OUTPUT"
- name: Prepare Package
run: |
mkdir -p ${{ env.binary }}.app/Contents/MacOS
cp target/x86_64-apple-darwin/release/${{ env.binary }} ${{ env.binary }}.app/Contents/MacOS/
cp -r assets ${{ env.binary }}.app/Contents/MacOS/
hdiutil create -fs HFS+ -volname "${{ env.binary }}" -srcfolder ${{ env.binary }}.app ${{ env.binary }}_${{ needs.load-env.outputs.tag }}_macos_intel.dmg
mkdir -p ${{ steps.set_paths.outputs.app_structure }}
cp target/x86_64-apple-darwin/release/${{ env.binary }} ${{ steps.set_paths.outputs.app_structure }}
cp -r assets ${{ steps.set_paths.outputs.app_structure }}
hdiutil create -fs HFS+ -volname "${{ env.binary }}" -srcfolder ${{ env.binary }}.app ${{ steps.set_paths.outputs.file_name }}.dmg
- name: Upload binaries to artifacts
uses: actions/upload-artifact@v3
with:
path: ${{ env.binary }}_${{ needs.load-env.outputs.tag }}_macos_intel.dmg
name: macos_intel
name: ${{ env.platform }}
path: ${{ steps.set_paths.outputs.file_name }}.dmg
retention-days: 1

# Build for MacOS Apple Silicon
build-macos-apple-silicon:
runs-on: macos-latest
needs: load-env
if: needs.load-env.outputs.run_build_macos_apple_silicon == 'true'
env:
platform: macos_apple_silicon
steps:
- uses: actions/checkout@v4

Expand All @@ -235,18 +279,24 @@ jobs:
run: |
cargo build --release --target aarch64-apple-darwin
- name: Set paths
id: set_paths
run: |
echo "file_name=${{ env.binary }}_${{ needs.load-env.outputs.tag }}_${{ env.platform }}" >> "$GITHUB_OUTPUT"
echo "app_structure=${{ env.binary }}.app/Contents/MacOS" >> "$GITHUB_OUTPUT"
- name: Prepare Package
run: |
mkdir -p ${{ env.binary }}.app/Contents/MacOS
cp target/aarch64-apple-darwin/release/${{ env.binary }} ${{ env.binary }}.app/Contents/MacOS/
cp -r assets ${{ env.binary }}.app/Contents/MacOS/
hdiutil create -fs HFS+ -volname "${{ env.binary }}" -srcfolder ${{ env.binary }}.app ${{ env.binary }}_${{ needs.load-env.outputs.tag }}_macos_apple_silicon.dmg
mkdir -p ${{ steps.set_paths.outputs.app_structure }}
cp target/aarch64-apple-darwin/release/${{ env.binary }} ${{ steps.set_paths.outputs.app_structure }}
cp -r assets ${{ steps.set_paths.outputs.app_structure }}
hdiutil create -fs HFS+ -volname "${{ env.binary }}" -srcfolder ${{ env.binary }}.app ${{ steps.set_paths.outputs.file_name }}.dmg
- name: Upload binaries to artifacts
uses: actions/upload-artifact@v3
with:
path: ${{ env.binary }}_${{ needs.load-env.outputs.tag }}_macos_apple_silicon.dmg
name: macos_apple_silicon
name: ${{ env.platform }}
path: ${{ steps.set_paths.outputs.file_name }}.dmg
retention-days: 1

# Release binaries in github
Expand Down Expand Up @@ -282,28 +332,28 @@ jobs:
with:
name: ${{ matrix.artifact_name }}

# check for zip or dmg file
- uses: haya14busa/action-cond@v1
if: steps.check_artifact.outputs.exists == 'true'
id: condval
with:
cond: ${{ matrix.os == 'macos-latest' }}
if_true: "dmg"
if_false: "zip"

- name: Download artifacts
if: steps.check_artifact.outputs.exists == 'true'
uses: actions/download-artifact@v3
with:
name: ${{ matrix.artifact_name }}
path: ./artifact

- name: Get file
if: steps.check_artifact.outputs.exists == 'true'
id: get_file_name
shell: bash
working-directory: ./artifact
run: |
ls -R
echo "file_name=$(ls | head -n 1)" >> "$GITHUB_OUTPUT"
- name: Upload artifact to release
if: steps.check_artifact.outputs.exists == 'true'
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ${{ env.binary }}_${{ needs.load-env.outputs.tag }}_${{ matrix.artifact_name }}.${{ steps.condval.outputs.value }}
asset_name: ${{ env.binary }}_${{ needs.load-env.outputs.tag }}_${{ matrix.artifact_name }}.${{ steps.condval.outputs.value }}
file: ./artifact/${{ steps.get_file_name.outputs.file_name }}
tag: ${{ needs.load-env.outputs.tag }}
overwrite: true

Expand Down Expand Up @@ -331,19 +381,19 @@ jobs:
chmod +x butler
./butler -V
- uses: olegtarasov/get-tag@v2.1.2
id: get_version

- name: Upload to itch.io
env:
BUTLER_API_KEY: ${{ secrets.BUTLER_CREDENTIALS }}
run: |
for channel in $(ls builds); do
if [ "$channel" = "github-pages" ]; then
continue
fi
./butler push \
--fix-permissions \
--userversion="${{ needs.load-env.outputs.tag }}" \
builds/$channel/* \
${{ inputs.itchio_target || env.itchio_target }}:$channel
--fix-permissions \
--userversion="${{ needs.load-env.outputs.tag }}" \
builds/$channel/* \
${{ needs.load-env.outputs.itchio_target }}:$channel
done
# Publish to github page
Expand All @@ -353,20 +403,13 @@ jobs:
- load-env
- build-web
if: ${{ needs.load-env.outputs.run_publish_github_pages == 'true' }}
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- uses: actions/checkout@v3

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

- name: Unzip artifact
run: |
unzip ./${{ env.binary }}_${{ needs.load-env.outputs.tag }}_web.zip -d web
- name: Setup Pages
uses: actions/configure-pages@v3

- name: Deploy to GitHub Pages
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: web
branch: gh-pages
id: deployment
uses: actions/deploy-pages@v2

0 comments on commit d0cac7f

Please sign in to comment.