Add artifact from github actions to releases
Asked Answered
R

1

17

I'm 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
Roadside answered 16/12, 2020 at 15:4 Comment(0)
N
3

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.

Nerta answered 12/1, 2021 at 0:37 Comment(4)
Caution: actions/upload-release-asset@v1 is currently unmaintained.Otho
I've edited my answer to use a different action that's still actively maintained, and recommended in the now-archived actions/upload-release-asset README.Nerta
What about you suggestion to repeat the last step to add more files? Would this new action work if the release is already created?Pugilist
@Pugilist yes, you can continue to add artifacts to a release after it's been created, or you can pass an array of filepaths to the action and it'll upload all files in a single step - see github.com/softprops/…Nerta

© 2022 - 2024 — McMap. All rights reserved.