-
Notifications
You must be signed in to change notification settings - Fork 22
Add release workflow automation #79
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
Open
gjtorikian
wants to merge
1
commit into
main
Choose a base branch
from
automate-workflows
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+148
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| name: Release | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [closed] | ||
| branches: [main] | ||
|
|
||
| defaults: | ||
| run: | ||
| shell: bash | ||
|
|
||
| jobs: | ||
| create-release: | ||
| name: Create GitHub Release | ||
| if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'version-bump') | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
| steps: | ||
| - name: Generate token | ||
| id: generate-token | ||
| uses: actions/create-github-app-token@v1 | ||
| with: | ||
| app-id: ${{ vars.WORKOS_BOT_APP_ID }} | ||
| private-key: ${{ secrets.WORKOS_BOT_PRIVATE_KEY }} | ||
|
|
||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| token: ${{ steps.generate-token.outputs.token }} | ||
|
|
||
| - name: Get version from mix.exs | ||
| id: get-version | ||
| run: | | ||
| VERSION=$(grep '@version "' mix.exs | sed 's/.*@version "\(.*\)"/\1/') | ||
| echo "version=$VERSION" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Create Release | ||
| uses: softprops/action-gh-release@v2 | ||
| with: | ||
| tag_name: v${{ steps.get-version.outputs.version }} | ||
| name: v${{ steps.get-version.outputs.version }} | ||
| generate_release_notes: true | ||
| token: ${{ steps.generate-token.outputs.token }} | ||
|
|
||
| publish: | ||
| name: Publish to Hex | ||
| needs: create-release | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Elixir and Erlang | ||
| uses: erlef/setup-beam@5304e04ea2b355f03681464e683d92e3b2f18451 # v1.18.2 | ||
| with: | ||
| elixir-version: '1.15' | ||
| otp-version: '26.0' | ||
|
|
||
| - name: Install dependencies | ||
| run: mix deps.get | ||
|
|
||
| - name: Publish to Hex | ||
| run: mix hex.publish --yes | ||
| env: | ||
| HEX_API_KEY: ${{ secrets.HEX_API_KEY }} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| name: Version Bump | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| bump_type: | ||
| description: "Version bump type" | ||
| required: true | ||
| type: choice | ||
| options: | ||
| - patch | ||
| - minor | ||
| - major | ||
|
|
||
| jobs: | ||
| bump-version: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
| steps: | ||
| - name: Generate token | ||
| id: generate-token | ||
| uses: actions/create-github-app-token@v1 | ||
| with: | ||
| app-id: ${{ vars.WORKOS_BOT_APP_ID }} | ||
| private-key: ${{ secrets.WORKOS_BOT_PRIVATE_KEY }} | ||
|
|
||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| token: ${{ steps.generate-token.outputs.token }} | ||
|
|
||
| - name: Configure Git | ||
| run: | | ||
| git config user.name "workos-bot[bot]" | ||
| git config user.email "workos-bot[bot]@users.noreply.github.com" | ||
|
|
||
| - name: Read current version | ||
| id: current-version | ||
| run: | | ||
| CURRENT_VERSION=$(grep '@version "' mix.exs | sed 's/.*@version "\(.*\)"/\1/') | ||
| echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Bump version | ||
| id: bump-version | ||
| run: | | ||
| CURRENT_VERSION="${{ steps.current-version.outputs.version }}" | ||
| IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION" | ||
|
|
||
| case "${{ github.event.inputs.bump_type }}" in | ||
| major) | ||
| NEW_VERSION="$((MAJOR + 1)).0.0" | ||
| ;; | ||
| minor) | ||
| NEW_VERSION="$MAJOR.$((MINOR + 1)).0" | ||
| ;; | ||
| patch) | ||
| NEW_VERSION="$MAJOR.$MINOR.$((PATCH + 1))" | ||
| ;; | ||
| esac | ||
|
|
||
| echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Update version in mix.exs | ||
| run: | | ||
| sed -i 's/@version ".*"/@version "${{ steps.bump-version.outputs.new_version }}"/' mix.exs | ||
|
|
||
| - name: Create Pull Request | ||
| uses: peter-evans/create-pull-request@v7 | ||
| with: | ||
| token: ${{ steps.generate-token.outputs.token }} | ||
| commit-message: "v${{ steps.bump-version.outputs.new_version }}" | ||
| title: "v${{ steps.bump-version.outputs.new_version }}" | ||
| body: | | ||
| Bumps version from ${{ steps.current-version.outputs.version }} to ${{ steps.bump-version.outputs.new_version }}. | ||
|
|
||
| This PR was automatically created by the version-bump workflow. | ||
| branch: version-bump-${{ steps.bump-version.outputs.new_version }} | ||
| labels: version-bump |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this flow will work with hex - releases become immutable one hour after publishing, so the version would need to be bumped with every PR before it can be pushed as a new release.