Skip to content

Commit

Permalink
feat!: add support for uploading to release drafts
Browse files Browse the repository at this point in the history
When we try to get a release by tag, it doesn't
return release drafts. In order to get release
drafts we need to list the releases using a token
that has write access on the repo.

Also added tests for the same.

BREAKING CHANGE: Changed behaviour to not create
a new release. Only upload to existing releases.
Also updated the action inputs to reflect the same.

Signed-off-by: Harikrishnan Balagopal <[email protected]>
  • Loading branch information
HarikrishnanBalagopal committed Dec 9, 2020
1 parent e74ff71 commit 5c0676c
Show file tree
Hide file tree
Showing 9 changed files with 16,362 additions and 12,320 deletions.
185 changes: 132 additions & 53 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,63 +9,142 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v2
- run: |
npm install
npm run all
- uses: actions/checkout@v2
- run: |
npm install
npm run all
test: # make sure the action works on a clean machine without building
name: E2E test
# make sure the action works on a clean machine without building
test_1:
name: E2E test on draft release
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v2
- name: Make test pre-release
uses: ./
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: README.md
asset_name: TEST.md
tag: ci-test-${{ matrix.os }}-${{ github.run_id }}
overwrite: true
prerelease: true
body: "rofl lol test"
- name: Check that the uploaded asset is readable
uses: actions/github-script@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs')
const child_process = require('child_process');
const assert = require('assert').strict;
- id: get_tag
run: echo "::set-output name=new_tag::ci-test-1-${{ matrix.os }}-${{ github.run_id }}"
- uses: actions/checkout@v2
- id: create_release
name: create temporary release for testing
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.get_tag.outputs.new_tag }}
release_name: Release ${{ steps.get_tag.outputs.new_tag }}
body: |
Changes in this Release
- First Change
- Second Change
draft: true
prerelease: false
- name: Make test pre-release
uses: ./
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ steps.get_tag.outputs.new_tag }}
file: README.md
asset_name: TEST.md
overwrite: true
- name: Check that the uploaded asset is readable
uses: actions/github-script@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs')
const child_process = require('child_process');
const assert = require('assert').strict;
const expected = fs.readFileSync("README.md")
const release = await github.repos.getReleaseByTag({
...context.repo,
tag: "ci-test-${{ matrix.os }}-${{ github.run_id }}",
})
assert.deepStrictEqual(release.data.prerelease, true)
assert.deepStrictEqual(release.data.body, "rofl lol test")
assert.deepStrictEqual(release.data.assets[0].name, "TEST.md")
const actual = child_process.execSync(`curl -Ls ${release.data.assets[0].browser_download_url}`)
assert.deepStrictEqual(expected, actual)
- name: Clean up
if: ${{ always() }}
uses: actions/github-script@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const release = await github.repos.getReleaseByTag({
...context.repo,
tag: "ci-test-${{ matrix.os }}-${{ github.run_id }}",
})
await github.repos.deleteRelease({
...context.repo,
release_id: release.data.id,
})
await github.git.deleteRef({
...context.repo,
ref: "tags/ci-test-${{ matrix.os }}-${{ github.run_id }}",
})
const expected = fs.readFileSync("README.md")
core.info("expected.toString()")
core.info(expected.toString())
const release = await github.repos.getRelease({
...context.repo,
release_id: "${{ steps.create_release.outputs.id }}",
})
assert.deepStrictEqual(release.data.assets[0].name, "TEST.md")
core.info(`hmm ${release.data.assets[0].browser_download_url}`)
const actual = child_process.execSync(`curl -Ls ${release.data.assets[0].browser_download_url}`)
core.info("actual.toString()")
core.info(actual.toString())
assert.deepStrictEqual(expected, actual)
- name: Clean up
if: ${{ always() }}
uses: actions/github-script@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
await github.repos.deleteRelease({
...context.repo,
release_id: ${{ steps.create_release.outputs.id }},
})
await github.git.deleteRef({
...context.repo,
ref: "tags/${{ steps.get_tag.outputs.new_tag }}",
})
test_2:
needs: [test_1]
name: E2E test on published release
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- id: get_tag
run: echo "::set-output name=new_tag::ci-test-2-${{ matrix.os }}-${{ github.run_id }}"
- uses: actions/checkout@v2
- id: create_release
name: create temporary release for testing
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.get_tag.outputs.new_tag }}
release_name: Release ${{ steps.get_tag.outputs.new_tag }}
body: |
Changes in this Release
- First Change
- Second Change
draft: false
prerelease: false
- name: Make test pre-release
uses: ./
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ steps.get_tag.outputs.new_tag }}
file: README.md
asset_name: TEST.md
overwrite: true
- name: Check that the uploaded asset is readable
uses: actions/github-script@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs')
const child_process = require('child_process');
const assert = require('assert').strict;
const expected = fs.readFileSync("README.md")
const release = await github.repos.getReleaseByTag({
...context.repo,
tag: "${{ steps.get_tag.outputs.new_tag }}",
})
assert.deepStrictEqual(release.data.assets[0].name, "TEST.md")
const actual = child_process.execSync(`curl -Ls ${release.data.assets[0].browser_download_url}`)
assert.deepStrictEqual(expected, actual)
- name: Clean up
if: ${{ always() }}
uses: actions/github-script@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
await github.repos.deleteRelease({
...context.repo,
release_id: ${{ steps.create_release.outputs.id }},
})
await github.git.deleteRef({
...context.repo,
ref: "tags/${{ steps.get_tag.outputs.new_tag }}",
})
58 changes: 36 additions & 22 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,50 @@
name: 'Upload files to a GitHub release'
description: 'Upload files to a GitHub release (cross-platform)'
author: 'Sven-Hendrik Haase'
name: "Upload files to a GitHub release"
description: "Upload files to a GitHub release (cross-platform)"
author: "Sven-Hendrik Haase"
branding:
icon: archive
color: orange
inputs:
repo_token:
description: 'GitHub token.'
required: true
file:
description: 'Local file to upload.'
required: true
description: "GitHub token."
tag:
description: 'Tag to use as a release.'
required: true
description: "Tag of the release."
file:
required: true
description: |
Path to the file to upload.
If this is a glob pattern then set file_glob to true.
file_glob:
required: false
description: |
If true the file can be a glob pattern.
asset_name will be ignored if this is true.
default: "false"
asset_name:
description: 'Name of the asset. When not provided will use the file name. Unused if file_glob is set to "true".'
required: false
description: |
By default the uploaded asset name will be same as the file name.
Use this to override the asset name. If asset_name contains the
string "$tag", it will get replaced by the release tag.
Unused if file_glob is set to true.
overwrite:
description: 'Overwrite the release in case it already exists.'
file_glob:
description: 'If true the file can be a glob pattern, asset_name is ignored if this is true.'
prerelease:
description: 'Mark the release as a pre-release. Defaults to "false".'
release_name:
description: 'Explicitly set a release name. Defaults to empty which will cause the release to take the tag as name on GitHub.'
body:
description: 'Content of the release text. Empty by default.'
required: false
description: |
By default if an asset already exists with the same name, this action will fail.
Use this to overwrite the asset instead.
default: "false"
repo_name:
description: 'Specify the name of the GitHub repository in which the GitHub release will be created, edited, and deleted. If the repository is other than the current, it is required to create a personal access token with `repo`, `user`, `admin:repo_hook` scopes to the foreign repository and add it as a secret. Defaults to the current repository'
required: false
description: |
If the release exists in a different repository then specify its name.
It is required to create a personal access token with `repo`, `user`,
and `admin:repo_hook` scopes to the external repository and give that
as the repo_token.
outputs:
browser_download_url:
description: 'The publicly available URL of the asset.'
description: "The publicly available URL of the asset."
runs:
using: 'node12'
main: 'dist/index.js'
using: "node12"
main: "dist/index.js"
Loading

0 comments on commit 5c0676c

Please sign in to comment.