Add artifact from github actions to releases

11.8k Views Asked by At

So im trying to implement a release section on my yml file for a generated artifact, explaining myself: i would like to add an artifact to my releases with my yml file.

Here's the only yml file am working on for an android app:

name: Android CI

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      - run: mkdir -p app/build/outputs/apk/release
      - run: echo hello > app/build/outputs/apk/release/app-release-unsigned.apk
      - uses: actions/upload-artifact@v2
        with:
          name: my-artifact
          path: app/build/outputs/apk/release/app-release-unsigned.apk
      - name: set up JDK 1.8
        uses: actions/setup-java@v1
        with:
          java-version: 1.8
      - name: Permition Gradlew
        run: chmod +x gradlew
      - name: Build Gradlew
        run: ./gradlew assembleRelease



1

There are 1 best solutions below

4
On

The actions/upload-artifact@v2 Action is meant for uploading artifacts to GitHub Actions workflow runs, not for adding assets to a GitHub release. If you want to add build assets to a GitHub release, you should instead use the softprops/action-gh-release example described here. I've modified the example to match your specific scenario:

on:
  push:
    # Sequence of patterns matched against refs/tags
    tags:
    - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10

name: Upload Release Asset

jobs:
  build:
    name: Upload Release Asset
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
      - name: Build project
        run: |
          mkdir -p app/build/outputs/apk/release
          echo hello > app/build/outputs/apk/release/app-release-unsigned.apk
      - name: Release with Notes
        uses: softprops/action-gh-release@v1
        with:
          files: |
            app/build/outputs/apk/release/app-release-unsigned.apk
            other/files/as/needed
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

You can repeat the final step as needed with different paths for adding further artifacts to the release.