From c0b18d2f4311f16753c2b58c792b0303a5a415ec Mon Sep 17 00:00:00 2001 From: Stephan Date: Fri, 18 Mar 2022 15:47:17 +0100 Subject: [PATCH] exp --- .github/workflows/publish-release.js | 15 ++++++ .github/workflows/publish-release.yml | 76 ++------------------------- 2 files changed, 20 insertions(+), 71 deletions(-) create mode 100644 .github/workflows/publish-release.js diff --git a/.github/workflows/publish-release.js b/.github/workflows/publish-release.js new file mode 100644 index 0000000..35d5170 --- /dev/null +++ b/.github/workflows/publish-release.js @@ -0,0 +1,15 @@ +module.exports = async ({github, context, core}) => { + + const restapi = github.rest + + function firstOrDefault(items, predicate) { + for (const item of items) { + if (predicate(item)) { + return item + } + } + return null + } + + console.log("script") +} \ No newline at end of file diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index e2dc60b..b3799b1 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -3,78 +3,12 @@ on: workflow_dispatch jobs: job: runs-on: ubuntu-latest - if: startsWith(github.ref, 'refs/heads/release/') + if: startsWith(github.ref, 'refs/heads/release/') # 19 leading chars steps: + - name: Validate the release - uses: actions/github-script@v4 + uses: actions/github-script@v5 with: script: | - const ver = "${{ github.ref }}".substring(19) - const tag = "v" + ver - try { - const rel = await github.repos.getReleaseByTag({ - owner: context.repo.owner, - repo: context.repo.repo, - tag: tag - }) - } - catch (error) { - core.setFailed(`Could not find a release for tag '${tag}'.`) - return - } - if (rel.draft) { - core.setFailed(`Release for tag '${tag}' is already published.`) - return - } - try { - const ref = await github.git.getRef({ - owner: context.repo.owner, - repo: context.repo.repo, - ref: 'tags/' + tag - }) - core.setFailed(`Tag '${tag}' already exists.`) - return - } - catch (error) { - // this is expected - } - // everything is OK - - - name: Checkout - uses: actions/checkout@v2 - with: - token: ${{ secrets.GITHUB_TOKEN }} - - - name: Configure repository - shell: bash - run: | - git config user.email "github-actions@hazelcast.com" - git config user.name "GitHub Actions (Build Release)" - - - name: Finalize the release - run: | - ref="${{ github.ref }}" - branch="${ref:11}" # trim starting 'refs/heads/' (11 chars) - version="${ref:19}" # trim starting 'refs/heads/release/' (19 chars) - echo "Tag branch $branch as v$version" - git tag v$version - git push --tags - #git push :$branch - - - name: Publish the release - uses: actions/github-script@v4 - with: - script: | - const ver = "${{ github.ref }}".substring(19) - const tag = "v" + ver - const rel = await github.repos.getReleaseByTag({ - owner: context.repo.owner, - repo: context.repo.repo, - tag: tag - }) - await github.repos.updateRelease({ - owner: context.repo.owner, - repo: context.repo.repo, - release_id: rel.id, - draft: false - }) \ No newline at end of file + const script = require('./.github/workflows/publish-release.js') + console.log(script)