cd(bump): allow release to write to repo #93
This file contains 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
name: CD | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
cross-build: | |
strategy: | |
matrix: | |
include: | |
# - target: aarch64-apple-darwin | |
# os: macos-latest | |
# - target: aarch64-unknown-linux-musl | |
# os: ubuntu-latest | |
- target: x86_64-unknown-linux-musl | |
os: ubuntu-latest | |
runs-on: ${{ matrix.os }} | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Install Rust | |
uses: actions-rs/toolchain@v1 | |
with: | |
target: ${{ matrix.target }} | |
toolchain: stable | |
override: true | |
- name: Cache Cross | |
id: cache-cross | |
uses: actions/cache@v2 | |
with: | |
path: ~/.cargo/bin/cross | |
key: ${{ runner.os }}-cross | |
- name: Check if Cross is installed | |
if: steps.cache-cross.outputs.cache-hit == 'true' | |
id: cross-check | |
run: | | |
if command -v cross &> /dev/null | |
then | |
echo "::set-output name=installed::true" | |
else | |
echo "::set-output name=installed::false" | |
fi | |
- name: Install Cross | |
if: steps.cross-check.outputs.installed != 'true' | |
uses: actions-rs/cargo@v1 | |
with: | |
command: install | |
args: cross | |
- name: Cache Cargo registry | |
uses: actions/cache@v2 | |
with: | |
path: ~/.cargo/registry | |
key: ${{ runner.os }}-${{ matrix.target }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} | |
- name: Cache Cargo index | |
uses: actions/cache@v2 | |
with: | |
path: ~/.cargo/git | |
key: ${{ runner.os }}-${{ matrix.target }}-cargo-git-${{ hashFiles('**/Cargo.lock') }} | |
- name: Cache Cargo build | |
uses: actions/cache@v2 | |
with: | |
path: target | |
key: ${{ runner.os }}-${{ matrix.target }}-cargo-build-${{ hashFiles('**/Cargo.lock', '**/Cargo.toml') }} | |
- name: Cross Build | |
run: | | |
cross build --target ${{ matrix.target }} --release | |
- name: Archive | |
uses: actions/upload-artifact@v2 | |
with: | |
name: ${{ matrix.target }} | |
path: target/${{ matrix.target }}/release/semrel | |
# native-build: | |
# strategy: | |
# matrix: | |
# include: | |
# - target: x86_64-apple-darwin | |
# os: macos-latest | |
# runs-on: ${{ matrix.os }} | |
# steps: | |
# - uses: actions/checkout@v2 | |
# - name: Install Rust | |
# uses: actions-rs/toolchain@v1 | |
# with: | |
# target: ${{ matrix.target }} | |
# toolchain: stable | |
# override: true | |
# - name: Cache Cargo registry | |
# uses: actions/cache@v2 | |
# with: | |
# path: ~/.cargo/registry | |
# key: ${{ runner.os }}-${{ matrix.target }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} | |
# - name: Cache Cargo index | |
# uses: actions/cache@v2 | |
# with: | |
# path: ~/.cargo/git | |
# key: ${{ runner.os }}-${{ matrix.target }}-cargo-git-${{ hashFiles('**/Cargo.lock') }} | |
# - name: Cache Cargo build | |
# uses: actions/cache@v2 | |
# with: | |
# path: target | |
# key: ${{ runner.os }}-${{ matrix.target }}-cargo-build-${{ hashFiles('**/Cargo.lock', '**/Cargo.toml') }} | |
# - name: Build | |
# run: | | |
# cargo build --release --target=${{ matrix.target }} | |
# - name: Archive | |
# uses: actions/upload-artifact@v2 | |
# with: | |
# name: ${{ matrix.target }} | |
# path: target/${{ matrix.target }}/release/semrel | |
release: | |
needs: [cross-build] | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
with: | |
# we need to fetch the whole history or semrel won't work | |
ref: main | |
fetch-depth: 0 | |
- name: Download Artifacts | |
uses: actions/download-artifact@v2 | |
- name: Install tar | |
run: sudo apt-get install tar | |
- name: Set permissions on artifacts | |
run: | | |
# chmod +x aarch64-apple-darwin/semrel | |
# chmod +x x86_64-apple-darwin/semrel | |
# chmod +x aarch64-unknown-linux-musl/semrel | |
chmod +x x86_64-unknown-linux-musl/semrel | |
- name: Get new version with semrel | |
id: version | |
run: | | |
version=$(./x86_64-unknown-linux-musl/semrel show next) | |
echo "::set-output name=version::$version" | |
- name: Update artifact names | |
run: | | |
# mv aarch64-apple-darwin/semrel aarch64-apple-darwin/semrel-${{ steps.version.outputs.version }}-amd64-apple-darwin | |
# mv x86_64-apple-darwin/semrel x86_64-apple-darwin/semrel-${{ steps.version.outputs.version }}-x86_64-apple-darwin | |
# mv aarch64-unknown-linux-musl/semrel aarch64-unknown-linux-musl/semrel-${{ steps.version.outputs.version }}-aarch64-unknown-linux-musl | |
mv x86_64-unknown-linux-musl/semrel x86_64-unknown-linux-musl/semrel-${{ steps.version.outputs.version }}-x86_64-unknown-linux-musl | |
echo "Path: ${PATH}" | |
cp x86_64-unknown-linux-musl/semrel-${{ steps.version.outputs.version }}-x86_64-unknown-linux-musl ~/.cargo/bin/semrel | |
- name: Package Artifacts | |
run: | | |
# tar czvf semrel-${{ steps.version.outputs.version }}-arm64-apple-darwin.tgz -C aarch64-apple-darwin . | |
# tar czvf semrel-${{ steps.version.outputs.version }}-x86_64-apple-darwin.tgz -C x86_64-apple-darwin . | |
# tar czvf semrel-${{ steps.version.outputs.version }}-aarch64-unknown-linux-musl.tgz -C aarch64-unknown-linux-musl . | |
tar czvf semrel-${{ steps.version.outputs.version }}-x86_64-unknown-linux-musl.tgz -C x86_64-unknown-linux-musl . | |
- name: Generate Release notes with semrel | |
run: | | |
semrel show notes > release-notes-${{ steps.version.outputs.version }}.md | |
- name: Commit changes | |
env: | |
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} | |
run: | | |
git config user.name github-actions | |
git config user.email github-actions@github.com | |
git log --oneline | |
semrel update | |
echo "current version: `semrel show current`" | |
echo "next version: `semrel show next`" | |
echo "log: `semrel show log`" | |
git add . | |
git commit -m "release: `semrel show next`\n\n`semrel show notes`" | |
git remote set-url origin https://x-access-token:${{ secrets.token }}@github.com/${{ github.repository }}.git | |
git push origin HEAD:main | |
- name: Create Release | |
id: create_release | |
uses: softprops/action-gh-release@v2 | |
env: | |
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} | |
with: | |
files: | | |
x86_64-unknown-linux-musl.tgz | |
name: semrel-${{ steps.version.outputs.version }} | |
body_path: release-notes-${{ steps.version.outputs.version }}.md | |
generate_release_notes: false | |
make_latest: true | |
draft: false | |
prerelease: false | |
tag_name: ${{ steps.version.outputs.version }} | |
token: ${{ secrets.RELEASE_TOKEN }} |