Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReleaseWorkflow.yml: Create PR to update version #396

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 36 additions & 85 deletions .github/workflows/ReleaseWorkflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,102 +32,53 @@ jobs:
- name: 🛠️ Download Rust Tools 🛠️
uses: microsoft/mu_devops/.github/actions/rust-tool-cache@main

- name: Get Current Draft Release
id: draft_release
uses: actions/github-script@v7
with:
script: |
const releases = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo,
});

const draftReleaseList = releases.data.filter(release => release.draft);

if (draftReleaseList.length === 0) {
core.setFailed("No draft release found. Exiting with error.");
} else if (draftReleaseList.length > 1) {
core.setFailed("Multiple draft releases found. Exiting with error.");
} else {
const draftRelease = draftReleaseList[0];

let tag = draftRelease.tag_name;
if (tag.startsWith('v')) {
tag = tag.slice(1);
}
core.setOutput("id", draftRelease.id);
core.setOutput("tag", tag);
console.log(`Draft Release ID: ${draftRelease.id}`);
console.log(`Draft Release Tag: ${tag}`);
}

- name: Cargo Release Dry Run
run: cargo release ${{ steps.draft_release.outputs.tag }} --workspace
env:
RUSTC_BOOTSTRAP: 1
- name: Get Release Tag
id: release_tag
run: |
tag_name="${{ github.event.release.tag_name }}"

# remove the leading 'v' if it exists
release_tag="${tag_name#v}"

- name: Login to Crates.io
run: cargo login ${{ secrets.CRATES_IO_TOKEN }}
echo "Release Tag: $release_tag"
echo "tag=$release_tag" >> $GITHUB_OUTPUT
shell: bash

- name: Update git credentials
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"

- name: Checkout New Branch
run: |
git checkout -b "github-actions/release-${{ steps.release_tag.outputs.tag }}"
git push origin "github-actions/release-${{ steps.release_tag.outputs.tag }}"

- name: Login to Crates.io
run: cargo login ${{ secrets.CRATES_IO_TOKEN }}

- name: Cargo Release Dry Run
run: cargo release ${{ steps.release_tag.outputs.tag }} --workspace
env:
RUSTC_BOOTSTRAP: 1

- name: Cargo Release
run: cargo release ${{ steps.draft_release.outputs.tag }} -x --no-tag --no-confirm --workspace
run: cargo release ${{ steps.release_tag.outputs.tag }} -x --no-tag --no-confirm --workspace
env:
RUSTC_BOOTSTRAP: 1

- name: Wait for Release Draft Updater
- name: Notify Branch Creation
uses: actions/github-script@v7
with:
script: |
const workflowId = "release-draft.yml";
const ref = "main";
const owner = context.repo.owner;
const repo = context.repo.repo;

// Try for 10 minutes. It should only take a few seconds
let maxAttempts = 40;
let attempt = 0;
let completed = false

while (attempt < maxAttempts && !completed) {
await new Promise(resolve => setTimeout(resolve, 15000));
const runs = await github.rest.actions.listWorkflowRuns({
owner,
repo,
workflow_id: workflowId,
branch: ref,
event: 'push',
status: 'in_progress',
});

if (runs.data.workflow_runs.length === 0) {
completed = true;
} else {
attempt++;
}
}

if (!completed) {
core.setFailed("Release Drafter did not complete in time. Please perform the release manually.");
}

- name: Publish Release
uses: actions/github-script@v7
with:
script: |
const releaseId = ${{ steps.draft_release.outputs.id }};

const response = await github.rest.repos.updateRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: releaseId,
draft: false,
});

if (response.status !== 200) {
core.setFailed(`Failed to publish release. Exiting with error.`);
}
const branch = `github-actions/release-${{ steps.release_tag.outputs.tag }}`;
const baseBranch = context.payload.repository.default_branch;
const repo = context.repo;

const prUrl = `https://github.com/${repo.owner}/${repo.repo}/compare/${baseBranch}...${branch}?expand=1`;

core.warning('A pull request needs to be created to update the version');
core.warning(`Click the link below to create the pull request:`);
core.warning(prUrl);

# TODO: Add ability for a github app to create a release from the published branch
19 changes: 2 additions & 17 deletions .sync/workflows/leaf/publish-release.yml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update the file description to reflect that the workflow no longer creates a release on GitHub but runs when a release is published?

Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,12 @@
name: Publish Release

on:
workflow_dispatch:
release:
types: [published]

jobs:
validate_branch:
name: Validate Branch
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Validate Branch
run: |
if [ "${GITHUB_REF}" != "refs/heads/main" ]; then
echo "This workflow can only be run on the main branch."
exit 1
fi

release:
name: Release
needs: validate_branch
uses: microsoft/mu_devops/.github/workflows/ReleaseWorkflow.yml@main
secrets:
CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
Expand Down
Loading